title: In PyQT how to open a child window that has access to the parent's attributes?
body: <p>I have an engine module that contains several helper methods and attributes:</p>
  
  <p><strong>engine.py</strong></p>
  
  <pre><code>class World:
      def __init__(self):
          # stuff
  
      def foo(a, b):
          c = a + b # trivial example
          return c
  </code></pre>
  
  <p>Then I have a main.py which incorporates the UI files (created in QtDesigner and converted to .py using a script I have):</p>
  
  <p><strong>main.py</strong></p>
  
  <pre><code>from PyQt4 import QtGui
  import design1
  import design2
  import engine
  
  class MainWindow(QtGui.QMainWindow, design1.Ui_MainWindow):
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.setupUi(self)
          self.world = engine.World()
  
          self.new_window_button.clicked.connect(self.open_new_window)
  
      def open_new_window(self):
          self.window_to_open = ChildWindow(self)
          self.window_to_open.show()
  
  class ChildWindow(QtGui.QMainWindow, design2.Ui_MainWindow):
      def __init__(self, parent):
          super(ChildWindow, self).__init__(parent)
          self.setupUi(self)
          print(self.world.foo(1, 2)) # trivial example
  
  def main():
      app = QtGui.QApplication(sys.argv)
      window = MainWindow()
      window.show()
      app.exec()
  </code></pre>
  
  <p>If I take out the <code>print</code> line, <code>ChildWindow</code> opens fine. But with it in I get the error: </p>
  
  <blockquote>
    <p>AttributeError: 'ChildWindow' object has no attribute 'world'</p>
  </blockquote>
  
  <p>I know I'm doing something silly but I can't figure it out.</p>
  
  <p><strong>edited main.py</strong></p>
  
  <pre><code>from PyQt4 import QtGui
  import design1
  import design2
  import engine
  
  class MainWindow(QtGui.QMainWindow, design1.Ui_MainWindow):
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.setupUi(self)
          self.world = engine.World()
  
          self.new_window_button.clicked.connect(self.open_new_window)
  
      def open_new_window(self):
          self.window_to_open = ChildWindow(self)
          self.window_to_open.show()
  
  class ChildWindow(QtGui.QMainWindow, design2.Ui_MainWindow):
      def __init__(self, parent):
          super(ChildWindow, self).__init__(parent)
          self.setupUi(self)
          print(self.parent().world.foo(1, 2)) # trivial example
  
  def main():
      app = QtGui.QApplication(sys.argv)
      window = MainWindow()
      window.show()
      app.exec()
  </code></pre>
  
  <p>I now get the error:</p>
  
  <blockquote>
    <p>TypeError: foo() takes 2 positional arguments but 3 were given</p>
  </blockquote>