1. Henning Schröder
  2. ttgui

Commits

Henning Schröder  committed 646ea86

started TLineEdit, slots will be called async now

  • Participants
  • Parent commits aa5bb0f
  • Branches default

Comments (0)

Files changed (3)

File tcore.py

View file
     def __cmp__(self, other):
         return cmp((self.x, self.y), (other.x, other.y))
 
+    
+    def __add__(self, other):
+        return Point(self.x + other.x, self.y + other.y)
+
+    
+    def __sub__(self, other):
+        return Point(self.x - other.x, self.y - other.y)
+
+    
+    def manhattanLength(self):
+        return self.x**2 + self.y**2
 
         
         
     def __init__(self, x1, y1, width, height):
         self._topLeft = TPoint(x1,y1)
         self._size = TSize(width,height)
-    
+
         
+    def __cmp__(self, other):
+        return cmp((self._topLeft, self._size), (other._topLeft, other._size))
+        
+
     @property
     def size(self):
         return self._size
 
 
 
+class TInvokeEvent(TEvent):
+    
+    def __init__(self, slot, args):
+        super(TInvokeEvent, self).__init__(-1)
+        self.slot = slot
+        self.args = args
+
+
+        
 
 class TEventLoop(object):
     _instance = None
         self.slots.add(slot)
         
         
-    def emit(self, *args):
+    def emit(self, *args, **kwargs):
+        direct = kwargs.pop("direct", False)
+        if kwargs:
+            raise TypeError("Unknown keyword arguments %r" % kwargs)
         if self.sender.signalsBlocked():
             return
         TObject._sender = self.sender
         for ref in self.slots:
             slot = ref()
             if slot:
-                slot(*args)
+                if direct:
+                    slot(*args)
+                else:
+                    # queued
+                    self.sender.postEvent(TInvokeEvent(slot, args))
+
         # Object.sender = None
 
 
         for receiver_object in self._event_filters:
             if receiver_object.eventFilter(self, event):
                 return
+        if isinstance(event, TInvokeEvent):
+            event.slot(*event.args)
 
     
     def eventFilter(self, obj, event):

File test.py

View file
-from tgui import TApplication, TWidget, TLabel, TPoint, TSize, TPushButton, TCheckBox
+from tgui import TApplication, TWidget, TLabel, TPoint, TSize, TPushButton, TCheckBox, TLineEdit
 
 
 def test():
 q.move(20, 5)
 q.clicked.connect(exit)
 
+e = TLineEdit(win, Text="edit me..", Pos=(3,4), Size=(10,1))
+
 win.show()
 
 app.run()

File tgui.py

View file
 
         
 class TToolButton(TAbstractButton):
-    pass
+    pass
+
+
+
+class TLineEdit(TWidget):
+
+    def __init__(self, parent, **kwargs):
+        self._text = ""
+        self._cursorPosition = 0
+        self._cursor_offset = 0
+        super(TLineEdit, self).__init__(parent, **kwargs)
+        
+        
+    def text(self):
+        return self._text
+    
+    
+    def setText(self, text):
+        self._text = text
+        self.update()        
+    
+    Text = Property(text, setText)
+        
+
+    def cursorPosition(self):
+        return self._cursorPosition
+    
+    
+    def setCursorPosition(self, pos):
+        self._cursorPosition = pos
+        
+        
+    CursorPosition = Property(cursorPosition, setCursorPosition)
+
+    
+    def focusInEvent(self, event):
+        pos = self.mapToGlobal(self.pos())
+        Console.instance.gotoxy(pos.x + self.cursorPosition(), pos.y)
+        Console.instance.show_cursor()
+        
+    
+    def paintEvent(self, event):
+        painter = TPainter(self)
+        text = self.text()[self._cursor_offset:]
+        painter.drawText(self.pos(), text)
+
+        
+    def keyPressEvent(self, event):
+        if event.key:
+            text = self.text()
+            cpos = self.cursorPosition()
+            new_text = text[:cpos] + event.key + text[cpos:]
+            self.setText(new_text)
+            self.setCursorPosition(cpos + 1)
+
+        super(TLineEdit, self).keyPressEvent(event)
+
+        
+