示例#1
0
    def cb_draw_button_press_event(self, widget, event):
        (scr, x, y) = self.pntr_device.get_position()
        cur = scr.get_monitor_at_point(x, y)

        # Save them temporarily here as we need both the new and old values
        startx = int(event.x)
        starty = int(event.y)
        g_startx = HW.screens[cur]['x'] + startx
        g_starty = HW.screens[cur]['y'] + starty

        for i in range(0, 9):
            # X and Y offsets, added to start position
            x = i % 3 / 2
            y = math.floor(i / 3) / 2
            offsetx = self.width * x
            offsety = self.height * y

            if in_circle(self.g_startx + offsetx, self.g_starty + offsety, 8,
                         g_startx, g_starty):
                self.resize_handle = i
                return True

        # Move selection
        if min(self.startx, self.endx) < startx < max(self.startx, self.endx) and \
           min(self.starty, self.endy) < starty < max(self.starty, self.endy):

            # Check if user double clicked somewhere in the selected area and accept it if they did
            if event.type == Gdk.EventType._2BUTTON_PRESS:
                self.accept_area()
                self.emit("area-selected")

            self.resize_handle = HANDLE_MOVE
            return True

        # Start new selection if no handle is selected
        self.startx = startx
        self.starty = starty
        self.g_startx = g_startx
        self.g_starty = g_starty
        self.endx = 0
        self.endy = 0
        self.g_endx = 0
        self.g_endy = 0
        self.width = 0
        self.height = 0
    def cb_draw_button_press_event(self, widget, event):
        (scr, x, y) = self.pntr_device.get_position()
        cur = scr.get_monitor_at_point(x, y)

        # Save them temporarily here as we need both the new and old values
        startx = int(event.x)
        starty = int(event.y)
        g_startx = HW.screens[cur]['x'] + startx
        g_starty = HW.screens[cur]['y'] + starty

        for i in range(0, 9):
            # X and Y offsets, added to start position
            x = i % 3 / 2
            y = math.floor(i / 3) / 2
            offsetx = self.width * x
            offsety = self.height * y

            if in_circle(self.g_startx + offsetx, self.g_starty + offsety, 8, g_startx, g_starty):
                self.resize_handle = i
                return True

        # Move selection
        if min(self.startx, self.endx) < startx < max(self.startx, self.endx) and \
           min(self.starty, self.endy) < starty < max(self.starty, self.endy):

            # Check if user double clicked somewhere in the selected area and accept it if they did
            if event.type == Gdk.EventType._2BUTTON_PRESS:
                self.accept_area()
                self.emit("area-selected")

            self.resize_handle = HANDLE_MOVE
            return True

        # Start new selection if no handle is selected
        self.startx = startx
        self.starty = starty
        self.g_startx = g_startx
        self.g_starty = g_starty
        self.endx = 0
        self.endy = 0
        self.g_endx = 0
        self.g_endy = 0
        self.width  = 0
        self.height = 0
示例#3
0
    def cb_draw_motion_notify_event(self, widget, event):
        (state, x, y,
         mask) = event.window.get_device_position(self.pntr_device)

        (scr, x, y) = self.pntr_device.get_position()
        cur = scr.get_monitor_at_point(x, y)
        ex = int(event.x)
        ey = int(event.y)
        sx = HW.screens[cur]['x']
        sy = HW.screens[cur]['y']

        # Set arrow cursors
        cursor_changed = False
        for i in range(0, 9):
            # X and Y offsets, added to start position
            x = i % 3 / 2
            y = math.floor(i / 3) / 2
            offsetx = self.width * x
            offsety = self.height * y

            # Invert cursors if area is selected from the bottom up
            if self.g_startx > self.g_endx:
                offsetx *= -1
            if self.g_starty > self.g_endy:
                offsety *= -1

            # Show arrow cursors when hovering over any of the handles
            if in_circle(
                    min(self.g_startx, self.g_endx) + offsetx,
                    min(self.g_starty, self.g_endy) + offsety, 8, sx + ex,
                    sy + ey):
                cursor_changed = True
                self.gdk_win.set_cursor(Gdk.Cursor(HANDLE_CURSORS[i]))
                break
            self.gdk_win.set_cursor(Gdk.Cursor(Gdk.CursorType.CROSSHAIR))

        # Set hand cursor
        if not cursor_changed and \
           min(self.startx, self.endx) < ex < max(self.startx, self.endx) and \
           min(self.starty, self.endy) < ey < max(self.starty, self.endy):
            self.gdk_win.set_cursor(Gdk.Cursor(HANDLE_CURSORS[HANDLE_MOVE]))

        if mask & Gdk.ModifierType.BUTTON1_MASK:
            # Top left
            if self.resize_handle == HANDLE_TL:
                self.startx = ex
                self.starty = ey
                self.g_startx = sx + ex
                self.g_starty = sy + ey

            # Top center
            elif self.resize_handle == HANDLE_TC:
                self.starty = ey
                self.g_starty = sy + ey

            # Top right
            elif self.resize_handle == HANDLE_TR:
                self.endx = ex
                self.starty = ey
                self.g_endx = sx + ex
                self.g_starty = sy + ey

            # Center left
            elif self.resize_handle == HANDLE_CL:
                self.startx = ex
                self.g_startx = sx + ex

            # Center right
            elif self.resize_handle == HANDLE_CR:
                self.endx = ex
                self.g_endx = sx + ex

            # Bottom left
            elif self.resize_handle == HANDLE_BL:
                self.startx = ex
                self.endy = ey
                self.g_startx = sx + ex
                self.g_endy = sy + ey

            # Bottom center
            elif self.resize_handle == HANDLE_BC:
                self.endy = ey
                self.g_endy = sy + ey

            # Bottom right
            elif self.resize_handle == HANDLE_BR:
                self.endx = ex
                self.endy = ey
                self.g_endx = sx + ex
                self.g_endy = sy + ey

            # Make selection movable
            elif self.resize_handle == HANDLE_MOVE:
                # The position where the movement was initiated
                if self.move_offsetx == self.move_offsety == 0:
                    self.move_offsetx = ex - self.startx
                    self.move_offsety = ey - self.starty

                # Update area position with respect to the initial offset
                self.startx = max(0, ex - self.move_offsetx)
                self.starty = max(0, ey - self.move_offsety)
                self.endx = self.startx + self.width
                self.endy = self.starty + self.height

                sw = HW.screens[cur]['width']
                sh = HW.screens[cur]['height']
                if self.endx > sw:
                    self.startx -= self.endx - sw
                    self.endx = sw
                if self.endy > sh:
                    self.starty -= self.endy - sh
                    self.endy = sh

                self.g_startx = sx + self.startx
                self.g_starty = sy + self.starty
                self.g_endx = sx + self.endx
                self.g_endy = sy + self.endy

            # New selection
            else:
                self.endx = ex
                self.endy = ey
                self.g_endx = sx + ex
                self.g_endy = sy + ey

            # Width and height should always be updated
            self.width = self.endx - self.startx
            self.height = self.endy - self.starty

        widget.queue_draw()
        return True
    def cb_draw_motion_notify_event(self, widget, event):
        (state, x, y, mask) = event.window.get_device_position(self.pntr_device)

        (scr, x, y) = self.pntr_device.get_position()
        cur = scr.get_monitor_at_point(x, y)
        ex = int(event.x)
        ey = int(event.y)
        sx = HW.screens[cur]['x']
        sy = HW.screens[cur]['y']

        # Set arrow cursors
        cursor_changed = False
        for i in range(0, 9):
            # X and Y offsets, added to start position
            x = i % 3 / 2
            y = math.floor(i / 3) / 2
            offsetx = self.width * x
            offsety = self.height * y

            # Invert cursors if area is selected from the bottom up
            if self.g_startx > self.g_endx:
                offsetx *= -1
            if self.g_starty > self.g_endy:
                offsety *= -1

            # Show arrow cursors when hovering over any of the handles
            if in_circle(min(self.g_startx, self.g_endx) + offsetx, min(self.g_starty, self.g_endy) + offsety, 8, sx + ex, sy + ey):
                cursor_changed = True
                self.gdk_win.set_cursor(Gdk.Cursor(HANDLE_CURSORS[i]))
                break
            self.gdk_win.set_cursor(Gdk.Cursor(Gdk.CursorType.CROSSHAIR))

        # Set hand cursor
        if not cursor_changed and \
           min(self.startx, self.endx) < ex < max(self.startx, self.endx) and \
           min(self.starty, self.endy) < ey < max(self.starty, self.endy):
            self.gdk_win.set_cursor(Gdk.Cursor(HANDLE_CURSORS[HANDLE_MOVE]))

        if mask & Gdk.ModifierType.BUTTON1_MASK:
            # Top left
            if self.resize_handle == HANDLE_TL:
                self.startx = ex
                self.starty = ey
                self.g_startx = sx + ex
                self.g_starty = sy + ey

            # Top center
            elif self.resize_handle == HANDLE_TC:
                self.starty = ey
                self.g_starty = sy + ey

            # Top right
            elif self.resize_handle == HANDLE_TR:
                self.endx = ex
                self.starty = ey
                self.g_endx = sx + ex
                self.g_starty = sy + ey

            # Center left
            elif self.resize_handle == HANDLE_CL:
                self.startx = ex
                self.g_startx = sx + ex

            # Center right
            elif self.resize_handle == HANDLE_CR:
                self.endx = ex
                self.g_endx = sx + ex

            # Bottom left
            elif self.resize_handle == HANDLE_BL:
                self.startx = ex
                self.endy = ey
                self.g_startx = sx + ex
                self.g_endy = sy + ey

            # Bottom center
            elif self.resize_handle == HANDLE_BC:
                self.endy = ey
                self.g_endy = sy + ey

            # Bottom right
            elif self.resize_handle == HANDLE_BR:
                self.endx = ex
                self.endy = ey
                self.g_endx = sx + ex
                self.g_endy = sy + ey

            # Make selection movable
            elif self.resize_handle == HANDLE_MOVE:
                # The position where the movement was initiated
                if self.move_offsetx == self.move_offsety == 0:
                    self.move_offsetx = ex - self.startx
                    self.move_offsety = ey - self.starty

                # Update area position with respect to the initial offset
                self.startx = max(0, ex - self.move_offsetx)
                self.starty = max(0, ey - self.move_offsety)
                self.endx = self.startx + self.width
                self.endy = self.starty + self.height

                sw = HW.screens[cur]['width']
                sh = HW.screens[cur]['height']
                if self.endx > sw:
                    self.startx -= self.endx - sw
                    self.endx = sw
                if self.endy > sh:
                    self.starty -= self.endy - sh
                    self.endy = sh

                self.g_startx = sx + self.startx
                self.g_starty = sy + self.starty
                self.g_endx = sx + self.endx
                self.g_endy = sy + self.endy

            # New selection
            else:
                self.endx = ex
                self.endy = ey
                self.g_endx = sx + ex
                self.g_endy = sy + ey

            # Width and height should always be updated
            self.width  = self.endx - self.startx
            self.height = self.endy - self.starty

        widget.queue_draw()
        return True