Python gi.repository.Gdk 模块,Rectangle() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用gi.repository.Gdk.Rectangle()

项目:python-gui    作者:neovim    | 项目源码 | 文件源码
def _gtk_draw(self, wid, cr):
        if not self._screen:
            return
        # from random import random
        # cr.rectangle(0, 0, self._pixel_width, self._pixel_height)
        # cr.set_source_rgb(random(), random(), random())
        # cr.fill()
        self._cairo_surface.flush()
        cr.save()
        cr.rectangle(0, 0, self._pixel_width, self._pixel_height)
        cr.clip()
        cr.set_source_surface(self._cairo_surface, 0, 0)
        cr.paint()
        cr.restore()
        if not self._busy and self._blink:
            # Cursor is drawn separately in the window. This approach is
            # simpler because it doesn't taint the internal cairo surface,
            # which is used for scrolling
            row, col = self._screen.row, self._screen.col
            text, attrs = self._screen.get_cursor()
            self._pango_draw(row, col, [(text, attrs,)], cr=cr, cursor=True)
            x, y = self._get_coords(row, col)
            currect = Rectangle(x, y, self._cell_pixel_width,
                                self._cell_pixel_height)
            self._im_context.set_cursor_location(currect)
项目:python-gui    作者:neovim    | 项目源码 | 文件源码
def Rectangle(x, y, w, h):
    r = Gdk.Rectangle()
    r.x, r.y, r.width, r.height = x, y, w, h
    return r
项目:ibus-typing-booster    作者:mike-fabian    | 项目源码 | 文件源码
def _emoji_event_box_selected(self, event_box):
        '''
        Called when an event box containing an emoji
        was selected in the flowbox.

        The emoji is then copied to the clipboard and a popover
        pops up for a short time to notify the user that the emoji
        has been copied to the clipboard.

        :param event_box: The event box which contains the emoji
        :type event_box: Gtk.EventBox object
        '''
        # Use .get_label() instead of .get_text() to fetch the text
        # from the label widget including any embedded underlines
        # indicating mnemonics and Pango markup. The emoji is in
        # first <span>...</span>, and we want fetch only the emoji
        # here:
        text = event_box.get_child().get_label()
        if _ARGS.debug:
            sys.stdout.write("_emoji_event_box_selected() text = %s\n" %text)
        (emoji, name) = self._parse_emoji_and_name_from_text(text)
        if not emoji:
            return Gdk.EVENT_PROPAGATE
        self._set_clipboards(emoji)
        self._add_to_recently_used(emoji)
        self._emoji_selected_popover = Gtk.Popover()
        self._emoji_selected_popover.set_relative_to(event_box)
        self._emoji_selected_popover.set_position(Gtk.PositionType.TOP)
        if name:
            rectangle = Gdk.Rectangle()
            rectangle.x = 0
            rectangle.y = 0
            rectangle.width = self._fontsize * 1.5
            rectangle.height = self._fontsize * 1.5
            self._emoji_selected_popover.set_pointing_to(rectangle)
        label = Gtk.Label(_('Copied to clipboard!'))
        self._emoji_selected_popover.add(label)
        if GTK_VERSION >= (3, 22, 0):
            self._emoji_selected_popover.popup()
        self._emoji_selected_popover.show_all()
        GLib.timeout_add(500, self._emoji_selected_popover_popdown)
项目:KTV    作者:RainMark    | 项目源码 | 文件源码
def show_all(self, widget, event):
        logging.debug(widget)
        if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
            app.in_popover = True
            self.menu.set_relative_to(widget)
            pos = Gdk.Rectangle()
            pos.x = event.x + 25
            pos.y = event.y + 25
            pos.width = 0
            pos.height = 0
            self.x = event.x
            self.y = event.y
            self.menu.set_pointing_to(pos)
            self.menu.popup()
            self.view = widget
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, padding=0):
        Gtk.Alignment.__init__(self)
        # set padding + some additional padding in the bottom, left and
        # right edges to factor in the dropshadow width, and ensure even
        # visual border
        self.set_padding(padding, padding + 2, padding + 1, padding + 1)

        self._cache_art_assets()
        # second tier of caching, cache resultant surface of
        # fully composed and rendered frame
        self._frame_surface_cache = None
        self._allocation = Gdk.Rectangle()
        self.connect("size-allocate", self.on_size_allocate)
        self.connect("style-updated", self.on_style_updated)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, widget, text=""):
        PangoLayoutProxy.__init__(self, widget.get_pango_context())

        self.widget = widget
        self.length = 0
        self.indent = 0
        self.vspacing = None
        self.is_bullet = False
        self.index = 0
        self.allocation = Gdk.Rectangle()
        self._default_attrs = True
        self.set_markup(text)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, padding=0):
        Gtk.Alignment.__init__(self)
        # set padding + some additional padding in the bottom, left and
        # right edges to factor in the dropshadow width, and ensure even
        # visual border
        self.set_padding(padding, padding + 2, padding + 1, padding + 1)

        self._cache_art_assets()
        # second tier of caching, cache resultant surface of
        # fully composed and rendered frame
        self._frame_surface_cache = None
        self._allocation = Gdk.Rectangle()
        self.connect("size-allocate", self.on_size_allocate)
        self.connect("style-updated", self.on_style_updated)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, widget, text=""):
        PangoLayoutProxy.__init__(self, widget.get_pango_context())

        self.widget = widget
        self.length = 0
        self.indent = 0
        self.vspacing = None
        self.is_bullet = False
        self.index = 0
        self.allocation = Gdk.Rectangle()
        self._default_attrs = True
        self.set_markup(text)
项目:python-sense-emu    作者:RPi-Distro    | 项目源码 | 文件源码
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