Esempio n. 1
0
 def _addCustomPressed():
     btn = _TTkColorButton.lastClicked
     TTkLog.debug(f"{btn}")
     if btn is not None and \
        btn.isCustom():
         TTkLog.debug(f"2 {btn}")
         btn.setColor(sc.color)
Esempio n. 2
0
 def _fps(self):
     curtime = time.time()
     self.frame += 1
     delta = curtime - self.time
     if delta > 5:
         TTkLog.debug(f"fps: {int(self.frame/delta)}")
         self.frame = 0
         self.time = curtime
Esempio n. 3
0
 def _moveToHighlighted(self):
     index = self._items.index(self._highlighted)
     h = self.height()
     offx, offy = self.getViewOffsets()
     if index >= h + offy - 1:
         TTkLog.debug(f"{index} {h} {offy}")
         self.viewMoveTo(offx, index - h + 1)
     elif index <= offy:
         self.viewMoveTo(offx, index)
Esempio n. 4
0
 def searchRe(self, regex, ignoreCase=False):
     indexes = []
     id = 0
     rr = re.compile(regex, re.IGNORECASE if ignoreCase else 0)
     TTkLog.debug(f"Search RE: {regex}")
     with open(self._filename, 'r') as infile:
         for line in infile:
             ma = rr.search(line)
             if ma:
                 indexes.append(id)
             id += 1
     return indexes
Esempio n. 5
0
    def paintCanvas(self, canvas, geom, slice, bound):
        # TTkLog.debug(f"PaintCanvas:{(x,y,w,h)}")
        x, y, w, h = geom
        bx, by, bw, bh = bound
        # out of bound
        if not self._visible: return
        if not canvas._visible: return
        if canvas._width == 0 or canvas._height == 0: return
        if x + w < bx or y + h < by or bx + bw - 1 < x or by + bh - 1 < y:
            return

        x = min(x, self._width - 1)
        y = min(y, self._height - 1)
        w = min(w, self._width - x)
        h = min(h, self._height - y)

        # if x>=self._width:    x=self._width-1
        # if y>=self._height:   y=self._height-1
        # if w>=self._width-x:  w=self._width-x
        # if h>=self._height-y: h=self._height-y

        xoffset = 0 if x >= bx else bx - x
        yoffset = 0 if y >= by else by - y
        wslice = w if x + w < bx + bw else bx + bw - x
        hslice = h if y + h < by + bh else by + bh - y

        for iy in range(yoffset, hslice):
            for ix in range(xoffset, wslice):
                #TTkLog.debug(f"PaintCanvas:{(ix,iy)}")
                if iy > len(canvas._data) - 1:
                    TTkLog.debug(
                        f"{canvas._width, canvas._height} - {(yoffset,hslice)}, {(xoffset,wslice)}, {slice}"
                    )
                b = canvas._data[iy]
                a = b[ix]
                self._data[y + iy][x + ix] = a  # canvas._data[iy][ix]
                self._colors[y + iy][x + ix] = canvas._colors[iy][ix]
Esempio n. 6
0
 def _menuCallback(self, button):
     #self._id = self._list.index(label)
     TTkLog.debug(f"Bind Clicked {button.text}")
     self.menuButtonClicked.emit(button)
     TTkHelper.removeOverlay()
     self.update()
Esempio n. 7
0
 def _controlClicked(self, status, widget, item):
     TTkLog.debug(f"{status} {widget._name}")
     if status:  # we need to expand the TTkFancyTreeWidgetItem
         self._expand(item=item, depth=(widget._depth + 1))
     else:  # we need to shrink the TTkFancyTreeWidgetItem
         self._shrink(item=item)
Esempio n. 8
0
 def mouseDragEvent(self, evt):
     TTkLog.debug(f"{self._name} Test Mouse {evt}")
