Note that there are some explanatory texts on larger screens.

plurals
  1. POPyQt4 SIGNAL/SLOT problem when using sub-directories
    primarykey
    data
    text
    <p>Thanks in advance for taking the time to read this. Apologies that it is somewhat verbose. But hopefully it fully explains the problem. Stripped code demonstrating the issue is included.</p> <p>I'm having an issue with PyQt4 SIGNAL/SLOTS. While I can make everything work fine if I am writing in a single file, I can't make things work if I some of the functions I wish to use are moved to sub-directories/classes.</p> <p>I've looked through the <a href="http://web.archive.org/web/20080313110720/http://www.riverbankcomputing.com/Docs/PyQt4/pyqt4ref.html#signal-and-slot-support---" rel="nofollow">Python Bindings document</a> I can see how this works when using a single file. But what I am trying to do is this:</p> <ul> <li>main.py file in root dir which contains the MainWindow <code>__init_</code>_ code.</li> <li>This file imports a number of widgets. Each widget is stored in its own sub-directory. All sub-directories contain an <code>__init__.py</code> file. These sub-directories are inside of a directory called 'bin', which is itself in the root dir</li> <li>Some of these widgets need to have SIGNAL/SLOT links between them This is where I fall down.</li> </ul> <p>So the file structure is:</p> <pre><code> - main.py - bin/textEditor/__init__.py - bin/textEditor/plugin.py - bin/logWindow/__init__.py - bin/logWindow/plugin.py </code></pre> <p>The following code shows the problem. This code creates a very basic main window that contains a central <code>QTextEdit()</code> widget and a dockable <code>QTextEdit()</code> widget. All that happens is that when the text in the central widget is changed, the same text is shown in the dockable widget. The example works. But it does so by connecting the signal textChanged() in the <code>bin/textEditor/plugin.py</code> file that creates the central <code>QTextEdit()</code> with a function in <code>main.py</code>. I would like it to do exactly the same thing but connexted to the updateUi function in <code>bin/textEditor/plugin.py</code></p> <p>If anyone could shed some light on this, I would be hugely grateful. I'm sure it is simple. But direction to any tutorials that cover this or statements that I am doing it all very wrong are equally appreciated!. Thanks again for your time:</p> <pre><code>### main.py import os import sys # Import PyQT modules from PyQt4.QtCore import * from PyQt4.QtGui import * # Start the main class class MainWindow(QMainWindow): # Initialise def __init__(self, parent=None): super(MainWindow, self).__init__(parent) # Name and size the main window self.setWindowTitle("EDITOR/LOG") self.resize(800, 600) import bin.logWindow.plugin as logWindow logWindow.create(self) import bin.textEditor.plugin as textEditor textEditor.create(self) def updateUi(self): # I can connect to this function from within bin/textEditor/plugin.py (see # below) but I want to connect to the function located in # bin/textEditor/plugin.py instead text = self.editor.toPlainText() self.logWidget.setText(text) # Run the app def main(): app = QApplication(sys.argv) form = MainWindow() form.show() app.exec_() # Call main main() </code></pre> <p>The code inside of the two plugin files is:</p> <pre><code>### bin/textEditor/plugin.py # Import PyQT modules from PyQt4.QtCore import * from PyQt4.QtGui import * def create(self): # Add a 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) </code></pre> <p>And</p> <pre><code>### bin/logWindow/plugin.py Import PyQT modules from PyQt4.QtCore import * from PyQt4.QtGui import * def create(self): # Create a text editing box self.editor = QTextEdit() # Add to main window self.setCentralWidget(self.editor) # connect text change to update log window. This is presumably what I need to # change so that it connects to the function below instead of the on in main.py self.connect(self.editor, SIGNAL("textChanged()"), self.updateUi) def updateUi(self): text = self.editor.toPlainText() self.logWidget.setText(text) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload