Example #1
0
    def tile_is_visible(self, tx, ty, transformation, clip_region, sparse,
                        translation_only):
        if not sparse:
            return True

        # it is worth checking whether this tile really will be visible
        # (to speed up the L-shaped expose event during scrolling)
        # (speedup clearly visible; slowdown measurable when always executing this code)
        N = tiledsurface.N
        if translation_only:
            x, y = transformation.transform_point(tx * N, ty * N)
            bbox = (int(x), int(y), N, N)
        else:
            corners = [(tx * N, ty * N), ((tx + 1) * N, ty * N),
                       (tx * N, (ty + 1) * N), ((tx + 1) * N, (ty + 1) * N)]
            corners = [
                transformation.transform_point(x_, y_) for (x_, y_) in corners
            ]
            bbox = helpers.rotated_rectangle_bbox(corners)

        c_r = gdk.Rectangle()
        c_r.x, c_r.y, c_r.width, c_r.height = clip_region
        bb_r = gdk.Rectangle()
        bb_r.x, bb_r.y, bb_r.width, bb_r.height = bbox
        intersects, isect_r = gdk.rectangle_intersect(bb_r, c_r)
        return intersects
    def __init__(self,
                 default_placement=None,
                 min_alpha=1.0,
                 max_alpha=1.0,
                 max_distance=100):
        super(CaribouWindow, self).__init__(gtk.WINDOW_POPUP)
        self.set_name("CaribouWindow")

        self._hbox = gtk.HBox()
        self.add(self._hbox)

        # we only have a keyboard widget right now
        self._hbox.pack_start(keyboard.CaribouKeyboard())

        # decision tree widget
        #label = gtk.Label("Hello World")
        #label.set_alignment(0, 0)
        self.colorHandler = colorhandler.ColorHandler()
        #label.show()

        self.connect("size-allocate", lambda w, a: self._update_position())
        self._gconf_client = gconf.client_get_default()

        self._cursor_location = gdk.Rectangle()
        self._entry_location = gdk.Rectangle()
        self._default_placement = default_placement or \
            CaribouWindowPlacement()
Example #3
0
    def do_size_allocate(self, allocation):
        self.allocation = allocation

        # give the controls hbox the height that it requested
        remaining_height = self.allocation.height - self._controls_hbox_height

        # give the mediaview the rest, constrained to 4/3 and centered
        media_view_width, media_view_height = self._constrain_4_3(self.allocation.width, remaining_height)
        media_view_x = self._center_in_plane(self.allocation.width, media_view_width)
        media_view_y = self._center_in_plane(remaining_height, media_view_height)

        # send allocation to mediaview
        alloc = gdk.Rectangle()
        alloc.width = media_view_width
        alloc.height = media_view_height
        alloc.x = media_view_x
        alloc.y = media_view_y
        self._media_view.size_allocate(alloc)

        # position hbox at the bottom of the window, with the requested height,
        # and the same width as the media view
        alloc = gdk.Rectangle()
        alloc.x = media_view_x
        alloc.y = self.allocation.height - self._controls_hbox_height
        alloc.width = media_view_width
        alloc.height = self._controls_hbox_height
        self._controls_hbox.size_allocate(alloc)

        if self.flags() & gtk.REALIZED:
            self.window.move_resize(*allocation)
Example #4
0
    def make_bar_bigger(self, orientation):
        if orientation == gtk.ORIENTATION_HORIZONTAL:
            region = gdk.region_rectangle(
                gdk.Rectangle(0, 0, int(self._horizaontal.bar_len),
                              self.bar_width))

            if self.hallocation.x == 0:
                self.hwindow.shape_combine_region(region,
                                                  self.top_bottom_space,
                                                  -self.right_space)
            else:
                self.hwindow.shape_combine_region(region,
                                                  -self.top_bottom_space,
                                                  -self.right_space)
        elif orientation == gtk.ORIENTATION_VERTICAL:
            region = gdk.region_rectangle(
                gdk.Rectangle(0, 0, self.bar_width,
                              int(self._vertical.bar_len)))

            if self.vallocation.y == 0:
                self.vwindow.shape_combine_region(region, -self.right_space,
                                                  self.top_bottom_space)
            else:
                self.vwindow.shape_combine_region(region, -self.right_space,
                                                  -self.top_bottom_space)
        else:
            raise "make_bar_bigger's orientation must be gtk.ORIENTATION_VERTICAL or gtk.ORIENTATION_HORIZONTAL"
