Python gi.repository.Gdk.Rectangle() Examples

The following are 19 code examples of gi.repository.Gdk.Rectangle(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gdk , or try the search function .
Example #1
Source File: gtk_ui.py    From python-gui with Apache License 2.0 6 votes vote down vote up
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) 
Example #2
Source File: tool_text.py    From drawing with GNU General Public License v3.0 6 votes vote down vote up
def _open_popover_at(self, x, y):
		rectangle = Gdk.Rectangle()
		rectangle.x = x
		rectangle.y = y
		rectangle.height = 1
		rectangle.width = 1
		self._popover.set_pointing_to(rectangle)
		self._popover.set_relative_to(self.get_image())
		self._popover.popup()
		self._entry.grab_focus()
		self._preview_text()

		# Usual text entry shortcuts don't work otherwise
		self.set_action_sensitivity('paste', False)
		self.set_action_sensitivity('select_all', False)
		self.set_action_sensitivity('selection_cut', False)
		self.set_action_sensitivity('selection_copy', False) 
Example #3
Source File: infobox.py    From syncthing-gtk with GNU General Public License v2.0 6 votes vote down vote up
def do_size_allocate(self, allocation):
		child_allocation = Gdk.Rectangle()
		child_allocation.x = self.border_width
		child_allocation.y = self.border_width
 
		self.set_allocation(allocation)
 
		if self.get_has_window():
			if self.get_realized():
				self.get_window().move_resize(allocation.x, allocation.y, allocation.width, allocation.height)
		
		# Allocate children as VBox does, always use all available width
		for c in self.children:
			if not c is None:
				if c.get_visible():
					min_size, nat_size = c.get_preferred_size()
					child_allocation.width = allocation.width - (self.border_width * 2)
					child_allocation.height = min_size.height
					# TODO: Handle child that has window (where would i get it?)
					c.size_allocate(child_allocation)
					child_allocation.y += child_allocation.height + self.border_width 
Example #4
Source File: BoardView.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
def _setHover(self, cord):
        if self._hover == cord:
            return
        if self._hover:
            rectangle = rect(self.cord2RectRelative(self._hover))
            # convert r from tuple to rect
            # tmpr = r
            # r = Gdk.Rectangle()
            # r.x, r.y, r.width, r.height = tmpr
            # if cord: r = r.union(rect(self.cord2RectRelative(cord)))
            if cord:
                rectangle = union(rectangle, rect(self.cord2RectRelative(cord)))
        elif cord:
            rectangle = rect(self.cord2RectRelative(cord))
            # convert r from tuple to rect
            # tmpr = r
            # r = Gdk.Rectangle()
            # r.x, r.y, r.width, r.height = tmpr
        self._hover = cord
        self.redrawCanvas(rectangle) 
Example #5
Source File: StarArrowButton.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
def __getButtonRectangle(self, position):
        starWidth, starHeight = self.getSizeOfSvg(self.bgSvg)
        buttonWidth, buttonHeight = self.getSizeOfSvg(self.svgs[position])

        buttonWidth = buttonWidth * self.size[0] / float(starWidth)
        buttonHeight = buttonHeight * self.size[1] / float(starHeight)
        dx_loc, dy_loc = DX_DY[position]
        x_loc = ceil(dx_loc * (1 + PADDING_X) * buttonWidth - buttonWidth / 2. +
                     self.size[0] / 2.)
        y_loc = ceil(dy_loc * (1 + PADDING_Y) * buttonHeight - buttonHeight / 2. +
                     self.size[1] / 2.)

        rect = Gdk.Rectangle()
        rect.x, rect.y, rect.width, rect.height = (x_loc, y_loc, ceil(buttonWidth),
                                                   ceil(buttonHeight))
        return rect 
Example #6
Source File: ChessClock.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def redraw_canvas(self):
        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)

        GLib.idle_add(do_redraw_canvas) 
