I am trying to migrate a plugin. I have these two lines:  QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Configuration.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Configuration.reject)   I thought after looking into some examples that in PyQt5 the lines should read:  self.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Configuration.accept) self.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Configuration.reject)   but it just throws the error  AttributeError: 'ConfigurationDialog' object has no attribute 'QObject'   This is confusing because ConfigurationDialog is not found in this py script. ConfigurationDialog is a class in another script but nowhere in it does it make reference to QObject. Can I get some clarification on what where I am going wrong?
31683
A while ago I made a plugin for QGIS for myself.  This worked until version 2.18. Now I have version 3.0 and would like to use this plugin here too. But I get some error messages. I have been able to solve most of them fairly easily. Only I can not do this. Perhaps there is someone among you who can help me in this.   This is the code that I used before.   def initGui(self):     """Create menu entries and toolbar icons inside the QGIS GUI."""      icon_path = ":/plugins/BFVWtools/"      """Create the menu entrie Configuratie and toolbar icon inside the QGIS GUI."""     self.add_action(icon_path + "/icon.png", text=self.tr(u'Configuratie'),      callback=self.run, parent=self.iface.mainWindow())     self.action = QAction( QIcon( os.path.dirname(os.path.realpath(__file__)) + "/icon.png" ), "Configuratie",      self.iface.mainWindow() )     QObject.connect(self.action, SIGNAL("triggered()"), self.run)   The error message I get is the following  AttributeError: type object 'QObject' has no attribute 'connect'  Traceback (most recent call last):   File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 345, in startPlugin plugins[packageName].initGui()   File "C:/Users/Automatisering/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\BFVWtools\bfvw_tools.py", line 212, in initGui QObject.connect(self.action, SIGNAL("triggered()"), self.run) AttributeError: type object 'QObject' has no attribute 'connect'   Apparently there is no attribute 'Connect' in QObject    After your explanation, I have converted everything to PyQt5 and changed the connect to slot. The strange thing is that I now get all the entrys from the menu one after the other.
15982
What are Ctools plugins, and how does one create them?
848
I'm writing a Python application that takes as a command as an argument, for example:  $ python myapp.py command1   I want the application to be extensible, that is, to be able to add new modules that implement new commands without having to change the main application source. The tree looks something like:  myapp/     __init__.py     commands/         __init__.py         command1.py         command2.py     foo.py     bar.py   So I want the application to find the available command modules at runtime and execute the appropriate one.  Python defines an __import__ function, which takes a string for a module name:     __import__(name, globals=None, locals=None, fromlist=(), level=0)      The function imports the module name, potentially using the given globals and locals to determine how to interpret the name in a package context. The fromlist gives the names of objects or submodules that should be imported from the module given by name.       Source:    So currently I have something like:  command = sys.argv[1] try:     command_module = __import__("myapp.commands.%s" % command, fromlist=["myapp.commands"]) except ImportError:     # Display error message  command_module.run()   This works just fine, I'm just wondering if there is possibly a more idiomatic way to accomplish what we are doing with this code.  Note that I specifically don't want to get in to using eggs or extension points. This is not an open-source project and I don't expect there to be "plugins". The point is to simplify the main application code and remove the need to modify it each time a new command module is added.
49049
Error Message:  Oops! Your question couldn't be submitted because: Please add some context to explain the code sections (or check that you have not incorrectly formatted all of your question as code).  How do I fix this issue? It says that I need to explain my code more when I try to post this as google-apps-script. I have explained almost every part of the code. Also, this code was posted previously and I just added a few extra lines with explanations. What do they mean by &quot;context&quot; function doGet() {   var app = UiApp.createApplication();   //Create listBox   var listBox = app.createListBox();   //Add items to listBox   listBox.addItem(&quot;item 1&quot;).addItem(&quot;item 2&quot;).addItem(&quot;item 3&quot;).setName(&quot;myListBox&quot;);   //Create hidden app   var hidden = app.createHidden().setName('hidden').setId('hidden')   //Create button handler   var handler = app.createServerHandler(&quot;buttonHandler&quot;);   // pass the listbox into the handler function as a parameter and the hidden widget as well   handler.addCallbackElement(listBox).addCallbackElement(hidden);    //Create flextable   var table = app.createFlexTable().setId(&quot;myTable&quot;);    //Create flex table style attributes     table.setStyleAttribute(&quot;border-style&quot;, &quot;solid&quot;)     table.setStyleAttribute(&quot;border-width&quot;, &quot;1px&quot;)     table.setCellPadding(1);      //Create flex table headers   table.setWidget(0, 0, app.createLabel(&quot;Product Type&quot;)).setStyleAttribute(&quot;color&quot;, &quot;blue&quot;);   table.setWidget(0, 5, app.createLabel(&quot;Size&quot;));    var button = app.createButton(&quot;+&quot;, handler);    // add all widgets to the app   app.add(table).add(hidden);   app.add(listBox).add(button)   return app; }  function buttonHandler(e) {   var app = UiApp.getActiveApplication();   // get the position (is a string)   var pos = e.parameter.hidden;   // initial condition, hidden widget is empty    if(pos==null){pos='0'};   // convert to number    pos=Number(pos);   var table = app.getElementById(&quot;myTable&quot;);   // add the new item at the right place   table.insertRow(pos).insertCell( pos, 0).setText(pos, 0, e.parameter.myListBox);   // increment position   ++pos;   // save value   app.getElementById('hidden').setValue(pos);   // update app   return app; }
24571
That is, can python code replace, for example, a single letter in a Text Object or insert a letter or string into a Text Object.  Note that I'm not talking about replacing a Text Object with some updated string, such as, object.text = "new string". I'm thinking more about having access to the Text cursor (not the mouse cursor) and positioning it on some letter that I'd like to replace.  In other words, I'd like to have the same capability during BGE play that I have when altering a Text Object in the edit mode.
30588
I am trying to talk to the PyQGIS API for use in a 3rd party application using the offical .dmg image provided on the QGIS homepage.  After setting PYTHONPATH to /Applications/QGIS3.4.app/Contents/Resources/python and initializing everything as stated in , I am facing the following error when running from PyQt5.QtGui import or from qgis import *:    ImportError: dlopen(/Applications/QGIS3.4.app/Contents/Resources/python/PyQt5/QtGui.so, 2): Library not loaded: @executable_path/../Frameworks/QtGui.framework/QtGui   Referenced from: /Applications/QGIS3.4.app/Contents/Resources/python/PyQt5/QtGui.so   Reason: image not found   Looks like I need to set some linkers or similar?   Side facts: - I have no problems when using the homebrew version of QGIS). - I am on macOS 10.14.6 (Mojave)
63383
The code below works flawless, if e.g. triggered by a menu button in a 3D view.          for area in bpy.context.screen.areas:            if area.type == 'VIEW_3D':             for space in area.spaces:                 if space.type == 'VIEW_3D':                      space.viewport_shade = 'BOUNDBOX'   However, if I bundle it into a function and hook it to a handler, it returns a NoneType error:  @persistent def allBound(dummy):   for area in bpy.context.screen.areas:        if area.type == 'VIEW_3D':         for space in area.spaces:             if space.type == 'VIEW_3D':                  space.viewport_shade = 'BOUNDBOX'   bpy.app.handlers.render_pre.append(allBound)   Returns:  AttributeError: 'NoneType' object has no attribute 'areas'   How to solve this?
29272
The dialog above is created with the code below. When I click on the file icon (see red arrow), nothing happens. Is there a proper way to get these to just work or at least point to a custom operator which invokes context.window_manager.fileselect_add(self) or something similar?  It really seems like the functionality I want should be built into the StringProperty when using FILE_PATH as a subtype... I must be missing something obvious.  What I am trying to do is execute a single operation that requires selecting more than one file path. I can invoke 2 fileselect_add's one after the other, but it becomes confusing because right when you click to accept the path the new path window opens immediately. It is just too confusing as to which one is being selected as there is really no way to customize the fileselect_add window to any usefull degree (as far as I am aware) to make it more obvious what the user is selecting.  Dialog code:  class mydialog(bpy.types.Operator):         bl_idname = "tools.mydialog"         bl_label = "My Dialog"          inFilePath = StringProperty(name="input file", subtype="FILE_PATH")         outFilePrefix = StringProperty(name="out prefix", subtype="FILE_PATH")      def invoke(self, context, event):         return context.window_manager.invoke_props_dialog(self)      def execute(self, context):         print(self.inFilePath)         print(self.outFilePrefix)         return {'FINISHED'}
96847
I have a code sample that gets a SEL from the current object,   SEL callback = @selector(mymethod:parameter2);   And I have a method like    -(void)mymethod:(id)v1 parameter2;(NSString*)v2 { }   Now I need to move mymethod to another object, say myDelegate.  I have tried:  SEL callback = @selector(myDelegate, mymethod:parameter2);   but it won't compile.
100108
I have a statement,     Either p or q   and I have to write it in terms of logical connectives but I don't get which logical connector should I be using? Here is what I did (I think there could have been a better way to do this)     $(p \lor q ) \land (\neg((p \Rightarrow q) \land (q \Rightarrow p)))$
69758
Is it (if at all) possible in Blender 2.6+?   If not, will future versions of Blender support it?  I see some old posts ( and ) saying that it is not possible. However, I found  referring to operators under  that allowed me to add sensors and controllers from python.  bpy.ops.logic.sensor_add(type='ALWAYS', object=my_obj.name) bpy.ops.logic.controller_add(type='LOGIC_AND', object=my_obj.name)   However I am not able to find any way to link them from python. I tried following (but did not work):  new_controller = my_obj.controllers[-1] new_sensor = my_obj.sensors[-1]   It throws AttributeError saying that object has no attribute 'controllers' :-/
6086
Putting aside whether the use of , I have run into the following conundrum when trying to evaluate isinstance after serializing/deserializing an object via Pickle:  from __future__ import with_statement import pickle  # Simple class definition class myclass(object):     def __init__(self, data):         self.data = data  # Create an instance of the class x = myclass(100)  # Pickle the instance to a file with open("c:\\pickletest.dat", "wb") as f:     pickle.dump(x, f)  # Replace class with exact same definition class myclass(object):     def __init__(self, data):         self.data = data  # Read an object from the pickled file with open("c:\\pickletest.dat", "rb") as f:     x2 = pickle.load(f)  # The class names appear to match print x.__class__ print x2.__class__  # Uh oh, this fails...(why?) assert isinstance(x2, x.__class__)   Can anyone shed some light on why isinstance would fail in this situation? In other words, why does Python think these objects are of two different classes? When I remove the second class definition, isinstance works fine.
106843
def execute(self, context):     stl_path = bpy.path.abspath(bpy.context.scene.stl_path)     bpy.ops.import_mesh.stl(filepath=stl_path)     try:         ob_new = bpy.context.selected_objects[0]         for f in ob_new.data.polygons:             f.use_smooth = True         for b in ob_new.data.polygons:             bpy.context.space_data.show_textured_solid = True             bpy.context.object.show_transparent = True             bpy.context.scene.render.engine = 'CYCLES'             bpy.ops.object.editmode_toggle()                bpy.ops.mesh.select_all(action='TOGGLE')                             bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')             bpy.ops.mesh.select_all(action='TOGGLE')                 bpy.ops.mesh.tris_convert_to_quads()             bpy.ops.view3d.snap_cursor_to_selected()             bpy.ops.object.origin_set(type = 'ORIGIN_CURSOR')                   Everything is working well, until I use origin_set. Maybe I should go to object mode, after converting mesh to quads.  But when I'm adding bpy.ops.object.editmode_toggle() after tris_convert_to_quads Blender is freezing. Without this last command, everything is working, also snapping cursor to selected.    Ok, I changed script.  def execute(self, context):     stl_path = bpy.path.abspath(bpy.context.scene.stl_path)     bpy.ops.import_mesh.stl(filepath=stl_path)     try:         ob_new = bpy.context.selected_objects[0]         for f in ob_new.data.polygons:             f.use_smooth = True             bpy.context.object.show_transparent = True             bpy.context.scene.render.engine = 'CYCLES'             bpy.ops.object.editmode_toggle()             bpy.ops.mesh.select_all(action='TOGGLE')                             bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')             bpy.ops.mesh.select_all(action='TOGGLE')                 bpy.ops.mesh.tris_convert_to_quads()             bpy.ops.mesh.faces_shade_smooth()             bpy.ops.object.mode_set(mode='EDIT')             bpy.ops.mesh.select_all(action='TOGGLE')    to this line everything is ok, and script is ends in object mode. but If I add this line                 bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')  I have msg in console, that I must be in object mode. If i add this command                 bpy.ops.object.mode_set(mode='OBJECT') Blender is switching off.
101212
I'm trying to establish a Postgres connection using QgsCredentials as described here:    The only problem is that I cannot establish a working connection unless I "physically" add the layer to the map canvas (which I don't want because I only want a connection to the DB and a reference to the layer which will be edited later on in the code)  When clicking a button the run function reads:  uri = QgsDataSourceURI() connInfo = uri.connectionInfo()  (success, user, passwd) = QgsCredentials.instance().get(connInfo, None, None)  if success:     # Isn't this enough to establish the connection and get a valid reference to the layer?     uri.setConnection("HOST", "PORT", "DB_NAME", user, passwd)     uri.setDataSource("SCHEMA", "TABLE_NAME", "the_geom")     LYR = QgsVectorLayer(uri.uri(), "LYR", "postgres")      # Unless I add the following line, I am not able to use properly the object     # (which asks the user the credentials until he/she inserts the right ones and gets     # a working connection with a valid reference to the layer)     QgsMapLayerRegistry.instance().addMapLayer(LYR)   What am I doing wrong?  Thanks in advance,  m.
27329
A simple script created within the QGIS 2.18 processing toolbox:  ##example=string print example   Upon running would produce and input box in a window with a run button:   Once executed would produce the expected print in the python console  When testing the same code in QGIS-3.0, changing the print to python 3's print(), I get an error where the input section is seemingly ignored as a comment:   Does the processing framework no longer accept inputs in this way?
111550
I want to be able to create the circuit depicted below, but running the code below results in an empty circuit when viewing the job afterwards.  backend = provider.backends.ibmq_armonk   qreg_q = QuantumRegister(1, 'q') creg_c = ClassicalRegister(1, 'c') circuit = QuantumCircuit(qreg_q, creg_c)  circuit.u(pi/2, pi/2, pi/2, qreg_q[0]) circuit.x(qreg_q[0]) circuit.y(qreg_q[0]) circuit.x(qreg_q[0]) circuit.y(qreg_q[0]) circuit.u(pi/2, pi/2, pi/2, qreg_q[0]).inverse()  circuit.measure(qreg_q[0], creg_c[0])   qobj = assemble(transpile(circuit, backend=backend), backend=backend) job = backend.run(qobj) retrieved_job = backend.retrieve_job(job.job_id())
92610
I'm using Blender 2.8+ and I found a web page containing a nice . I copied the script in Blenders text editor and an error occurred at line 88:  bpy.context.scene.objects.link (object)      AttributeError: 'bpy_prop_collection' object has no attribute 'link'   Error: Python script failed, check the message in the system console   Unfortunately, I have no idea what a 'bpy_prop_collection' is and I don't know where to start fixing this issue. What I need to do in order to make the script work for Blender 2.8x?