Example #5
0
 def calculate_workarea(self, maxw, maxh):
     screenlog("calculate_workarea(%s, %s)", maxw, maxh)
     workarea = gdk.Rectangle(0, 0, maxw, maxh)
     for ss in self._server_sources.values():
         screen_sizes = ss.screen_sizes
         screenlog("calculate_workarea() screen_sizes(%s)=%s", ss,
                   screen_sizes)
         if not screen_sizes:
             continue
         for display in screen_sizes:
             #avoid error with old/broken clients:
             if not display or type(display) not in (list, tuple):
                 continue
             #display: [':0.0', 2560, 1600, 677, 423, [['DFP2', 0, 0, 2560, 1600, 646, 406]], 0, 0, 2560, 1574]
             if len(display) >= 10:
                 work_x, work_y, work_w, work_h = display[6:10]
                 display_workarea = gdk.Rectangle(work_x, work_y, work_w,
                                                  work_h)
                 screenlog("calculate_workarea() found %s for display %s",
                           display_workarea, display[0])
                 workarea = workarea.intersect(display_workarea)
     #sanity checks:
     screenlog("calculate_workarea(%s, %s) workarea=%s", maxw, maxh,
               workarea)
     if workarea.width == 0 or workarea.height == 0:
         screenlog.warn("Warning: failed to calculate a common workarea")
         screenlog.warn(" using the full display area: %ix%i", maxw, maxh)
         workarea = gdk.Rectangle(0, 0, maxw, maxh)
     self.set_workarea(workarea)
Example #6
0
    def do_expose_event(self, event):
        """
    Draw the widget

    Each swatch is centered in a square the size of the widget height for a
    horizontal palette or width for a vertical palette. The swatch is
    smaller than this size by twice the current padding.

    A simple shadow is drawn behind the swatch and the currently selected
    swatch is outlined.

    When dragging a color over the palette, an empty space is left to
    indicate where the new swatch would be added if dropped.
    """
        if not self.palette:
            return

        white_col = self.gc.get_colormap().alloc_color(255 * 257, 255 * 257,
                                                       255 * 257)
        self.gc.set_foreground(white_col)
        rect = gdk.Rectangle(0, 0, self.allocation.width,
                             self.allocation.height)
        self.window.draw_rectangle(self.gc, True, *rect.intersect(event.area))

        if self.direction == self.HORIZONTAL:
            size = self.allocation.height - 2 * self.padding
            x = self.padding - int(self.pan)
            y = self.padding
        else:
            size = self.allocation.width - 2 * self.padding
            x = self.padding
            y = self.padding - int(self.pan)

        rect = gdk.Rectangle(x, y, size, size)

        self.dnd_helper.set_swatch_size(size + 4)

        for color in self.palette.colors:
            # skip color being dragged
            if self.drag_is_move and color == self.drag_color: continue

            # leave room for dragged color
            if (self.direction == self.HORIZONTAL and self.drag_loc
                    and self.drag_loc[0] >= rect.x - self.padding
                    and self.drag_loc[0] < rect.x + rect.width + self.padding):
                rect.x += rect.width + 2 * self.padding

            elif (self.direction == self.VERTICAL and self.drag_loc
                  and self.drag_loc[1] >= rect.y - self.padding
                  and self.drag_loc[1] < rect.y + rect.height + self.padding):
                rect.y += rect.height + 2 * self.padding

            self.draw_swatch(color, rect, event.area, self.selected == color)

            if self.direction == self.HORIZONTAL:
                rect.x += rect.width + 2 * self.padding
            else:
                rect.y += rect.height + 2 * self.padding
Example #7
0
 def calc_vbar_allocation(self):
     bar_len = int(self._vertical.bar_len)
     if bar_len == 0:
         self.vallocation = gdk.Rectangle(0, 0, 0, 0)
         self.vwindow.hide()
     else:
         self.vwindow.show()
         self.vallocation = gdk.Rectangle(
             self.allocation.width - self.bar_width,
             int(self._vertical.bar_pos), self.bar_width, bar_len)