Example #7
Source File: ChainVBox.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def on_size_allocate(self, widget, requisition):
        if self.get_window():
            allocation = self.get_allocation()
            rect = Gdk.Rectangle()
            rect.x, rect.y, rect.width, rect.height = (allocation.x, allocation.y,
                                                       allocation.width, allocation.height)
            unionrect = union(self.lastRectangle,
                              rect) if self.lastRectangle is not None else rect
            self.get_window().invalidate_rect(unionrect, True)
            self.get_window().process_updates(True)
            self.lastRectangle = rect 
Example #8
Source File: ChessClock.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def expose(self, widget, ctx):
        context = widget.get_window().cairo_create()
        clip_ext = context.clip_extents()

        if clip_ext[0] > 0 or clip_ext[2] < self.get_allocated_width():
            self.redraw_canvas()
            return False

        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 
Example #9
Source File: BoardView.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def union(r_zero, r_one):
    """ Takes 2 rectangles and returns a rectangle that represents
        the union of the two areas
        Returns a Gdk.Rectangle
    """
    x_min = min(r_zero.x, r_one.x)
    y_min = min(r_zero.y, r_one.y)
    w_max = max(r_zero.x + r_zero.width, r_one.x + r_one.width) - x_min
    h_max = max(r_zero.y + r_zero.height, r_one.y + r_one.height) - y_min
    rct = Gdk.Rectangle()
    rct.x, rct.y, rct.width, rct.height = (x_min, y_min, w_max, h_max)
    return rct 
Example #10
Source File: BoardView.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def rect(rectangle):
    """
        Takes a list of 3 variables x,y,height and generates a rectangle
        rectangle(list) : contains screen locations
        returns a Gdk.Rectangle
    """
    x_size, y_size = [int(floor(v)) for v in rectangle[:2]]
    width = int(ceil(rectangle[2]))
    if len(rectangle) == 4:
        height = int(ceil(rectangle[3]))
    else:
        height = width
    rct = Gdk.Rectangle()
    rct.x, rct.y, rct.width, rct.height = (x_size, y_size, width, height)
    return rct 
Example #11
Source File: BoardView.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def expose(self, widget, ctx):
        context = widget.get_window().cairo_create()

        start = time()
        rectangle = Gdk.Rectangle()
        clip_ext = ctx.clip_extents()
        rectangle.x, rectangle.y = clip_ext[0], clip_ext[1]
        rectangle.width, rectangle.height = clip_ext[2] - clip_ext[0], clip_ext[3] - clip_ext[1]

        if False:
            import profile
            profile.runctx("self.draw(context, rectangle)", locals(), globals(), "/tmp/pychessprofile")
            from pstats import Stats
            stats = Stats("/tmp/pychessprofile")
            stats.sort_stats('cumulative')
            stats.print_stats()
        else:
            self.draw(context, rectangle)
            # self.drawcount += 1
            # self.drawtime += time() - start
            # if self.drawcount % 100 == 0:
            #    print( "Average FPS: %0.3f - %d / %d" % \
            #     (self.drawcount/self.drawtime, self.drawcount, self.drawtime))

        return False

    ############################################################################
    #                            drawing functions                             #
    ############################################################################

    ###############################
    #        redrawCanvas        #
    ############################### 
Example #12
Source File: BoardView.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def redrawCanvas(self, rect=None):
        if self.get_window():
            if not rect:
                alloc = self.get_allocation()
                rect = Gdk.Rectangle()
                rect.x, rect.y, rect.width, rect.height = (0, 0, alloc.width, alloc.height)
            self.get_window().invalidate_rect(rect, True)
            self.get_window().process_updates(True)

    ###############################
    #            draw             #
    ###############################

    # draw called each time we hover on a case. WARNING it only redraw the case 
Example #13
Source File: scorePanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def redraw(self):
        if self.get_window():
            a = self.get_allocation()
            rect = Gdk.Rectangle()
            rect.x, rect.y, rect.width, rect.height = (0, 0, a.width, a.height)
            self.get_window().invalidate_rect(rect, True)
            self.get_window().process_updates(True) 
