Beispiel #1
0
    def mouse_event(self, msg):
        # drag start
        if msg.command == yutani.MouseEvent.DOWN and msg.buttons & yutani.MouseButton.BUTTON_LEFT:
            self.drag_start()

        if msg.buttons & yutani.MouseButton.BUTTON_RIGHT:
            if not self.menus:

                def set_face(x):
                    self.watchface = self.watchfaces[x]

                faces = [
                    MenuEntryAction(x, None, set_face, x)
                    for x in self.watchfaces.keys()
                ]
                menu_entries = [
                    MenuEntrySubmenu("Watchface", faces, icon='clock'),
                    MenuEntryAction(f"About {app_name}", "star", self.about,
                                    None),
                    MenuEntryDivider(),
                    MenuEntryAction("Exit", "exit", self.exit, None),
                ]
                menu = MenuWindow(menu_entries,
                                  (self.x + msg.new_x, self.y + msg.new_y),
                                  root=self)
Beispiel #2
0
    def mouse_action(self, msg):
        if not len(windows):
            return
        msg.new_x -= self.offset
        hovered_index = int(msg.new_x / self.unit_width)
        previously_hovered = self.hovered
        if hovered_index < len(windows):
            self.hovered = windows[hovered_index].wid
            if msg.command == yutani.MouseEvent.CLICK:
                yctx.focus_window(self.hovered)
            elif msg.buttons & yutani.MouseButton.BUTTON_RIGHT:
                if not self.window.menus:

                    def move_window(window):
                        yutani.yutani_lib.yutani_window_drag_start_wid(
                            yutani.yutani_ctx._ptr, window)

                    #def close_window(window):
                    #    print("Should close window",window)
                    menu_entries = [
                        MenuEntryAction("Move", None, move_window,
                                        self.hovered),
                        #MenuEntryAction("Close",None,close_window,self.hovered)
                    ]
                    menu = MenuWindow(menu_entries,
                                      (msg.new_x + self.offset, PANEL_HEIGHT),
                                      root=self.window)
        else:
            self.hovered = None
        return self.hovered != previously_hovered
Beispiel #3
0
 def mouse_action(self, msg):
     if msg.command == yutani.MouseEvent.CLICK:
         def _pass(action):
             pass
         menu_entries = [
             CalendarMenuEntry(),
         ]
         menu = MenuWindow(menu_entries,(self.offset-120,PANEL_HEIGHT),root=self.window)
Beispiel #4
0
 def mouse_action(self, msg):
     if msg.command == yutani.MouseEvent.CLICK:
         def _pass(action):
             pass
         if self.status == 1:
             menu_entries = [
                 MenuEntryAction(f"IP: {self.ip}",None,_pass,None),
                 MenuEntryAction(f"Primary DNS: {self.dns}",None,_pass,None),
                 MenuEntryAction(f"MAC: {self.mac}",None,_pass,None),
                 MenuEntryAction(f"Device: {self.device}",None,_pass,None),
             ]
         else:
             menu_entries = [
                 MenuEntryAction(f"No network.",None,_pass,None),
             ]
         menu = MenuWindow(menu_entries,(self.offset-100,PANEL_HEIGHT),root=self.window)