Example #8
0
 def calc_hbar_allocation(self):
     bar_len = int(self._horizaontal.bar_len)
     if bar_len == 0:
         self.hallocation = gdk.Rectangle(0, 0, 0, 0)
         self.hwindow.hide()
     else:
         self.hwindow.show()
         self.hallocation = gdk.Rectangle(
             int(self._horizaontal.bar_pos),
             self.allocation.height - self.bar_width, bar_len,
             self.bar_width)
Example #9
0
    def do_expose_event(self, event):
        """
    Draw the widget

    The scaled pixbuf is initially centered within the widget, and then
    offset by the current pan value.

    On top of this, a grid indicating the pixel size is drawn if draw_grid is true.

    Finally, a dashed box is drawn if a measurement is currently active.
    """
        if self.has_data == False: return

        # center image in given space
        r = gdk.Rectangle(
            int((self.allocation.width - self.pixbuf_width) / 2 + self.pan_x),
            int((self.allocation.height - self.pixbuf_height) / 2 +
                self.pan_y), self.pixbuf_width, self.pixbuf_height)

        r2 = r.intersect(event.area)

        self.window.draw_pixbuf(self.gc, self.pixbuf, r2.x - r.x, r2.y - r.y,
                                r2.x, r2.y, r2.width, r2.height,
                                gdk.RGB_DITHER_NONE, 0, 0)

        # the pixel grid is not drawn if zoom is 1, since it would fill the
        # entire image area
        if self.show_grid and self.zoom != 1:
            x_off = (r.x - r2.x) % self.zoom
            y_off = (r.y - r2.y) % self.zoom

            xmin = r2.x + x_off
            xmax = r2.x + r.width + 1
            ymin = r2.y + y_off
            ymax = r2.y + r.height + 1

            for x in range(xmin, xmax, self.zoom):
                self.window.draw_line(self.grid_gc, x, r.y, x, r.y + r.height)

            for y in range(ymin, ymax, self.zoom):
                self.window.draw_line(self.grid_gc, r.x, y, r.x + r.width, y)

        if (self.measure_rect):
            x, y = self.coord_pixbuf_to_widget(self.measure_rect.x,
                                               self.measure_rect.y)
            w = self.measure_rect.width * self.zoom
            h = self.measure_rect.height * self.zoom
            r = gdk.Rectangle(x, y, w, h)
            r = r.intersect(event.area)
            if (r.width > 0 and r.height > 0):
                self.window.draw_rectangle(self.measure_gc, False, *r)
Example #10
0
    def __init__(
        self,
        right_space=2,
        top_bottom_space=3,
    ):
        '''
        Init scrolled window.

        @param right_space: the space between right border and the vertical scrollbar.
        @param top_bottom_space: the space between top border and the vertical scrollbar.
        '''
        gtk.Bin.__init__(self)
        self.bar_min_length = 50  #scrollbar smallest height
        self.bar_small_width = 7
        self.bar_width = 14  #normal scrollbar width
        self.bar_background = ui_theme.get_color("scrolledbar")
        self.right_space = right_space
        self.top_bottom_space = top_bottom_space

        self.h_value_change_id = None
        self.h_change_id = None
        self.v_value_change_id = None
        self.v_change_id = None

        self.vscrollbar_state = None

        class Record():
            def __init__(self):
                self.bar_len = 0  # scrollbar length
                self.last_pos = 0  # last mouse motion pointer's position (x or y)

                # Last mouse motion times-tamp, if user moved the window
                # then the last_pos is likely become invalid so we need "last_time"
                # to deal with this situation.
                self.last_time = 0
                self.virtual_len = 0  # the virtual window height or width length
                self.bar_pos = 0  # the scrollbar top-corner/left-corner position
                self.is_inside = False  # is pointer in the scrollbar region?
                self.in_motion = False  # is user is dragging scrollbar?
                self.policy = gtk.POLICY_AUTOMATIC
                self.need_update_region = False  # update gdk.Window's shape_region when need

        self._horizaontal = Record()
        self._vertical = Record()

        self.set_can_focus(True)
        self.vallocation = gdk.Rectangle()
        self.hallocation = gdk.Rectangle()
        self.set_vadjustment(gtk.Adjustment())
        self.set_hadjustment(gtk.Adjustment())
        self.set_has_window(False)