Example #14
Source File: gtk_utils.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def get_monitor_workarea_at_point(x, y):
    """Returns the workarea (Gdk.Rectangle) for the monitor at the given point"""
    display = Gdk.Display.get_default()
    if Gtk.get_minor_version() >= 22:
        monitor = display.get_monitor_at_point(x, y)
        return monitor.get_workarea()
    screen = display.get_default_screen()
    monitor_number = screen.get_monitor_at_point(x, y)
    return screen.get_monitor_workarea(monitor_number) 
Example #15
Source File: extras.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def draw_zoom_target(self, widget, cairo_context):
        """ Perform the drawings by user.

        Args:
            widget (:class:`~Gtk.DrawingArea`): The widget where to draw the scribbles.
            cairo_context (:class:`~cairo.Context`): The canvas on which to render the drawings
        """
        ww, wh = widget.get_allocated_width(), widget.get_allocated_height()

        if self.zoom_selecting and self.zoom_points:
            xmin, xmax = sorted(p[0] * ww for p in self.zoom_points)
            ymin, ymax = sorted(p[1] * wh for p in self.zoom_points)

            rect = Gdk.Rectangle()
            rect.x = xmin
            rect.width = xmax - xmin
            rect.y = ymin
            rect.height = ymax - ymin

            cairo_context.set_line_width(3)
            cairo_context.set_line_cap(cairo.LINE_CAP_SQUARE)
            Gdk.cairo_rectangle(cairo_context, rect)
            cairo_context.set_source_rgba(.1, .1, 1, .4)
            cairo_context.stroke()

            Gdk.cairo_rectangle(cairo_context, rect)
            cairo_context.set_source_rgba(.5, .5, 1, .2)
            cairo_context.fill() 
Example #16
Source File: pdf_quench.py    From pdf-quench with GNU General Public License v2.0 5 votes vote down vote up
def __on_page_selected(self, selection=None):
    if not selection:
      selection = self.__pages_view.get_selection()

    tree_store, tree_iter = selection.get_selected()
    if tree_iter:
      page_info = tree_store[tree_iter][1]
      self.__current_page = self.__pdf_document.get_page(page_info.pagenum)
      page_width, page_height = self.__current_page.get_size()
      w, h = int(page_width), int(page_height)
      scale = self.__canvas.get_scale()
      w, h = int(w * scale), int(h * scale)
      self.__canvas.set_bounds(0, 0, w, h)

      self.__canvas.page_region = Gdk.Rectangle()
      self.__canvas.page_region.width, self.__canvas.page_region.height = w, h
      pw, ph = page_width, page_height
      page = self.__current_page
      # Render to a pixmap
      scale = min(w/pw, h/ph)
      surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
      context = cairo.Context(surface)
      context.scale(scale, scale)
      context.save()
      page.render(context)
      context.restore()
      # Convert pixmap to pixbuf
      pixbuf  = Gdk.pixbuf_get_from_surface (surface, 0, 0, w, h)
      self.__pdf_view.redraw(page_info, pixbuf)
    else:
      self.__pdf_view.redraw() 
Example #17
Source File: selection_manager.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #18
Source File: tool_text.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def _set_background_style(self, *args):
		state_as_string = self.get_option_value('text-background')
		self._bg_id = state_as_string
		if state_as_string == 'none':
			self._bg_label = _("No background")
		elif state_as_string == 'shadow':
			self._bg_label = _("Shadow")
		elif state_as_string == 'outline':
			self._bg_label = _("Outline")
		else:
			self._bg_label = _("Rectangle background") 
Example #19
Source File: gtk_ui.py    From python-gui with Apache License 2.0 5 votes vote down vote up
def Rectangle(x, y, w, h):
    r = Gdk.Rectangle()
    r.x, r.y, r.width, r.height = x, y, w, h
    return r