Beispiel #5
0
    def mouse_check(self, msg):
        if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
            window.close()
            sys.exit(0)
        x, y = msg.new_x - self.decorator.left_width(
        ), msg.new_y - self.decorator.top_height()
        w, h = self.width - self.decorator.width(
        ), self.height - self.decorator.height()
        if x >= 0 and x < w and y >= 0 and y < self.menubar.height:
            self.menubar.mouse_event(msg, x, y)

        if x >= 0 and x < w and y >= self.menubar.height and y < h:
            if msg.buttons & yutani.MouseButton.BUTTON_RIGHT:
                if not self.menus:
                    menu_entries = [
                        MenuEntryAction("Back", "back", self.go_back, None),
                        MenuEntryAction("Forward", "forward", self.go_forward,
                                        None),
                    ]
                    menu = MenuWindow(menu_entries,
                                      (self.x + msg.new_x, self.y + msg.new_y),
                                      root=self)
        if msg.command == yutani.MouseEvent.DOWN:
            e = self.text_under_cursor(msg)
            r = False
            if self.down_text and e != self.down_text:
                for u in self.down_text.tag_group:
                    if u.unit_type == 4:
                        u.set_extra('hilight', False)
                    else:
                        u.set_font(self.down_font[u])
                del self.down_font
                self.down_text = None
                self.update_text_buffer()
                r = True
            if e and 'link' in e.extra and e.tag_group:
                self.down_font = {}
                for u in e.tag_group:
                    if u.unit_type == 4:
                        u.set_extra('hilight', True)
                    else:
                        new_font = toaru_fonts.Font(u.font.font_number,
                                                    u.font.font_size,
                                                    0xFFFF0000)
                        self.down_font[u] = u.font
                        u.set_font(new_font)
                self.update_text_buffer()
                r = True
                self.down_text = e
            else:
                self.down_text = None
            return r
        if msg.command == yutani.MouseEvent.CLICK or msg.command == yutani.MouseEvent.RAISE:
            e = self.text_under_cursor(msg)
            if self.down_text and e == self.down_text:
                self.navigate(e.extra['link'])
                return True
            elif self.down_text:
                for u in self.down_text.tag_group:
                    if u.unit_type == 4:
                        u.set_extra('hilight', False)
                    else:
                        u.set_font(self.down_font[u])
                del self.down_font
                self.down_text = None
                self.update_text_buffer()
                return True
        if msg.buttons & yutani.MouseButton.SCROLL_UP:
            self.scroll(-30)
            return True
        elif msg.buttons & yutani.MouseButton.SCROLL_DOWN:
            self.scroll(30)
            return True
        return False
Beispiel #6
0
 def activate(self):
     menu = MenuWindow(self.menu_entries,(0,PANEL_HEIGHT),root=self.window)
Beispiel #7
0
    def mouse_event(self, msg):
        if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
            window.close()
            sys.exit(0)
        x, y = msg.new_x - self.decorator.left_width(
        ), msg.new_y - self.decorator.top_height()
        w, h = self.width - self.decorator.width(
        ), self.height - self.decorator.height()

        if x >= 0 and x < w and y >= 0 and y < self.menubar.height:
            self.menubar.mouse_event(msg, x, y)
            return

        if msg.buttons & yutani.MouseButton.SCROLL_UP:
            self.scroll(30)
            self.draw()
            return
        elif msg.buttons & yutani.MouseButton.SCROLL_DOWN:
            self.scroll(-30)
            self.draw()
            return

        if x >= 0 and x < w and y >= self.menubar.height and y < h:
            if msg.buttons & yutani.MouseButton.BUTTON_RIGHT:
                if not self.menus:
                    menu_entries = [
                        MenuEntryAction("Up", "up", self.go_up, None),
                    ]
                    menu = MenuWindow(menu_entries,
                                      (self.x + msg.new_x, self.y + msg.new_y),
                                      root=self)
                return

        if y < 0: return

        offset_x = 0
        offset_y = self.scroll_y + self.menubar.height

        redraw = []

        files_per_row = int(w / 100)
        rows_total = math.ceil(len(self.files) / files_per_row)
        skip_files = files_per_row * (int(-offset_y / 100))
        offset_y += int(-offset_y / 100) * 100

        hit = False
        for f in self.files[skip_files:]:
            if offset_y > h: break
            if offset_y > -100:
                if x >= offset_x and x < offset_x + 100 and y >= offset_y and y < offset_y + 100:
                    if not f.hilight:
                        redraw.append(f)
                        if self.hilighted:
                            redraw.append(self.hilighted)
                            self.hilighted.hilight = False
                        f.hilight = True
                    self.hilighted = f
                    hit = True
                    break
            offset_x += 100
            if offset_x + 100 > w:
                offset_x = 0
                offset_y += 100
        if not hit:
            if self.hilighted:
                redraw.append(self.hilighted)
                self.hilighted.hilight = False
                self.hilighted = None

        if self.hilighted:
            if msg.command == yutani.MouseEvent.DOWN:
                self.hilighted.do_action()

        if redraw:
            self.redraw_buf(redraw)
            self.draw()