Example #11
0
    def __set_entry_location(self, acc):
        text = acc.queryText()
        cursor_bb = gdk.Rectangle(*text.getCharacterExtents(
            text.caretOffset, pyatspi.DESKTOP_COORDS))

        component = acc.queryComponent()
        entry_bb = component.getExtents(pyatspi.DESKTOP_COORDS)

        if cursor_bb == gdk.Rectangle(0, 0, 0, 0):
            cursor_bb = entry_bb

        caribouwindow.set_cursor_location(cursor_bb)
        caribouwindow.set_entry_location(entry_bb)

        caribouwindow.show_all()
Example #12
0
    def press_notify_event(self, obj, data):
        x, y, data = data.window.get_pointer()
        col = self.find_col(x)
        row = self.find_row(y)
        if (row >= 0) and (col >= 0):
            self.jday = self.day[row][col]
            self.current_day = [0, 0]
            if (row == 0) and (self.day[row][col] > 15):
                self.jmonth -= 1
                if self.jmonth <= 0:
                    self.jmonth = 12
                    self.jyear -= 1
                self.emit("month-change", self.jmonth, self.jyear)

            if (row > 3) and (self.day[row][col] < 15):
                self.jmonth += 1
                if self.jmonth > 12:
                    self.jmonth = 1
                    self.jyear += 1
                self.emit("month-change", self.jmonth, self.jyear)

            self.emit("day-change", self.jmonth, self.jyear,
                      self.day[row][col])
            alloc = self.get_allocation()
            rect = gdk.Rectangle(0, 0, alloc.width, alloc.height)
            self.window.invalidate_rect(rect, True)
        return True
Example #13
0
    def do_realize(self):
        ident = os.environ.get('XSCREENSAVER_WINDOW')

        if ident is None:
            self.window = gdk.Window(self.get_parent_window(),
                                     width=self.allocation.width,
                                     height=self.allocation.height,
                                     window_type=gdk.WINDOW_TOPLEVEL,
                                     event_mask=self.get_events()
                                     | gdk.EXPOSURE_MASK,
                                     wclass=gdk.INPUT_OUTPUT,
                                     title=self.__default_title)

            self.set_size_request(self.__default_width, self.__default_height)
            self.connect('delete-event', self.on_destroy)

        else:
            self.window = gdk.window_foreign_new(int(ident, 16))
            self.window.set_events(gdk.EXPOSURE_MASK | gdk.STRUCTURE_MASK)

            x, y, w, h, depth = self.window.get_geometry()
            self.size_allocate(gdk.Rectangle(x, y, w, h))
            self.set_default_size(w, h)
            self.set_size_request(w, h)

            self.set_decorated(False)

        self.window.set_user_data(self)
        self.style.attach(self.window)
        self.set_flags(self.flags() | gtk.REALIZED)
Example #14
0
 def update(self):
     if self.window is None:
         return
     alloc = self.get_allocation()
     rect = gdk.Rectangle(alloc.x, alloc.y, alloc.width, alloc.height)
     self.window.invalidate_rect(rect, True)
     self.window.process_updates(True)
Example #15
0
def center_of_dimensions(dim):
    '''
  Returns a point (a rect) that is the center of the dimensions.
  '''
    rect = gdk.Rectangle(dim.x + dim.width / 2, dim.y + dim.height / 2, 1, 1)
    # print "coordinates.center_of_dimensions", rect
    return rect
    def _get_root_bbox(self):
        root_window = gdk.get_default_root_window()
        args = root_window.get_position() + root_window.get_size()

        root_bbox = gdk.Rectangle(*args)

        current_screen = gtk.gdk.screen_get_default().get_number()
        for panel in self._gconf_client.all_dirs('/apps/panel/toplevels'):
            orientation = self._gconf_client.get_string(panel + '/orientation')
            size = self._gconf_client.get_int(panel + '/size')
            screen = self._gconf_client.get_int(panel + '/screen')
            if screen != current_screen:
                continue
            if orientation == 'top':
                root_bbox.y += size
                root_bbox.height -= size
            elif orientation == 'bottom':
                root_bbox.height -= size
            elif orientation == 'right':
                root_bbox.x += size
                root_bbox.width -= size
            elif orientation == 'left':
                root_bbox.x -= size

        return root_bbox
Example #17
0
    def realize(self):
        if self.flags() & gtk.REALIZED:
            return

        ident = os.environ.get('XSCREENSAVER_WINDOW')

        if ident:
            self.window = gdk.window_foreign_new(int(ident, 16))
            self.window.set_events(gdk.EXPOSURE_MASK | gdk.STRUCTURE_MASK)
            x, y, w, h, depth = self.window.get_geometry()
            self.size_allocate(gdk.Rectangle(x, y, w, h))
            self.set_default_size(w, h)
            self.set_decorated(False)

            self.window.set_user_data(self)
            self.style.attach(self.window)
            self.set_flags(self.flags() | gtk.REALIZED)
            #self.window.connect("destroy", self.destroy)

        if not self.window:
            self.window = gdk.Window(None, 1024, 768, gdk.WINDOW_TOPLEVEL,
                                     (gdk.EXPOSURE_MASK | gdk.STRUCTURE_MASK),
                                     gdk.INPUT_OUTPUT)

        if self.window:
            #self.window.add_filter(lambda *args: self.filter_event(args))
            self.set_flags(self.flags() | gtk.REALIZED)
Example #18
0
    def _on__button_press_event(self, window, event):
        # If we're clicking outside of the window close the popup
        hide = False

        # Also if the intersection of self and the event is empty, hide
        # the calendar
        if (tuple(
                self.allocation.intersect(
                    gdk.Rectangle(x=int(event.x),
                                  y=int(event.y),
                                  width=1,
                                  height=1))) == (0, 0, 0, 0)):
            hide = True

        # Toplevel is the window that received the event, and parent is the
        # calendar window. If they are not the same, means the popup should
        # be hidden. This is necessary for when the event happens on another
        # widget
        toplevel = event.window.get_toplevel()
        parent = self.calendar.get_parent_window()
        if toplevel != parent:
            hide = True

        if hide:
            self.popdown()
Example #19
0
    def set_child_size(self):
        title_w_padding = self.allocation.width / len(self.children)
        allocation = gdk.Rectangle()
        allocation.x = 0
        allocation.y = 0
        allocation.width = title_w_padding
        allocation.height = self.title_h
        self.title_child1.size_allocate(allocation)
        allocation.x = 0 + allocation.width
        self.title_child2.size_allocate(allocation)
        #
        if self.layout_show_check:
            layout2_x = -self.allocation.width
        else:
            layout2_x = 0

        allocation.x = layout2_x
        allocation.y = 0 + self.title_h  #self.layout2.allocation.y
        allocation.width = self.allocation.width
        allocation.height = self.allocation.height - self.title_h
        self.layout2.size_allocate(allocation)
        if not self.layout_show_check:
            layout1_x = -self.allocation.width
        else:
            layout1_x = 0
        allocation.x = layout1_x
        allocation.y = 0 + self.title_h  #self.layout1.allocation.y
        self.layout1.size_allocate(allocation)
Example #20
0
 def next_month(self):
     self.jmonth += 1
     if self.jmonth > 12:
         self.jmonth = 1
         self.jyear += 1
     alloc = self.get_allocation()
     rect = gdk.Rectangle(0, 0, alloc.width, alloc.height)
     self.window.invalidate_rect(rect, True)
Example #21
0
def dimensions_from_extents(ulx, uly, lrx, lry):
    '''
  Convert extents to a dimensions rect
  '''
    assert isinstance(ulx, int)
    width = lrx - ulx
    height = lry - uly
    return gdk.Rectangle(ulx, uly, width, height)
Example #22
0
 def _on__button_press_event(self, window, event):
     # If we're clicking outside of the window
     # close the popup
     if (event.window != self.window or
         (tuple(self.allocation.intersect(
                gdk.Rectangle(x=int(event.x), y=int(event.y),
                              width=1, height=1)))) == (0, 0, 0, 0)):
         self.popdown()