Esempio n. 9
0
    def mainloop(self):
        '''Enters the main event loop and waits until :meth:`~quit` is called or the main widget is destroyed.'''
        TTkLog.debug("")
        TTkLog.debug("         ████████╗            ████████╗    ")
        TTkLog.debug("         ╚══██╔══╝            ╚══██╔══╝    ")
        TTkLog.debug("            ██║  ▄▄  ▄ ▄▄ ▄▄▖▄▖  ██║ █ ▗▖  ")
        TTkLog.debug("    ▞▀▚ ▖▗  ██║ █▄▄█ █▀▘  █ █ █  ██║ █▟▘   ")
        TTkLog.debug("    ▙▄▞▐▄▟  ██║ ▀▄▄▖ █    █ ▝ █  ██║ █ ▀▄  ")
        TTkLog.debug("    ▌    ▐  ╚═╝                  ╚═╝       ")
        TTkLog.debug("      ▚▄▄▘                                 ")
        TTkLog.debug("")
        TTkLog.debug(f"  Version: {TTkCfg.version}")
        TTkLog.debug("")
        TTkLog.debug("Starting Main Loop...")
        # Register events
        try:
            signal.signal(signal.SIGTSTP, self._SIGSTOP)  # Ctrl-Z
            signal.signal(signal.SIGCONT, self._SIGCONT)  # Resume
            signal.signal(signal.SIGINT, self._SIGINT)  # Ctrl-C
        except Exception as e:
            TTkLog.error(f"{e}")
            exit(1)
        else:
            TTkLog.debug("Signal Event Registered")

        TTkTerm.registerResizeCb(self._win_resize_cb)
        threading.Thread(target=self._input_thread, daemon=True).start()
        self._timer = TTkTimer()
        self._timer.timeout.connect(self._time_event)
        self._timer.start(0.1)
        self.show()

        self.running = True
        # Keep track of the multiTap to avoid the extra key release
        lastMultiTap = False
        TTkTerm.init(title=self._title)
        while self.running:
            # Main Loop
            evt = self.events.get()
            if evt is TTkK.MOUSE_EVENT:
                mevt = self.mouse_events.get()

                # Avoid to broadcast a key release after a multitap event
                if mevt.evt == TTkK.Release and lastMultiTap: continue
                lastMultiTap = mevt.tap > 1

                focusWidget = TTkHelper.getFocus()
                if focusWidget is not None and \
                   mevt.evt != TTkK.Press and \
                   mevt.key != TTkK.Wheel:
                    x, y = TTkHelper.absPos(focusWidget)
                    nmevt = mevt.clone(pos=(mevt.x - x, mevt.y - y))
                    focusWidget.mouseEvent(nmevt)
                else:
                    # Sometimes the release event is not retrieved
                    if focusWidget and focusWidget._pendingMouseRelease:
                        focusWidget.mouseEvent(nmevt.clone(evt=TTkK.Release))
                        focusWidget._pendingMouseRelease = False
                    self.mouseEvent(mevt)
            elif evt is TTkK.KEY_EVENT:
                keyHandled = False
                kevt = self.key_events.get()
                # TTkLog.debug(f"Key: {kevt}")
                focusWidget = TTkHelper.getFocus()
                overlayWidget = TTkHelper.getOverlay()
                TTkLog.debug(f"{focusWidget}")
                if focusWidget is not None:
                    TTkHelper.execShortcut(kevt.key, focusWidget)
                    keyHandled = focusWidget.keyEvent(kevt)
                else:
                    TTkHelper.execShortcut(kevt.key)
                # Handle Next Focus Key Binding
                if not keyHandled and \
                   ((kevt.key == TTkK.Key_Tab and kevt.mod == TTkK.NoModifier) or
                   ( kevt.key == TTkK.Key_Right )):
                    TTkHelper.nextFocus(focusWidget if focusWidget else self)
                # Handle Prev Focus Key Binding
                if not keyHandled and \
                   ((kevt.key == TTkK.Key_Tab and kevt.mod == TTkK.ShiftModifier) or
                   ( kevt.key == TTkK.Key_Left )):
                    TTkHelper.prevFocus(focusWidget if focusWidget else self)
            elif evt is TTkK.TIME_EVENT:
                size = os.get_terminal_size()
                self.setGeometry(0, 0, size.columns, size.lines)
                TTkHelper.paintAll()
                self._timer.start(1 / TTkCfg.maxFps)
                self._fps()
                pass
            elif evt is TTkK.SCREEN_EVENT:
                self.setGeometry(0, 0, TTkGlbl.term_w, TTkGlbl.term_h)
                TTkLog.info(f"Resize: w:{TTkGlbl.term_w}, h:{TTkGlbl.term_h}")
            elif evt is TTkK.QUIT_EVENT:
                TTkLog.debug(f"Quit.")
                break
            else:
                TTkLog.error(f"Unhandled Event {evt}")
                break
        TTkTerm.exit()
Esempio n. 10
0
 def _SIGINT(self, signum, frame):
     TTkLog.debug("Captured SIGINT <CTRL-C>")
     # Deregister the handler
     # so CTRL-C can be redirected to the default handler if the app does not exit
     signal.signal(signal.SIGINT, signal.SIG_DFL)
     self.quit()
Esempio n. 11
0
 def _SIGCONT(self, signum, frame):
     """Set terminal settings and restart background input read"""
     TTkLog.debug("Captured SIGCONT 'fg/bg'")
     TTkTerm.cont()
Esempio n. 12
0
 def _SIGSTOP(self, signum, frame):
     """Reset terminal settings and stop background input read before putting to sleep"""
     TTkLog.debug("Captured SIGSTOP <CTRL-z>")
     TTkTerm.stop()
     # TODO: stop the threads
     os.kill(os.getpid(), signal.SIGSTOP)