python - PyQt4 SIGNAL/SLOT problem when using sub-directories -


thanks in advance taking time read this. apologies verbose. explains problem. stripped code demonstrating issue included.

i'm having issue pyqt4 signal/slots. while can make work fine if writing in single file, can't make things work if of functions wish use moved sub-directories/classes.

i've looked through python bindings document can see how works when using single file. trying this:

  • main.py file in root dir contains mainwindow __init__ code.
  • this file imports number of widgets. each widget stored in own sub-directory. sub-directories contain __init__.py file. these sub-directories inside of directory called 'bin', in root dir
  • some of these widgets need have signal/slot links between them fall down.

so file structure is:

 - main.py  - bin/texteditor/__init__.py  - bin/texteditor/plugin.py  - bin/logwindow/__init__.py  - bin/logwindow/plugin.py 

the following code shows problem. code creates basic main window contains central qtextedit() widget , dockable qtextedit() widget. happens when text in central widget changed, same text shown in dockable widget. example works. connecting signal textchanged() in bin/texteditor/plugin.py file creates central qtextedit() function in main.py. same thing connexted updateui function in bin/texteditor/plugin.py

if shed light on this, hugely grateful. i'm sure simple. direction tutorials cover or statements doing wrong equally appreciated!. again time:

### main.py import os import sys # import pyqt modules pyqt4.qtcore import * pyqt4.qtgui import *  # start main class class mainwindow(qmainwindow):      # initialise     def __init__(self, parent=none):         super(mainwindow, self).__init__(parent)          # name , size main window         self.setwindowtitle("editor/log")         self.resize(800, 600)          import bin.logwindow.plugin logwindow         logwindow.create(self)          import bin.texteditor.plugin texteditor         texteditor.create(self)      def updateui(self):          # can connect function within bin/texteditor/plugin.py (see          # below) want connect function located in          # bin/texteditor/plugin.py instead         text = self.editor.toplaintext()         self.logwidget.settext(text)  # run app def main():     app = qapplication(sys.argv)     form = mainwindow()     form.show()     app.exec_() # call main main() 

the code inside of 2 plugin files is:

### bin/texteditor/plugin.py # import pyqt modules pyqt4.qtcore import * pyqt4.qtgui import *  def create(self):     # add dockable widget     self.logdockwidget = qdockwidget("log", self)     self.logdockwidget.setobjectname("logdockwidget")     self.logdockwidget.setallowedareas(qt.leftdockwidgetarea|                                        qt.rightdockwidgetarea)      self.logwidget = qtextedit()     self.logdockwidget.setwidget(self.logwidget)     self.adddockwidget(qt.leftdockwidgetarea, self.logdockwidget) 

and

### bin/logwindow/plugin.py import pyqt modules pyqt4.qtcore import * pyqt4.qtgui import *  def create(self):      # create text editing box     self.editor = qtextedit()      # add main window     self.setcentralwidget(self.editor)      # connect text change update log window. presumably need      # change connects function below instead of on in main.py     self.connect(self.editor, signal("textchanged()"), self.updateui)  def updateui(self):     text = self.editor.toplaintext()     self.logwidget.settext(text) 

for starters, there reason you're using old version of pyqt release document? new 1 is: here

there few things doing bit unusual. import statements in python placed @ top of file (to more see dependencies), assume you're doing support more generalized import system plugins in future.

it seems basic problem you're trying connect signal source slot in object, without storing other object in particular place. need either make connection in main, make neutral "updateui" slot emits it's own special signal plugins waiting for, or keep reference subobjects in main , careful initialization order.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -