Пример #1
0
 def invalt(self, x, y, w, h):
     ''' Mark a region for refresh '''
     rectangle = Gdk.Rectangle()
     rectangle.x = x
     rectangle.y = y
     rectangle.width = w
     rectangle.height = h
     self._canvas.window.invalidate_rect(rectangle)
Пример #2
0
 def set_popovers_position(self, x, y):
     rectangle = Gdk.Rectangle()
     rectangle.x = int(x)
     rectangle.y = int(y)
     rectangle.height = 1
     rectangle.width = 1
     self.menu_if_inactive.set_pointing_to(rectangle)
     self.menu_if_active.set_pointing_to(rectangle)
Пример #3
0
    def _on_send_key_button_clicked_cb(self, src):
        event = Gtk.get_current_event()
        win = self._toolbar.get_window()
        rect = Gdk.Rectangle()

        rect.y = win.get_height()
        self._keycombo_menu.popup_at_rect(win, rect, Gdk.Gravity.NORTH_WEST,
                                          Gdk.Gravity.NORTH_WEST, event)
Пример #4
0
 def do_redraw_canvas():
     if self.get_window():
         allocation = self.get_allocation()
         rect = Gdk.Rectangle()
         rect.x, rect.y, rect.width, rect.height = (0, 0, allocation.width,
                                                    allocation.height)
         self.get_window().invalidate_rect(rect, True)
         self.get_window().process_updates(True)
Пример #5
0
 def set_r_popover_position(self, x, y):
     rectangle = Gdk.Rectangle()
     rectangle.x = int(x)
     rectangle.y = int(y)
     rectangle.height = 1
     rectangle.width = 1
     self.r_popover.set_relative_to(self.image)
     self.r_popover.set_pointing_to(rectangle)
Пример #6
0
def make_rect(x, y, width, height):
    rect = Gdk.Rectangle()
    rect.x = x
    rect.y = y
    rect.width = width
    rect.height = height

    return rect
Пример #7
0
 def __init__(self, view):
     super().__init__(view)
     self.text = None  # None while x, y has not been assigned any value
     self.current = 0  # cursor position in text
     self.font = view.get_font()
     self.preedit = ('', None, 0)
     self.caret = Gdk.Rectangle()
     self.ink = [0, 0]
Пример #8
0
    def checkGetLayerAt(self, heights, preferred, past_middle_when_adjacent, expectations):
        timeline_container = create_timeline_container()
        timeline = timeline_container.timeline

        # Allocate layers
        y = 0
        for priority, height in enumerate(heights):
            ges_layer = timeline.create_layer(priority=priority)
            rect = Gdk.Rectangle()
            rect.y = y
            rect.height = height
            ges_layer.ui.set_allocation(rect)
            y += height + SEPARATOR_HEIGHT

        ges_layers = timeline.ges_timeline.get_layers()
        if preferred is None:
            preferred_ges_layer = None
        else:
            preferred_ges_layer = ges_layers[preferred]
        # The heights of the layers.
        h = [ges_layer.ui.get_allocation().height for ges_layer in ges_layers]
        s = SEPARATOR_HEIGHT

        def assertLayerAt(ges_layer, y):
            result = timeline._get_layer_at(
                int(y),
                prefer_ges_layer=preferred_ges_layer,
                past_middle_when_adjacent=past_middle_when_adjacent)
            self.assertEqual(
                ges_layer,
                result[0],
                "Expected %d, got %d at %d" % (ges_layers.index(ges_layer), ges_layers.index(result[0]), y))

        # y on the top layer.
        assertLayerAt(ges_layers[expectations[0]], 0)
        assertLayerAt(ges_layers[expectations[1]], h[0] / 2 - 1)
        assertLayerAt(ges_layers[expectations[2]], h[0] / 2)
        assertLayerAt(ges_layers[expectations[3]], h[0] - 1)

        # y on the separator.
        assertLayerAt(ges_layers[expectations[4]], h[0])
        assertLayerAt(ges_layers[expectations[5]], h[0] + s - 1)

        # y on the middle layer.
        assertLayerAt(ges_layers[expectations[6]], h[0] + s)
        assertLayerAt(ges_layers[expectations[7]], h[0] + s + h[1] / 2 - 1)
        assertLayerAt(ges_layers[expectations[8]], h[0] + s + h[1] / 2)
        assertLayerAt(ges_layers[expectations[9]], h[0] + s + h[1] - 1)

        # y on the separator.
        assertLayerAt(ges_layers[expectations[10]], h[0] + s + h[1])
        assertLayerAt(ges_layers[expectations[11]], h[0] + s + h[1] + s - 1)

        # y on the bottom layer.
        assertLayerAt(ges_layers[expectations[12]], h[0] + s + h[1] + s)
        assertLayerAt(ges_layers[expectations[13]], h[0] + s + h[1] + s + h[2] / 2 - 1)
        assertLayerAt(ges_layers[expectations[14]], h[0] + s + h[1] + s + h[2] / 2)
        assertLayerAt(ges_layers[expectations[15]], h[0] + s + h[1] + s + h[2] - 1)
Пример #9
0
 def _update_run(self):
     # This method runs in the background _update_thread
     while True:
         # Only update the screen if do_draw's finished the last update;
         # this effectively serves to "drop frames" if the system's too
         # busy
         if self._draw_pending.wait(self.screen_update_delay):
             # The wait period above enforces the maximum update rate; if
             # a draw is still pending, wait on the stop event instead
             if self._stop.wait(self.screen_update_delay):
                 break
         else:
             # Only update if the screen's modification timestamp indicates
             # that the data has changed since last time
             ts = self._screen_client.timestamp
             if ts > self._draw_timestamp:
                 with self._size_lock:
                     img = self._board_scaled.copy()
                     pixels = GdkPixbuf.Pixbuf.new_from_bytes(
                         GLib.Bytes.new(self._screen_client.rgb_array.tostring()),
                         colorspace=GdkPixbuf.Colorspace.RGB, has_alpha=False,
                         bits_per_sample=8, width=8, height=8, rowstride=8 * 3)
                     pixel_rect = Gdk.Rectangle()
                     pixel_rect.x = int(126 * self._ratio)
                     pixel_rect.y = int(155 * self._ratio)
                     pixel_rect.width = int(512 * self._ratio)
                     pixel_rect.height = pixel_rect.width
                     pixels.composite(
                         img,
                         pixel_rect.x, pixel_rect.y,
                         pixel_rect.width, pixel_rect.height,
                         pixel_rect.x, pixel_rect.y,
                         # Why 8.1? With 8.0 (which is what it should be),
                         # registration errors crop up at the far right (try
                         # it and see); no idea why 8.1 is required to
                         # correct them, but I'm too knackered to argue with
                         # Gdk any more...
                         pixel_rect.width / 8.1, pixel_rect.height / 8.1,
                         GdkPixbuf.InterpType.NEAREST, 255)
                     self._grid_scaled.composite(
                         img,
                         pixel_rect.x, pixel_rect.y,
                         pixel_rect.width, pixel_rect.height,
                         pixel_rect.x, pixel_rect.y,
                         1, 1,
                         GdkPixbuf.InterpType.NEAREST, 255)
                 self._draw_image = img
                 self._draw_timestamp = ts
                 self._draw_pending.set()
                 # Schedule a redraw when the app is next idle; like Gtk
                 # methods, Gdk methods must only be called from the main
                 # thread (otherwise the app locks up)
                 try:
                     GLib.idle_add(self.props.window.invalidate_rect, None, False)
                 except AttributeError:
                     # Our Gdk window has been destroyed; don't whinge, just
                     # exit the thread as we're obviously shutting down
                     break
Пример #10
0
    def draw(self, context):
        """
        Draw the widget. This method is called automatically. Don't call it
        yourself. If you want to force a redrawing of the widget, call
        the queue_draw() method.
        
        @type context: cairo.Context
        @param context: The context to draw on.
        """
        label.begin_drawing()

        rect = self.get_allocation()
        rect = Gdk.Rectangle(
            0, 0, rect.width,
            rect.height)  #transform rect to context coordinates
        context.set_line_width(1)

        rect = self.draw_basics(context, rect)
        maximum_value = max(bar.get_value() for bar in self._bars)
        #find out the size of the value labels
        value_label_size = 0
        if self._draw_labels:
            for bar in self._bars:
                value_label_size = max(
                    value_label_size,
                    bar.get_value_label_size(context, rect, self._mode,
                                             len(self._bars),
                                             self._bar_padding))
            value_label_size += 3

        #find out the size of the labels:
        label_size = 0
        if self._draw_labels:
            for bar in self._bars:
                label_size = max(
                    label_size,
                    bar.get_label_size(context, rect, self._mode,
                                       len(self._bars), self._bar_padding))
            label_size += 3

        rect = self._do_draw_grid(context, rect, maximum_value,
                                  value_label_size, label_size)
        self._do_draw_bars(context, rect, maximum_value, value_label_size,
                           label_size)

        label.finish_drawing()

        if self._mode == MODE_VERTICAL:
            n = len(self._bars)
            minimum_width = rect.x + self._padding + (
                n - 1) * self._bar_padding + n * 10
            minimum_height = 100 + self._padding + rect.y
        elif self._mode == MODE_HORIZONTAL:
            n = len(self._bars)
            minimum_width = rect.x + self._bar_padding + 100
            minimum_height = rect.y + self._padding + (
                n - 1) * self._bar_padding + n * 10
        self.set_size_request(minimum_width, minimum_height)
Пример #11
0
 def on_size_allocate(self, widget, requisition):
     if self.get_window():
         a = self.get_allocation()
         rect = Gdk.Rectangle()
         rect.x, rect.y, rect.width, rect.height = (a.x, a.y, a.width, a.height)
         unionrect = union(self.lastRectangle, rect) if self.lastRectangle != None else rect
         self.get_window().invalidate_rect(unionrect, True)
         self.get_window().process_updates(True)
         self.lastRectangle = rect
Пример #12
0
 def get_allocation(self):
     """
     Returns an allocation rectangle.
     
     @return: Gdk.Rectangle.
     """
     x, y = self._real_position
     w, h = self._real_dimensions
     return Gdk.Rectangle(int(x), int(y), int(w), int(h))
Пример #13
0
 def __grid_child_changed_cb(self, grid, child):
     request = child.size_request()
     rect = self._grid.get_child_rect(child)
     child_allocation = Gdk.Rectangle()
     child_allocation.x = int(round(rect.x * _CELL_SIZE))
     child_allocation.y = int(round(rect.y * _CELL_SIZE))
     child_allocation.width = request.width
     child_allocation.height = request.height
     child.size_allocate(child_allocation)
Пример #14
0
    def _scroll_size_allocate(self, src_ignore, req):
        if not self._viewer:
            return
        if not self._viewer.console_get_desktop_resolution():
            return

        scroll = self.widget("console-gfx-scroll")
        is_scale = self._viewer.console_get_scaling()
        is_resizeguest = self._viewer.console_get_resizeguest()

        dx = 0
        dy = 0
        align_ratio = float(req.width) / float(req.height)

        # pylint: disable=unpacking-non-sequence
        desktop_w, desktop_h = self._viewer.console_get_desktop_resolution()
        desktop_ratio = float(desktop_w) / float(desktop_h)

        if is_scale:
            # Make sure we never show scrollbars when scaling
            scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
        else:
            scroll.set_policy(Gtk.PolicyType.AUTOMATIC,
                              Gtk.PolicyType.AUTOMATIC)

        if is_resizeguest:
            # With resize guest, we don't want to maintain aspect ratio,
            # since the guest can resize to arbitrary resolutions.
            self._viewer.console_set_size_request(req.width, req.height)
            return

        if not is_scale:
            # Scaling disabled is easy, just force the VNC widget size. Since
            # we are inside a scrollwindow, it shouldn't cause issues.
            self._viewer.console_set_size_request(desktop_w, desktop_h)
            return

        # Make sure there is no hard size requirement so we can scale down
        self._viewer.console_set_size_request(-1, -1)

        # Make sure desktop aspect ratio is maintained
        if align_ratio > desktop_ratio:
            desktop_w = int(req.height * desktop_ratio)
            desktop_h = req.height
            dx = (req.width - desktop_w) / 2

        else:
            desktop_w = req.width
            desktop_h = int(req.width / desktop_ratio)
            dy = (req.height - desktop_h) / 2

        viewer_alloc = Gdk.Rectangle()
        viewer_alloc.x = dx
        viewer_alloc.y = dy
        viewer_alloc.width = desktop_w
        viewer_alloc.height = desktop_h
        self._viewer.console_size_allocate(viewer_alloc)
Пример #15
0
    def __on_scroll(self, adj):
        """
            Show a popover with current letter
            @param adj as Gtk.Adjustement
        """
        if self.__fast_scroll:
            top_path = self.__view.get_dest_row_at_pos(0, 0)
            if top_path is not None:
                row = top_path[0]
                if row is not None:
                    row_iter = self.__model.get_iter(row)
                    rowid = self.__model.get_value(row_iter, 0)
                    if rowid < 0:
                        self.__button.hide()
                    else:
                        self.__button.show()
        # Only show if self.__scrolled window is huge
        if adj.get_upper() < adj.get_page_size() * 3:
            return
        if self.__last_motion_event is None:
            return

        if self.__timeout is not None:
            GLib.source_remove(self.__timeout)
            self.__timeout = None

        path = self.__view.get_dest_row_at_pos(self.__last_motion_event.x,
                                               self.__last_motion_event.y)
        if path is None:
            return

        row = path[0]

        if row is None:
            return

        row_iter = self.__model.get_iter(row)
        if row_iter is None or self.__model.get_value(row_iter, 0) < 0:
            return

        # We need to get artist sortname
        if self.__is_artists:
            rowid = self.__model.get_value(row_iter, 0)
            text = Lp().artists.get_sortname(rowid)
        else:
            text = self.__model.get_value(row_iter, 1)
        if text:
            self.__popover.set_text("  %s  " % text[0].upper())
            self.__popover.set_relative_to(self)
            r = Gdk.Rectangle()
            r.x = self.get_allocated_width()
            r.y = self.__last_motion_event.y
            r.width = 1
            r.height = 1
            self.__popover.set_pointing_to(r)
            self.__popover.set_position(Gtk.PositionType.RIGHT)
            self.__popover.show()
 def redraw_canvas(self, prect=None):
     if self.get_window():
         if not prect:
             alloc = self.get_allocation()
             prect = (0, 0, alloc.width, alloc.height)
         rect = Gdk.Rectangle()
         rect.x, rect.y, rect.width, rect.height = prect
         self.get_window().invalidate_rect(rect, True)
         self.get_window().process_updates(True)
Пример #17
0
	def set_popover_position(self):
		rectangle = Gdk.Rectangle()
		main_x, main_y = self.get_image().get_main_coord()
		x = self.get_image().selection_x + self.get_selection_pixbuf().get_width()/2 - main_x
		y = self.get_image().selection_y + self.get_selection_pixbuf().get_height()/2 - main_y
		[rectangle.x, rectangle.y] = [x, y]
		rectangle.height = 1
		rectangle.width = 1
		self.selection_popover.set_pointing_to(rectangle)
Пример #18
0
def _get_screen_area():
    frame_thickness = style.GRID_CELL_SIZE

    screen_area = Gdk.Rectangle()
    screen_area.x = screen_area.y = frame_thickness
    screen_area.width = Gdk.Screen.width() - frame_thickness
    screen_area.height = Gdk.Screen.height() - frame_thickness

    return screen_area
