Commits

Henning Schröder  committed 4b218a1

widgetCreated signal calls setupUi asynchronously

  • Participants
  • Parent commits 51d5f6a

Comments (0)

Files changed (1)

File tgui/twidget.py

 
 class TWidget(TObject):
 
+    widgetCreated = Signal()
+
     def __init__(self, parent=None, **kwargs):
         self._contents_margins = TMargins(0, 0, 0, 0)
         self._focus_policy = TFocusPolicy.TabFocus
         self._geom = (0, 0, 1, 1)
         self._visible = True
         self._focus_widget = None
-        self._palette = TPalette()
-        self._windowTitle = ""
+        self._palette = kwargs.pop("Palette", None) or TPalette()
+        self._windowTitle = u""
         self._actions = []
         self._cursor = TCursor.NORMAL
         self._cursorPosition = TPoint(0, 0)
         super(TWidget, self).__init__(parent, **kwargs)
         if not parent:
             self.activateWindow()
+        self.widgetCreated.connect(self.setupUi)
+        self.widgetCreated.emit()  # will be called later in event loop
+
+    def setupUi(self):
+        pass
 
     def cursor(self):
         return self._cursor
         return self._windowTitle
 
     def setWindowTitle(self, title):
-        self._windowTitle = title or ""
+        self._windowTitle = title or u""
         if not self.parent():
             self.update()
 
     def paintEvent(self, event):
         painter = TPainter(self)
         if self.parent():
-            painter.fillRect(self.geometry(), " ")
+            painter.fillRect(self.geometry(), u" ")
         else:
             # This is a dialog/window
             rect = self.geometry()
             painter.drawRect(rect)
-            painter.fillRect(rect.inner(), " ")
+            painter.fillRect(rect.inner(), u" ")
             pos = self.pos()
-            painter.drawText(pos.x + self.width() - 4, pos.y, "[*]")
-            painter.drawText(pos.x + 2, pos.y, " %s " %
+            painter.drawText(pos.x + self.width() - 4, pos.y, u"[*]")
+            painter.drawText(pos.x + 2, pos.y, u" %s " %
                              elide(self.windowTitle(), self.width() - 4))
         for child in self.children():
             if isinstance(child, TWidget) and child.isVisible():