I'm programming a GUI in Octave and was wondering how to implement code that the calls functions behind my buttons that will return a assigned value to the workspace.
To be more specific I have written down a code snippet which is dealing with my topic.
The original GUI can be found here: https://www.gomatlab.de/gui-in-octave-erstellen-t44037.html
What I'm trying to do is to modify the given code to my purpose (nothing from scratch).
function load_params(obj)
clear h
h = guidata(obj)
[filename, pathname] = uigetfile('*.mat')
result = load([pathname,filenname]) //Want to have result in my workspace
end;
//Create the button here
h.load_params = uicontrol ('style', 'pushbutton' , 'units' , 'normalized' , 'string' , 'new parameters' , 'callback' , #load_parameters)
Related
I want to create a custom processing algorithm with PyQGIS, which is able to take a vector layer as input (in this case of type point) and then do something with it's features. It's working well as long as I just choose the whole layer. But it doesn't work if I'm trying to work on selected features only.
I'm using QgsProcessingParameterFeatureSource to be able to work on selected features only. The option is shown and I can enable the checkbox. But when I'm executing the algorithm, I get NoneType as return of parameterAsVectorLayer.
Below you'll find a minimal working example to reproduce the problem:
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (
QgsProcessing,
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource
)
name = "selectedonly"
display_name = "Selected features only example"
group = "Test"
group_id = "test"
short_help_string = "Minimal working example code for showing my problem."
class ExampleProcessingAlgorithm(QgsProcessingAlgorithm):
def tr(self, string):
return QCoreApplication.translate('Processing', string)
def createInstance(self):
return ExampleProcessingAlgorithm()
def name(self):
return name
def displayName(self):
return self.tr(display_name)
def group(self):
return self.tr(group)
def groupId(self):
return group_id
def shortHelpString(self):
return self.tr(short_help_string)
def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterFeatureSource(
'INPUT',
self.tr('Some point vector layer.'),
types=[QgsProcessing.TypeVectorPoint]
)
)
def processAlgorithm(self, parameters, context, feedback):
layer = self.parameterAsVectorLayer(
parameters,
'INPUT',
context
)
return {"OUTPUT": layer}
If I'm working on the whole layer, the output is {'OUTPUT': <QgsVectorLayer: 'Neuer Temporärlayer' (memory)>}, which is what I would expect.
If I'm working on selected features only, my output is {'OUTPUT': None}, which doesn't makes sense to me. I selected some of the features before executing of course.
I'm using QGIS-version 3.22 LTR, if it's relevant.
Can anybody tell me what I'm doing wrong?
I would suggest you trying to use the method 'parameterAsSource' in the 'processAlgorithm' method.
layer = self.parameterAsSource(
parameters,
'INPUT',
context
)
I have been searching for ar.js multimarkers tutorial or anything that explains about it. But all I can find is 2 examples, but no tutorials or explanations.
So far, I understand that it requires to learn the pattern or order of the markers, then it stores it in localStorage. This data is used later to display the image.
What I don't understand, is how this "learner" is implemented. Also, the learning process is only used once by the "creator", right? The output file should be stored and then served later when needed, not created from scratch at each person's phone or computer.
Any help is appreciated.
Since the question is mostly about the learner page, I'll try to break it down as much as i can:
1) You need to have an array of {type, URL} objects.
A sample of creating the default array is shown below (source code):
var markersControlsParameters = [
{
type : 'pattern',
patternUrl : 'examples/marker-training/examples/pattern-files/pattern-hiro.patt',
},
{
type : 'pattern',
patternUrl : 'examples/marker-training/examples/pattern-files/pattern-kanji.patt',
}]
2) You need to feed this to the 'learner' object.
By default the above object is being encoded into the url (source) and then decoded by the learner site. What is important, happens on the site:
for each object in the array, an ArMarkerControls object is created and stored:
// array.forEach(function(markerParams){
var markerRoot = new THREE.Group()
scene.add(markerRoot)
// create markerControls for our markerRoot
var markerControls = new THREEx.ArMarkerControls(arToolkitContext, markerRoot, markerParams)
subMarkersControls.push(markerControls)
The subMarkersControls is used to create the object used to do the learning. At long last:
var multiMarkerLearning = new THREEx.ArMultiMakersLearning(arToolkitContext, subMarkersControls)
The example learner site has multiple utility functions, but as far as i know, the most important here are the ArMultiMakersLearning members which can be used in the following order (or any other):
// this method resets previously collected statistics
multiMarkerLearning.resetStats()
// this member flag enables data collection
multiMarkerLearning.enabled = true
// this member flag stops data collection
multiMarkerLearning.enabled = false
// To obtain the 'learned' data, simply call .toJSON()
var jsonString = multiMarkerLearning.toJSON()
Thats all. If you store the jsonString as
localStorage.setItem('ARjsMultiMarkerFile', jsonString);
then it will be used as the default multimarker file later on. If you want a custom name or more areas - then you'll have to modify the name in the source code.
3) 2.1.4 debugUI
It seems that the debug UI is broken - the UI buttons do exist but are nowhere to be seen. A hot fix would be using the 'markersAreaEnabled' span style for the div
containing the buttons (see this source bit).
It's all in this glitch, you can find it under the phrase 'CHANGES HERE' in the arjs code.
I'm fairly new to programming so please be patient with me. I'm trying to create a simple script in Autodesk Maya. I've created a method that sets up two check-boxes side by side (See below)...
def checkboxLayout(self, name1, text1, name2, text2, parentLayout, initState):
##create and add horizontal layout
layout = QtGui.QHBoxLayout()
parentLayout.addLayout(layout)
width = 75
name1 = QtGui.QCheckBox(text1)
layout.addWidget(name1)
name1.setMinimumWidth(width)
name1.setMaximumWidth(width)
name1.setChecked(initState)
name2 = QtGui.QCheckBox(text2)
layout.addWidget(name2)
name2.setMinimumWidth(width)
name2.setMaximumWidth(width)
And later on I've called this method twice in order to save me having to write out the same big block of code twice...
def createLayout(self):
##Layout
mainLayout = QtGui.QVBoxLayout()
mainLayout.addWidget(self.title)
mainLayout.addSpacerItem(self.titleSpacer)
mainLayout.addWidget(self.oldLabel)
self.checkboxLayout("selection_CB", "Selection", "name_CB", "Name", mainLayout, True)
mainLayout.addWidget(self.textbox1)
mainLayout.addSpacerItem(self.midSpacer)
mainLayout.addWidget(self.newLabel)
mainLayout.addWidget(self.textbox2)
self.checkboxLayout("delHistory_CB", "Delete\nHistory", "freezeTrans_CB", "Freeze\nTransforms", mainLayout, False)
self.buttonLayout = QtGui.QGridLayout()
mainLayout.addLayout(self.buttonLayout)
self.buttonLayout.addWidget(self.cancelButton, 0, 0)
self.buttonLayout.addWidget(self.okButton, 0, 1)
self.setLayout(mainLayout)
My problem is that when I try to connect a signal to it, it won't work. All the tutorials I've watched so far have only connected signals to widgets that WERE NOT created by calling a method inside another method (I realize that probably isn't the correct terminology but like I said, I'm new to this :( ) I'll post the code that I've written to try and connect the signal below. My guess was that I had to specify the method that created the check box, but I couldn't get that to work either. So how do I get this signal connected? Also feel free to correct my terminology :) Thanks to anyone who can help :)
def createConnections(self):
self.selection_CB.toggled.connect(self.checkboxLine1_ChangeState)
Where and how are you setting the variable self.selection_CB?
In your checkboxLayout function you can include a return for your check box like so:
`return [name1, name2]`
then simply assign them as you're calling the function and connect the events from there:
self.check1, self.check2 = self.checkboxLayout("selection_CB", "Selection", "name_CB", "Name", mainLayout, True)
Or if they are always being connected to the same functions, then why not just do the connection straight from checkboxLayout?
name1.stateChanged.connect(self.checkboxLine1_ChangeState)
I've created an ALV tree view with use of the class CL_SALV_TREE.
Everything works fine but I'd like to grap the event when a node is expanded, for filling in a function that automatically resizes the tree columns.
My problem is, that the expanding event is the private method HANDLE_EXPAND_NC of class CL_GUI_ALV_TREE and I actually don't know how to capture this event. I'm open for any ideas and thanks for your time.
As far as I know, you can only be notified if a folder is expanded that does not yet contain children (the _NC part of the method/event name signifies that). This is intended for lazy loading of the tree. The tree displays in the SAP menu or the IMG are a good example for that - you can actually see parts of the tree being loaded when you expand the top-level nodes.
If that is sufficient for you, use the event EXPAND_EMPTY_FOLDER of the interface IF_SALV_EVENTS_TREE, implemented by CL_SALV_EVENTS_TREE. There doesn't seem to be a good demo program for this though.
Here is a minimal reproducible example which shows that the event EXPAND_EMPTY_FOLDER is triggered when you expand a node which has no children initially, a child node is added during that event:
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS pbo
RAISING
cx_salv_error.
PRIVATE SECTION.
DATA: salv TYPE REF TO cl_salv_tree,
scarrs TYPE STANDARD TABLE OF scarr.
METHODS on_expand_empty_folder
FOR EVENT expand_empty_folder
OF cl_salv_events_tree
IMPORTING node_key.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD pbo.
IF salv IS NOT BOUND.
cl_salv_tree=>factory( EXPORTING r_container = cl_gui_container=>screen0
IMPORTING r_salv_tree = salv
CHANGING t_table = scarrs ).
DATA(lo_settings) = salv->get_tree_settings( ).
lo_settings->set_hierarchy_size( 30 ).
DATA(event) = salv->get_event( ).
salv->get_functions( )->add_function( name = 'NEW' text = 'NEW' tooltip = '' position = 1 ).
SET HANDLER on_expand_empty_folder FOR event.
SELECT * FROM scarr INTO TABLE #DATA(local_scarrs).
LOOP AT local_scarrs REFERENCE INTO DATA(scarr).
salv->get_nodes( )->add_node(
related_node = space " (root node)
relationship = cl_gui_column_tree=>relat_last_child
text = |{ scarr->carrid } - { scarr->carrname }|
data_row = scarr->*
folder = abap_true
expander = abap_true ).
ENDLOOP.
salv->display( ).
ENDIF.
LOOP AT SCREEN.
screen-active = '0'.
MODIFY SCREEN.
ENDLOOP.
ENDMETHOD.
METHOD on_expand_empty_folder.
TRY.
DATA(scarr) = CAST scarr( salv->get_nodes( )->get_node( node_key )->get_data_row( ) )->*.
salv->get_nodes( )->add_node(
related_node = node_key
relationship = cl_gui_column_tree=>relat_last_child
text = |Node added at time of expand below { scarr-carrid }| ).
CATCH cx_root INTO DATA(lx).
MESSAGE lx TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
ENDMETHOD.
ENDCLASS.
PARAMETERS dummy.
LOAD-OF-PROGRAM.
DATA(app) = NEW lcl_app( ).
AT SELECTION-SCREEN OUTPUT.
TRY.
app->pbo( ).
CATCH cx_root INTO DATA(lx).
MESSAGE lx TYPE 'S' DISPLAY LIKE 'E'.
ENDTRY.
I am trying to export an Excel spreadsheet to SharePoint. I recorded the Visual Basic code, and now I want to translate it to Perl. I tried like this but it didn't work.
I don't get any error, but I also don't see the list in the Sharepoint. When I did it using the macro in Excel it worked
use Win32::OLE::Const 'Microsoft Excel';
my $excel = Win32::OLE->new('Excel.Application');
$excel->{'Visible'} = 1;
$excel->{DisplayAlerts} = 1;
my $book = $excel->Workbooks->Open("C:\\Book1.xlsx")
|| die("Unable to open document ", Win32::OLE->LastError());
my $list = $book->ActiveSheet->ListObjects("Table1")->Publish Array("https:\/\/sponsor\/sites\/dev_test_site", "myname"), False;
The original Visual Basic code
Sub Macro1()
ActiveSheet.ListObjects("Table1").Publish Array( _
"https://sponsor/sites/dev_test_site", "myname"), False
Range("C2").Select
End Sub
Eventually I came up with this code
my $excel = Win32::OLE->new('Excel.Application');
$excel->{'Visible'} = 1;
$excel->{DisplayAlerts} = 1;
my $book = $excel->Workbooks->Open("C:\\Book1.xlsm")
|| die("Unable to open document ", Win32::OLE->LastError());
my #array=("https:\/\/sponsor\/sites\/dev_test_site", "aaaa");
my $list= $book->ActiveSheet->ListObjects("hhhh")->Publish(#array, 0);
And this image shows the result
You should use strict and use warnings. It will proceed to tell you a number of error messages then.
What I can make out from the Perl code you posted without running it is:
my $list= $book->ActiveSheet->ListObjects("Table1")->Publish Array("https:\/\/sponsor\/sites\/dev_test_site", "myname"), False;
Note that there is a space between Publish and Array(. That has to be a problem. The only way to have a function cal followed by something other than ( or ; or , is if it has prototypes. But method calls in object oriented Perl cannot have prototypes. So that is definitely wrong.
Then there's Array(...). There is no built-in function called Array and I do not think that Win32::OLE::Const exports that, though I did not look. Even if it did, you told it to only export 'Microsoft Excel'. The same goes for False.
I suggest you read the documentation of Win32::OLE::Const and add use strict and use warnings. There are also some resources of how to work with Win32 modules on Sinan Ünürs blog.
You could take a look at this: Convert perl script to vba This already has some answers.
You may need to follow this script. % pp -o hello hello.pl or something like that.