Пример #19
0
    def click_derecho_panel_izquierdo(self, widget, event):

        if event.button == 3:
            rect = Gdk.Rectangle()
            rect.x = event.x
            rect.y = event.y+70
            rect.width = rect.height = 1
            self.menu_panel_izquierdo.set_pointing_to(rect)
            self.menu_panel_izquierdo.show_all()
Пример #20
0
    def _invalidate_client_rect(self, x, y, width, height):
        if self.get_window():
            rect = Gdk.Rectangle()
            rect.x, rect.y, rect.width, rect.height = (
                int(math.floor(x)) + self._preview_rect.x,
                int(math.floor(y)) + self._preview_rect.y,
                int(math.ceil(width)) + 1, int(math.ceil(height)) + 1)

            self.get_window().invalidate_rect(rect, True)
Пример #21
0
 def do_dock_tray(self, xid):
     root = get_default_root_window()
     window = GdkX11.X11Window.foreign_new_for_display(
         root.get_display(), xid)
     if window is None:
         log.warn("could not find gdk window for tray window %#x", xid)
         return
     log("dock_tray: root=%s, window=%s", root, window)
     w, h = window.get_geometry()[2:4]
     log("dock_tray: geometry=%s", (w, h))
     if w == 0 and h == 0:
         log("dock_tray: invalid tray geometry, ignoring this request")
         return
     em = Gdk.EventMask
     event_mask = em.STRUCTURE_MASK | em.EXPOSURE_MASK | em.PROPERTY_CHANGE_MASK
     window.set_events(event_mask=event_mask)
     add_event_receiver(window, self)
     w = max(1, min(MAX_TRAY_SIZE, w))
     h = max(1, min(MAX_TRAY_SIZE, h))
     title = prop_get(window, "_NET_WM_NAME", "utf8", ignore_errors=True)
     if title is None:
         title = prop_get(window, "WM_NAME", "latin1", ignore_errors=True)
     if title is None:
         title = ""
     xid = root.get_xid()
     log("dock_tray(%#x) gdk window=%#x, geometry=%s, title=%s", xid, xid,
         window.get_geometry(), title)
     visual = window.get_visual()
     tray_window = GDKX11Window(root,
                                width=w,
                                height=h,
                                event_mask=event_mask,
                                title=title,
                                x=-200,
                                y=-200,
                                override_redirect=True,
                                visual=visual)
     log("dock_tray(%#x) setting tray properties", xid)
     set_tray_window(tray_window, window)
     tray_window.show()
     self.tray_windows[window] = tray_window
     self.window_trays[tray_window] = window
     log("dock_tray(%#x) resizing and reparenting", xid)
     window.resize(w, h)
     xwin = window.get_xid()
     xtray = tray_window.get_xid()
     X11Window.Withdraw(xwin)
     X11Window.Reparent(xwin, xtray, 0, 0)
     X11Window.MapRaised(xwin)
     log("dock_tray(%#x) new tray container window %#x", xid, xtray)
     rect = Gdk.Rectangle()
     rect.width = w
     rect.height = h
     tray_window.invalidate_rect(rect, True)
     X11Window.send_xembed_message(xwin, XEMBED_EMBEDDED_NOTIFY, 0, xtray,
                                   XEMBED_VERSION)
Пример #22
0
    def __getButtonAtPoint (self, x, y):
        for position in range(POSITIONS_COUNT):

            rect = Gdk.Rectangle()
            rect.x, rect.y, rect.width, rect.height = (x, y, 1, 1)

            inside, dest = Gdk.rectangle_intersect(self.__getButtonRectangle(position), rect)
            if inside:
                return position
        return -1
Пример #23
0
 def tag_editing_started(self, renderer_combo, combobox, path):
     event = Gtk.get_current_event()
     rect = Gdk.Rectangle()
     rect.x = event.x
     rect.y = event.y + 30
     rect.width = rect.height = 1
     combobox.hide()
     popover = self.builder.get_object('tag_popover')
     popover.set_pointing_to(rect)
     GLib.idle_add(popover.show)
 def on_drawingareaExample_draw(self, widget, cr, *args):
     """ Handler for drawingareaExample.draw. """
     sizes = self.eventboxForDrawingSample.get_allocation()
     min_size = min(sizes.width, sizes.height)
     self.working_restangle = Gdk.Rectangle()
     self.working_restangle.x = int((sizes.width - min_size) / 2)
     self.working_restangle.y = int((sizes.height - min_size) / 2)
     self.working_restangle.width = int(min_size)
     self.working_restangle.height = int(min_size)
     self.draw_example(cr)