Example #23
0
def center_on_coords(dim, point):
    '''
  Returns dimensions with ul at point.
  Takes the width and height from the dimensions.
  '''
    rect = gdk.Rectangle(point.x - (dim.width / 2), point.y - (dim.height / 2),
                         dim.width, dim.height)
    return rect
Example #24
0
File: fps.py Project: tardyp/Xpra
 def repaint(self):
     self.counter += 1
     if GTK3:
         self.queue_draw()
     else:
         window = self.get_window()
         window.invalidate_rect(gdk.Rectangle(0, 0, WIDTH, HEIGHT), False)
     return True
Example #25
0
 def prev_month(self):
     self.jmonth -= 1
     if self.jmonth <= 0:
         self.jmonth = 12
         self.jyear -= 1
     alloc = self.get_allocation()
     rect = gdk.Rectangle(0, 0, alloc.width, alloc.height)
     self.window.invalidate_rect(rect, True)
Example #26
0
 def queue_draw(self, x, y, width, height):
     window = self.get_window()
     if window:
         window.invalidate_rect(gdk.Rectangle(x, y, width, height), False)
     else:
         log.warn(
             "ignoring draw received for a window which is not realized yet!"
         )
Example #27
0
 def _allocate_child(self, child):
     allocation = gdk.Rectangle()
     allocation.x = child.x
     allocation.y = child.y
     req = child.widget.get_child_requisition()
     allocation.width = req[0]
     allocation.height = req[1]
     child.widget.size_allocate(allocation)
Example #28
0
    def _insert_item(self, item, position=None, visible_position=None):
        assert isinstance(item, DockItem)
        assert self.item_num(item) is None

        if position is None or position < 0:
            position = len(self)

        # Create composite children for tab
        gtk.widget_push_composite_child()
        tab = _DockGroupTab()
        tab.image = item.get_image()
        tab.label = gtk.Label()
        tab.button = CompactButton(has_frame=False)
        tab.menu_item = gtk.ImageMenuItem()
        gtk.widget_pop_composite_child()

        # Configure child widgets for tab
        tab.item = item
        tab.item.set_parent(self)
        tab.item_title_handler = tab.item.connect('notify::title',
                                                  self._on_item_title_changed,
                                                  tab)
        tab.item_title_tooltip_text_handler = tab.item.connect(
            'notify::title-tooltip-text',
            self._on_item_title_tooltip_text_changed, tab)
        tab.image.set_parent(self)
        tab.label.set_text(item.get_title())
        tab.label.set_parent(self)
        tab.button.set_icon_name_normal('compact-close')
        tab.button.set_icon_name_prelight('compact-close-prelight')
        tab.button.set_parent(self)
        tab.button.connect('clicked', self._on_tab_button_clicked, item)
        tab.menu_item.set_image(item.get_image())
        tab.menu_item.set_label(item.get_title())
        tab.menu_item.connect('activate', self._on_list_menu_item_activated,
                              tab)
        self._list_menu.append(tab.menu_item)
        tab.area = gdk.Rectangle()
        tab.last_focused = time()

        if self.flags() & gtk.REALIZED:
            tab.item.set_parent_window(self.window)
            tab.image.set_parent_window(self.window)
            tab.label.set_parent_window(self.window)
            tab.button.set_parent_window(self.window)

        self._tabs.insert(position, tab)
        self.emit('item-added', item)

        # TODO: get rid of this pronto!
        if visible_position is not None:
            self._visible_tabs.insert(visible_position, tab)

        item_num = self.item_num(item)
        self.set_current_item(item_num)

        return item_num
Example #29
0
def center_on_origin(dim):
    '''
  Returns rect translated so its center is at the origin (0,0)
  '''
    center = center_of_dimensions(dim)
    # FIXME call center_on_coords(center)
    rect = gdk.Rectangle(dim.x - center.x, dim.y - center.y, dim.width,
                         dim.height)
    return rect
Example #30
0
def dimensions_from_float_extents(ulx, uly, lrx, lry):
    '''
  Convert extents to a dimensions rect
  '''
    assert isinstance(ulx, float)
    width = math.ceil(lrx - ulx)
    height = math.ceil(lry - uly)
    # Rectangle() will convert to ints
    return gdk.Rectangle(ulx, uly, width, height)