Commits

Henning Schröder  committed 2544b2a

added window title and nice borders

  • Participants
  • Parent commits 5447f6d

Comments (0)

Files changed (4)

         curses.curs_set(0)
 
 
+    def rectangle(self, ulx, uly, lrx, lry):
+        # taken from curses.textpad
+        self.window.vline(uly+1, ulx, curses.ACS_VLINE, lry - uly - 1)
+        self.window.hline(uly, ulx+1, curses.ACS_HLINE, lrx - ulx - 1)
+        self.window.hline(lry, ulx+1, curses.ACS_HLINE, lrx - ulx - 1)
+        self.window.vline(uly+1, lrx, curses.ACS_VLINE, lry - uly - 1)
+        self.window.addch(uly, ulx, curses.ACS_ULCORNER)
+        self.window.addch(uly, lrx, curses.ACS_URCORNER)
+        self.window.addch(lry, lrx, curses.ACS_LRCORNER)
+        self.window.addch(lry, ulx, curses.ACS_LLCORNER)
+        
 
 if __name__=='__main__':
     c = Console()
         sz = self._size
         return TRect(
            TPoint(tl.x+radius, tl.y+radius), 
-           TSize(sz.width-1-radius, sz.height-1-radius))
+           TSize(sz.width-1-radius, sz.height-radius))
 
 
 
 
 
 def exit():
+	print e.Text
 	app.quit()
 
 
 app = TApplication()
 app.desktop().show()
 
-win = TWidget(Pos=(4,4), Size=(30,10))
+win = TWidget(Pos=(4,4), Size=(30,10), WindowTitle="Foo bar")
 
 c = TCheckBox(win, Text="Is this working?", Pos=(2,3), Size=(10,10))
 
 win.show()
 
 app.run()
+
         height = rect.size.height
         x2 = x1 + width - 1
         y2 = y1 + height - 1
-        # topleft
-        self.engine.text(x1, y1, "+")
-        # topright
-        self.engine.text(x2, y1, "+")
-        # top line
-        self.engine.text(x1 + 1, y1, "-" * (width-2))
-        # bottomleft
-        self.engine.text(x1, y2, "+")
-        # bottomright
-        self.engine.text(x2, y2, "+")
-        # bottom line
-        self.engine.text(x1+1, y2, "-" * (width-2))
-        # side lines
-        for y in range(y1+1, y2):
-            self.engine.text(x1, y, "|") # left
-            self.engine.text(x2, y, "|") # right
-
+        if 1:
+            self.engine.rectangle(x1, y1, x2, y2)
+        else:
+            self.engine.text(x1, y1, "+")                 # top-left
+            self.engine.text(x2, y1, "+")                 # top-right
+            self.engine.text(x1 + 1, y1, "-" * (width-2)) # top line
+            self.engine.text(x1, y2, "+")                 # bottomleft
+            self.engine.text(x2, y2, "+")                 # bottomright
+            self.engine.text(x1+1, y2, "-" * (width-2))   # bottom line
+            for y in range(y1+1, y2):                     # side lines
+                self.engine.text(x1, y, "|")              #  (left)
+                self.engine.text(x2, y, "|")              #  (right)
+    
 
     
     def drawLine(self, start_pos, end_pos):
             raise NotImplementedError("Only horizontal and vertial lines supported right now")
 
         
+    @dispatch(TPoint, str)
     def drawText(self, pos, text):
-        gpos = self.obj.mapToGlobal(pos)
-        self.engine.text(gpos.x, gpos.y, text)
+        gpos = self.obj.mapToGlobal(TPoint(0,0))
+        self.engine.text(gpos.x + pos.x, gpos.y + pos.y, text)
         
 
+    @dispatch(int, int, str)
+    def drawText(self, x, y, text):
+        self.drawText(TPoint(x, y), text)
 
+
+    @dispatch(TRect, str)
     def fillRect(self, rect, char):
         gpos = self.obj.mapToGlobal(TPoint(0, 0))
         x1 = gpos.x + rect.topLeft.x
         y2 = y1 + height - 1
         for y in range(y1, y2):
             self.engine.text(x1, y, char*width)
-    
 
 
 class TInputContext(TObject):
                 Console.instance.refresh()
             self.input_context.poll()
 
-            
+
+def elide(text, width):
+    if len(text) > width:
+        text = text[:width-3] + "..."
+    return text
+
 
 
 class TWidget(TObject):
         self._visible = True
         self._focus_widget = None
         self._palette = TPalette()
+        self._windowTitle = ""
         super(TWidget, self).__init__(parent, **kwargs)
         if not parent:
             self.activateWindow()
 
+            
+    def windowTitle(self):
+        return self._windowTitle
+
         
-        
+    def setWindowTitle(self, title):
+        self._windowTitle = title or ""
+        if not self.parent():
+            self.update()
+
+
+    WindowTitle = Property(windowTitle, setWindowTitle)
+    
+
     @dispatch(int,int,int,int)
     def setContentsMargins(self, left, top, right, bottom):
         self.setContentsMargins(TMargins(left, top, right, bottom))
             rect = self.geometry()
             painter.drawRect(rect)
             painter.fillRect(rect.inner(), " ")
+            pos = self.pos()
+            painter.drawText(pos.x + self.width() - 4, pos.y, "[*]")
+            painter.drawText(pos.x + 2, pos.y, " %s " % elide(self.windowTitle(), self.width() - 4) )
         for child in self.children():
             if isinstance(child, TWidget) and child.isVisible():
                 child.postEvent(event)
         
     def paintEvent(self, event):
         painter = TPainter(self)
-        painter.fillRect(self.geometry(), ".")
+        painter.fillRect(self.geometry(), " ")
 
 
     
     def paintEvent(self, event):
         painter = TPainter(self)
         text = self.text()[self._cursor_offset:self._cursor_offset+self.width()]
-        display_text = "[%s]" % text.ljust(self.width(), ".")
+        display_text = "[%s]" % text.ljust(self.width(), " ")
         painter.drawText(self.pos(), display_text)
 
         
     def keyPressEvent(self, event):
-        if event.key or event.text:
+        if event.key in (TKey.Key_Tab, TKey.Key_Backtab):
+            pass
+        elif event.key or event.text:
             text = self.text()
             cpos = self.cursorPosition()
             tpos = self._cursor_offset + cpos