Пример #25
0
    def do_draw(self, contexto):
        """
        Dibuja el estado de la barra de progreso.
        """

        rect = self.get_allocation()
        w, h = (rect.width, rect.height)

        # Relleno de la barra
        ww = w - self.borde * 2
        hh = 10  #h - self.borde * 2
        Gdk.cairo_set_source_color(contexto, get_color("NEGRO"))
        rect = Gdk.Rectangle()
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde, ww,
                                                   hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # Relleno de la barra segun progreso
        Gdk.cairo_set_source_color(contexto, get_color("NARANJA"))
        rect = Gdk.Rectangle()
        ximage = int(self.get_adjustment().get_value() * ww / 100)
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde,
                                                   ximage, hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.fill()

        # borde del progreso
        Gdk.cairo_set_source_color(contexto, get_color("BLANCO"))
        rect = Gdk.Rectangle()
        rect.x, rect.y, rect.width, rect.height = (self.borde, self.borde, ww,
                                                   hh)
        Gdk.cairo_rectangle(contexto, rect)
        contexto.stroke()

        # La Imagen
        imgw, imgh = (self.pixbuf.get_width(), self.pixbuf.get_height())
        imgx = ximage
        imgy = float(self.borde + hh / 2 - imgh / 2)
        Gdk.cairo_set_source_pixbuf(contexto, self.pixbuf, imgx, imgy)
        contexto.paint()

        return True
Пример #26
0
 def expose(self, widget, ctx):
     context = widget.get_window().cairo_create()
     clip_ext = context.clip_extents()
     rec = Gdk.Rectangle()
     rec.x, rec.y, rec.width, rec.height = clip_ext[0], clip_ext[1], \
         clip_ext[2] - clip_ext[0], clip_ext[3] - clip_ext[1]
     context.rectangle(rec.x, rec.y, rec.width, rec.height)
     context.clip()
     self.draw(context)
     return False
Пример #27
0
 def expose(self, widget, ctx):        
     context = widget.get_window().cairo_create()
     ce = context.clip_extents()
     a = Gdk.Rectangle()
     a.x, a.y, a.width, a.height = ce[0], ce[1], ce[2]-ce[0], ce[3]-ce[1]
     context.rectangle(a.x, a.y,
                       a.width, a.height)       
     context.clip()
     self.draw(context)
     return False
Пример #28
0
    def _get_under_window_geometry(self):
        geo = Gdk.Rectangle()
        actual_min = self._get_actual_min()

        geo.x = 0
        geo.y = actual_min
        geo.width = self.get_allocation().width
        geo.height = (self.get_allocation().height - actual_min)

        return geo
Пример #29
0
 def _track_gesture_for_area(self, directions, x, y, width, height):
     rectangle = Gdk.Rectangle()
     rectangle.x = x
     rectangle.y = y
     rectangle.width = width
     rectangle.height = height
     swipe = SugarGestures.SwipeController(directions=directions)
     swipe.connect('swipe-ended', self.__swipe_ended_cb)
     self._gesture_grabber.add(swipe, rectangle)
     self._controller.append(swipe)
Пример #30
0
    def set_popovers_position(self, x, y):
        """Set the coords where the popover should be opened. These coords are
		relative TO THE WIDGET, not to the pixbuf."""
        rectangle = Gdk.Rectangle()
        rectangle.x = int(x)
        rectangle.y = int(y)
        rectangle.height = 1
        rectangle.width = 1
        self.menu_if_inactive.set_pointing_to(rectangle)
        self.menu_if_active.set_pointing_to(rectangle)