Пример #1
0
 def motion_notify_event(self, widget, event):
     x, y, _ = widget.window.get_pointer()
     x, y = widget.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
     tags = widget.get_iter_at_location(x, y).get_tags()
     is_over_anchor = False
     for tag, href in self.anchor_tags.values():
         if tag in tags:
             is_over_anchor = True
             break
     if is_over_anchor:
         if not self._changed_cursor:
             # print 'set cursor hand'
             window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
             window.set_cursor(gdk.Cursor(self.handcursor))
             self._changed_cursor = True
         self.statusbar.pop(0)
         href = self.normurl(href)
         self.statusbar.push(0, href)
     else:
         if self._changed_cursor:
             # print 'set cursor xterm'
             window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
             window.set_cursor(gdk.Cursor(self.defcursor))
             self._changed_cursor = False
         self.statusbar.pop(0)
     return False
Пример #2
0
    def do_realize(self):
        # Internal housekeeping
        self.set_flags(self.flags() | gtk.REALIZED)
        self.window = gdk.Window(
            self.get_parent_window(),
            x=self.allocation.x,
            y=self.allocation.y,
            width=self.allocation.width,
            height=self.allocation.height,
            window_type=gdk.WINDOW_CHILD,
            wclass=gdk.INPUT_OUTPUT,
            event_mask=(gdk.EXPOSURE_MASK | gdk.LEAVE_NOTIFY_MASK
                        | gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK
                        | gdk.POINTER_MOTION_MASK))
        self.window.set_user_data(self)
        self.style.attach(self.window)
        self.style.set_background(self.window, gtk.STATE_NORMAL)

        # Set parent window on all child widgets
        for item in self._items:
            item.child.set_parent_window(self.window)

        # Initialize cursors
        self._hcursor = gdk.Cursor(self.get_display(), gdk.SB_H_DOUBLE_ARROW)
        self._vcursor = gdk.Cursor(self.get_display(), gdk.SB_V_DOUBLE_ARROW)
Пример #3
0
    def show(self, text, x, y):
        """
        Show the window with the given text, its top-left corner at x-y.
        Decide on initial size.
        """
        # The initial size is the minimum of:
        # * N_COLS*N_ROWS
        # * Whatever fits into the screen
        # * The actual content

        tv = self.textview
        vs = self.vscrollbar
        win = self.window

        text = text.replace('\0', '')  # Fixes bug #611513

        win.hide()
        tv.get_buffer().set_text(text)

        f_width = self.char_width * N_COLS
        f_height = self.char_height * N_ROWS

        s_width = gdk.screen_width() - x
        s_height = gdk.screen_height() - y

        # Get the size of the contents
        layout = tv.create_pango_layout(text)
        p_width, p_height = layout.get_size()
        c_width = pango.PIXELS(p_width)
        c_height = pango.PIXELS(p_height)
        del layout

        add_width = vs.size_request()[0] + 5
        width = int(min(f_width, s_width, c_width) + add_width)
        height = int(min(f_height, s_height, c_height))

        # Don't show the vertical scrollbar if the height is short enough.
        vs.props.visible = (height > vs.size_request()[1])

        win.resize(width, height)

        win.move(x, y)

        self.hscrollbar.props.adjustment.props.value = 0
        self.vscrollbar.props.adjustment.props.value = 0

        self.sourceview.handler_unblock(self.keypress_handler)
        self.keypress_handler_blocked = False

        win.show()

        # This has to be done after the textview was displayed
        if not self.was_displayed:
            self.was_displayed = True
            hand = gdk.Cursor(gdk.HAND1)
            tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(hand)
            br_corner = gdk.Cursor(gdk.BOTTOM_RIGHT_CORNER)
            self.resizegrip.window.set_cursor(br_corner)
Пример #4
0
 def make_cursor(self, cursor_data):
     #if present, try cursor ny name:
     if len(cursor_data) >= 9 and cursor_names:
         cursor_name = cursor_data[8]
         if cursor_name:
             gdk_cursor = cursor_names.get(cursor_name.upper())
             if gdk_cursor is not None:
                 log("setting new cursor by name: %s=%s", cursor_name,
                     gdk_cursor)
                 return gdk.Cursor(gdk_cursor)
             else:
                 global missing_cursor_names
                 if cursor_name not in missing_cursor_names:
                     log.warn("cursor name '%s' not found", cursor_name)
                     missing_cursor_names.add(cursor_name)
     #create cursor from the pixel data:
     w, h, xhot, yhot, serial, pixels = cursor_data[2:8]
     if len(pixels) < w * h * 4:
         import binascii
         log.warn(
             "not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)",
             w * h * 4, len(pixels),
             binascii.hexlify(pixels)[:100])
         return
     pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8,
                                       w, h, w * 4)
     x = max(0, min(xhot, w - 1))
     y = max(0, min(yhot, h - 1))
     display = gdk.display_get_default()
     csize = display.get_default_cursor_size()
     cmaxw, cmaxh = display.get_maximal_cursor_size()
     if len(cursor_data) >= 11:
         ssize = cursor_data[9]
         smax = cursor_data[10]
         log("server cursor sizes: default=%s, max=%s", ssize, smax)
     log(
         "new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s, default cursor size is %s, maximum=%s",
         xhot, yhot, serial, w, h, len(pixels), csize, (cmaxw, cmaxh))
     ratio = 1
     if w > cmaxw or h > cmaxh or (csize > 0 and (csize < w or csize < h)):
         ratio = max(
             float(w) / cmaxw,
             float(h) / cmaxh,
             float(max(w, h)) / csize)
         log("downscaling cursor by %.2f", ratio)
         pixbuf = pixbuf.scale_simple(int(w / ratio), int(h / ratio),
                                      gdk.INTERP_BILINEAR)
         x = int(x / ratio)
         y = int(y / ratio)
     return gdk.Cursor(gdk.display_get_default(), pixbuf, x, y)
Пример #5
0
    def on_btn_right_clicked(self, widget, selection):
        (model, l_iter) = selection.get_selected()
        if l_iter is None:
            return

        fname = model.get_filename(l_iter)

        #Check duplicate
        ff = os.path.join(self.conf.sl_dicts_dir, fname[:-4])
        if os.path.isfile(ff):
            ghlp.show_error(self, _("Dictionary already installed!"))
            return

        #Check permissions
        if not is_path_writable(self.conf.sl_dicts_dir):
            ghlp.show_error(self, _("You do not have permissions!"))
            return

        ghlp.change_cursor(gdk.Cursor(gdk.WATCH))

        event = threading.Event()
        installer = DictInstaller(fname, event)
        installer.connect(self.on_installer_change)

        self.pg = ghlp.ProgressDialog(self, "Installation...", "Connecting...")
        self.pg.connect("response", lambda x, y:
                        (y == -6 and installer.cancel()))
        self.pg.show_all()

        thread = threading.Thread(target=self.__wait_connection,
                                  args=(event, self.pg))
        thread.start()
        installer.start()
Пример #6
0
 def leave_event(self, widget, event):
     if self._changed_cursor:
         # print 'set cursor xterm'
         window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
         window.set_cursor(gdk.Cursor(self.defcursor))
         self._changed_cursor = False
     self.statusbar.pop(0)
Пример #7
0
 def update_cursor(self):
     # Callback for updating the cursor
     if not self.get_mapped():
         return
     window = self.get_window()
     app = self.app
     if window is None:
         logger.error("update_cursor: no window")
         return
     override_cursor = self._override_cursor
     layer = self.doc._layers.current
     if override_cursor is not None:
         c = override_cursor
     elif self.get_state() == gtk.STATE_INSENSITIVE:
         c = None
     elif self.doc is None:
         logger.error("update_cursor: no document")
         return
     elif layer.locked or not layer.visible or not layer.get_paintable():
         # Cursor to represent that one cannot draw.
         # Often a red circle with a diagonal bar through it.
         c = gdk.Cursor(gdk.CIRCLE)
     elif app is None:
         logger.error("update_cursor: no app")
         return
     # Last two cases only pertain to FreehandMode cursors.
     # XXX refactor: bad for separation of responsibilities, put the
     # special cases in the mode class.
     elif app.preferences.get("cursor.freehand.style", None) == 'crosshair':
         c = app.cursors.get_freehand_cursor()
     else:
         radius, style = self._get_cursor_info()
         c = cursor.get_brush_cursor(radius, style, self.app.preferences)
     window.set_cursor(c)
Пример #8
0
    def _selectAllPackages(self, *args):
        selection = self.xml.get_widget("groupList").get_selection()
        if selection.count_selected_rows() == 0:
            return
        (model, paths) = selection.get_selected_rows()

        self.vbox.window.set_cursor(gdk.Cursor(gdk.WATCH))

        for p in paths:
            i = model.get_iter(p)
            grp = model.get_value(i, 2)

            # ensure the group is selected
            self.ayum.selectGroup(grp.groupid)
            model.set_value(i, 0, True)
        
            for pkg in grp.default_packages.keys() + \
                    grp.optional_packages.keys():
                if self.ayum.isPackageInstalled(pkg):
                    continue
                elif self.ayum.simpleDBInstalled(name = pkg):
                    txmbrs = self.ayum.tsInfo.matchNaevr(name = pkg)
                    for tx in txmbrs:
                        if tx.output_state == TS_ERASE:
                            self.ayum.tsInfo.remove(tx.pkgtup)
                else:
                    _selectPackage(self.ayum, grp, pkg)

        if len(paths) == 1:
            self.__setGroupDescription(grp)
        self.vbox.window.set_cursor(None)
Пример #9
0
    def _update_cursors(self, tdw, xd, yd):
        model = self.doc.model
        if not model.frame_enabled:
            self.active_cursor = self.cursor_forbidden
            self.inactive_cursor = self.cursor_forbidden
            return

        # Simpler interpretations
        zone = self._get_zone(tdw, xd, yd)
        if zone == self.OUTSIDE:
            self.active_cursor = self.cursor_forbidden
            self.inactive_cursor = self.cursor_forbidden
            return
        elif zone == self.INSIDE:
            self.active_cursor = self.cursor_hand_closed
            self.inactive_cursor = self.cursor_hand_open
            return

        # Centre of frame, in display coordinates
        fx, fy, fw, fh = model.get_frame()
        cx, cy = fx + (fw / 2.0), fy + (fh / 2.0)
        cxd, cyd = tdw.model_to_display(cx, cy)

        # A reference point, reflecting the side or edge where the pointer is
        rx, ry = cx, cy
        if zone & self.RIGHT: rx = fx + fw
        elif zone & self.LEFT: rx = fx
        if zone & self.BOTTOM: ry = fy + fh
        elif zone & self.TOP: ry = fy
        rxd, ryd = tdw.model_to_display(rx, ry)

        # Angle of the line from (cx, cy) to (rx, ry), in display space
        # First constrain to {0..2pi}
        theta = math.atan2((ryd - cyd), (rxd - cxd))
        while theta < 2 * math.pi:
            theta += 2 * math.pi
        theta %= 2 * math.pi
        assert theta >= 0
        assert theta < 2 * math.pi

        # The cursor chosen reflects how the chosen edge can be moved.
        cursors = [
            (1, self.cursor_move_w_e),  # right side
            (3, self.cursor_move_nw_se),  # bottom right corner
            (5, self.cursor_move_n_s),  # bottom side
            (7, self.cursor_move_ne_sw),  # bottom left corner
            (9, self.cursor_move_w_e),  # left side
            (11, self.cursor_move_nw_se),  # top left corner
            (13, self.cursor_move_n_s),  # top side
            (15, self.cursor_move_ne_sw),  # top right corner
            (17, self.cursor_move_w_e),  # right side
        ]
        for i, cursor in cursors:
            if theta < i * (2.0 / 16) * math.pi:
                self.inactive_cursor = cursor
                self.active_cursor = cursor
                return

        # This should never happen.
        self.cursor = gdk.Cursor(gdk.BOGOSITY)
Пример #10
0
def capture_begin_execute_panel(capture, panel, view, label):
    view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gdk.Cursor(gdk.WATCH))

    panel['stop'].set_sensitive(True)
    panel.clear()
    panel.write(_("Running tool:"), panel.italic_tag)
    panel.write(" %s\n\n" % label, panel.bold_tag)
Пример #11
0
def capture_end_execute_panel(capture, exit_code, panel, view, output_type):
    panel['stop'].set_sensitive(False)

    if output_type in ('new-document', 'replace-document'):
        doc = view.get_buffer()
        start = doc.get_start_iter()
        end = start.copy()
        end.forward_chars(300)

        mtype = gio.content_type_guess(data=doc.get_text(start, end))
        lmanager = pluma.get_language_manager()

        language = lmanager.guess_language(doc.get_uri(), mtype)

        if language is not None:
            doc.set_language(language)

    view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gdk.Cursor(gdk.XTERM))
    view.set_cursor_visible(True)
    view.set_editable(True)

    if exit_code == 0:
        panel.write("\n" + _("Done.") + "\n", panel.italic_tag)
    else:
        panel.write("\n" + _("Exited") + ":", panel.italic_tag)
        panel.write(" %d\n" % exit_code, panel.bold_tag)
    def __init__(self, datadir, window):
        if UniqueById.__init__(self, window):
            return

        callbacks = {
            'on_stop_clicked': self.on_stop_clicked,
            'on_view_visibility_notify_event':
            self.on_view_visibility_notify_event,
            'on_view_motion_notify_event': self.on_view_motion_notify_event,
            'on_view_button_press_event': self.on_view_button_press_event
        }

        self.window = window
        self.ui = gtk.Builder()
        self.ui.add_from_file(os.path.join(datadir, 'ui', 'outputpanel.ui'))
        self.ui.connect_signals(callbacks)

        self.panel = self["output-panel"]
        self['view'].modify_font(pango.FontDescription('Monospace'))

        buffer = self['view'].get_buffer()

        self.normal_tag = buffer.create_tag('normal')

        self.error_tag = buffer.create_tag('error')
        self.error_tag.set_property('foreground', 'red')

        self.italic_tag = buffer.create_tag('italic')
        self.italic_tag.set_property('style', pango.STYLE_OBLIQUE)

        self.bold_tag = buffer.create_tag('bold')
        self.bold_tag.set_property('weight', pango.WEIGHT_BOLD)

        self.invalid_link_tag = buffer.create_tag('invalid_link')

        self.link_tag = buffer.create_tag('link')
        self.link_tag.set_property('underline', pango.UNDERLINE_SINGLE)

        self.link_cursor = gdk.Cursor(gdk.HAND2)
        self.normal_cursor = gdk.Cursor(gdk.XTERM)

        self.process = None

        self.links = []

        self.link_parser = linkparsing.LinkParser()
        self.file_lookup = filelookup.FileLookup()
Пример #13
0
    def __init__(self,
                 app,
                 parent,
                 title=None,
                 images=None,
                 color='blue',
                 bg='#c0c0c0',
                 height=25,
                 show_text=1,
                 norm=1):
        self.parent = parent
        self.percent = 0
        self.steps_sum = 0
        self.norm = norm
        self.top = makeToplevel(parent, title=title)
        self.top.set_position(gtk.WIN_POS_CENTER)
        self.top.set_resizable(False)
        self.top.connect("delete_event", self.wmDeleteWindow)

        # hbox
        hbox = gtk.HBox(spacing=5)
        hbox.set_border_width(10)
        hbox.show()
        self.top.table.attach(hbox, 0, 1, 0, 1, 0, 0, 0, 0)
        # hbox-1: image
        if images and images[0]:
            im = gtk.Image()
            im.set_from_pixbuf(images[0].pixbuf)
            hbox.pack_start(im, expand=False, fill=False)
            im.show()
            im.set_property('xpad', 10)
            im.set_property('ypad', 5)
        # hbox-2:vbox
        vbox = gtk.VBox()
        vbox.show()
        hbox.pack_start(vbox, False, False)
        # hbox-2:vbox:pbar
        self.pbar = gtk.ProgressBar()
        self.pbar.show()
        vbox.pack_start(self.pbar, True, False)
        self.pbar.realize()
        # ~ self.pbar.set_show_text(show_text)
        self.pbar.set_text(str(show_text) + '%')
        w, h = self.pbar.size_request()
        self.pbar.set_size_request(max(w, 300), max(h, height))
        # hbox-3:image
        if images and images[1]:
            im = gtk.Image()
            im.set_from_pixbuf(images[1].pixbuf)
            hbox.pack_end(im, expand=False)
            im.show()
            im.set_property('xpad', 10)
            im.set_property('ypad', 5)

        setTransient(self.top, parent)
        self.top.show()
        self.top.window.set_cursor(gdk.Cursor(gdk.WATCH))
        self.update(percent=0)
Пример #14
0
    def get_action_cursor(self, action_name, cursor_name="cursor_arrow"):
        """Returns an overlay cursor for a named action. Cached.

        :param action_name: the name of a GtkAction defined in mypaint.xml
        :param cursor_name: name of a pixmaps/ image to use, minus the .png

        The action's icon will be overlaid at a small size to the bottom and
        right of the cursor image.

        """
        # Find a small action icon for the overlay
        action = self.app.find_action(action_name)
        if action is None:
            return gdk.Cursor(gdk.BOGOSITY)
        icon_name = action.get_icon_name()
        if icon_name is None:
            return gdk.Cursor(gdk.BOGOSITY)
        return self.get_icon_cursor(icon_name, cursor_name)
Пример #15
0
def _get_cursor(gdk_pos):
    # Do a lazy initialization of those gdk.Cursor objects
    # If we initialize them too early (e.g. in the module) they would
    # break Stoq running on non graphical environments.
    c = _cursors.get(gdk_pos, None)
    if c is not None:
        return c

    return _cursors.setdefault(gdk_pos, gdk.Cursor(gdk_pos))
Пример #16
0
    def do_button_release_event(self, event):
        if event.button == 1:
            self.__move_begined = False
            del self.__press_pos
            del self.__workarea
            self.window.set_cursor(gdk.Cursor(gdk.LEFT_PTR))
            self.emit("move-end")
            return True

        return False
Пример #17
0
class Pan(Operation):
    cursor = gdk.Cursor(gdk.DOT)
    begin_cursor = gdk.Cursor(gdk.CIRCLE)

    def beginState(self):
        self.canvas.window.set_cursor(self.cursor)

    def endState(self):
        self.canvas.window.set_cursor(None)

    def begin(self):
        self.canvas.window.set_cursor(self.begin_cursor)

    def finish(self):
        self.canvas.window.set_cursor(self.cursor)

    def update(self, x, y):
        ha = self.canvas.get_hadjustment()
        va = self.canvas.get_vadjustment()

        # FIXME - Pan could be much faster, but it gets jittery
        x_moved = self.begin_x - x
        y_moved = self.begin_y - y

        alloc = self.canvas.get_allocation()

        if x_moved:
            if ha.lower <= (ha.value + x_moved + alloc.width) <= ha.upper:
                ha.set_value(ha.value + x_moved)
            elif ha.value + x_moved + alloc.width > ha.upper:
                ha.set_value(ha.upper - alloc.width)
            elif ha.lower < ha.value + x_moved + alloc.width:
                ha.set_value(ha.lower)

        if y_moved:
            if va.lower <= (va.value + y_moved + alloc.height) <= va.upper:
                va.set_value(va.value + y_moved)
            elif va.value + y_moved + alloc.height > va.upper:
                va.set_value(va.upper - alloc.height)
            elif va.lower < va.value + y_moved + alloc.height:
                va.set_value(va.lower)
Пример #18
0
 def set_windows_cursor(self, gtkwindows, cursor_data):
     cursor = None
     if cursor_data:
         try:
             cursor = self.make_cursor(cursor_data)
         except Exception, e:
             log.warn("error creating cursor: %s (using default)",
                      e,
                      exc_info=True)
         if cursor is None:
             #use default:
             cursor = gdk.Cursor(gtk.gdk.X_CURSOR)
Пример #19
0
def button_press_event(box, event):
    global OFFSET_X, OFFSET_Y

    if event.button == 1:
        window = box.get_parent()
        x, y = window.get_position()
        OFFSET_X = event.x_root - x
        OFFSET_Y = event.y_root - y

        arrow = gdk.Cursor(gdk.FLEUR)
        root = window.get_root_window()
        root.set_cursor(arrow)
Пример #20
0
    def __init__(self, prefs, datapath):
        """Initialises with default colors and an empty adjuster list.

        :param prefs: Prefs dict for saving settings.
        :param datapath: Base path for saving palettes and masks.

        """
        gobject.GObject.__init__(self)

        # Defaults
        self._color = None  #: Currently edited color, a UIColor object
        self._hist = []  #: List of previous colors, most recent last
        self._palette = None  #: Current working palette
        self._adjusters = weakref.WeakSet()  #: The set of registered adjusters
        self._picker_cursor = gdk.Cursor(gdk.CROSSHAIR)  #: Cursor for pickers
        self._datapath = datapath  #: Base path for saving palettes and masks
        self._hue_distorts = None  #: Hue-remapping table for color wheels
        self._prefs = prefs  #: Shared preferences dictionary

        # Build the history. Last item is most recent.
        hist_hex = list(prefs.get(PREFS_KEY_COLOR_HISTORY, []))
        hist_hex = self._DEFAULT_HIST + hist_hex
        self._hist = [RGBColor.new_from_hex_str(s) for s in hist_hex]
        self._trim_hist()

        # Restore current color, or use the most recent color.
        col_hex = prefs.get(PREFS_KEY_CURRENT_COLOR, None)
        if col_hex is None:
            col_hex = hist_hex[-1]
        self._color = RGBColor.new_from_hex_str(col_hex)

        # Initialize angle distort table
        wheel_type = prefs.get(PREFS_KEY_WHEEL_TYPE, self._DEFAULT_WHEEL_TYPE)
        distorts_table = self._HUE_DISTORTION_TABLES[wheel_type]
        self._hue_distorts = distorts_table

        # Initialize working palette
        palette_dict = prefs.get(PREFS_PALETTE_DICT_KEY, None)
        if palette_dict is not None:
            palette = Palette.new_from_simple_dict(palette_dict)
        else:
            datapath = self.get_data_path()
            palettes_dir = os.path.join(datapath, DATAPATH_PALETTES_SUBDIR)
            default = os.path.join(palettes_dir, DEFAULT_PALETTE_FILE)
            palette = Palette(filename=default)
        self._palette = palette

        # Capture updates to the working palette
        palette.info_changed += self._palette_changed_cb
        palette.match_changed += self._palette_changed_cb
        palette.sequence_changed += self._palette_changed_cb
        palette.color_changed += self._palette_changed_cb
Пример #21
0
 def make_cursor(self, cursor_data):
     #if present, try cursor ny name:
     if len(cursor_data) >= 9 and cursor_names:
         cursor_name = cursor_data[8]
         if cursor_name:
             gdk_cursor = cursor_names.get(cursor_name.upper())
             if gdk_cursor is not None:
                 log("setting new cursor by name: %s=%s", cursor_name,
                     gdk_cursor)
                 return gdk.Cursor(gdk_cursor)
             else:
                 log("cursor name '%s' not found", cursor_name)
     #create cursor from the pixel data:
     w, h, xhot, yhot, serial, pixels = cursor_data[2:8]
     if len(pixels) < w * h * 4:
         import binascii
         log.warn(
             "not enough pixels provided in cursor data: %s needed and only %s bytes found (%s)",
             w * h * 4, len(pixels),
             binascii.hexlify(pixels)[:100])
         return
     pixbuf = gdk.pixbuf_new_from_data(pixels, gdk.COLORSPACE_RGB, True, 8,
                                       w, h, w * 4)
     x = max(0, min(xhot, w - 1))
     y = max(0, min(yhot, h - 1))
     size = gdk.display_get_default().get_default_cursor_size()
     log(
         "new cursor at %s,%s with serial=%s, dimensions: %sx%s, len(pixels)=%s, default cursor size is %s",
         xhot, yhot, serial, w, h, len(pixels), size)
     if size > 0 and (size < w or size < h) and False:
         ratio = float(max(w, h)) / size
         log("downscaling cursor by %.2f", ratio)
         pixbuf = pixbuf.scale_simple(int(w / ratio), int(h / ratio),
                                      gdk.INTERP_BILINEAR)
         x = int(x / ratio)
         y = int(y / ratio)
     return gdk.Cursor(gdk.display_get_default(), pixbuf, x, y)
Пример #22
0
    def refresh(self):
        ghlp.change_cursor(gdk.Cursor(gdk.WATCH))

        event = threading.Event()
        thread = threading.Thread(target=self.download_repo_file,
                                  args=(event, ))
        thread.start()

        while not event.isSet():
            event.wait(0.1)
            while gtk.events_pending():
                gtk.main_iteration(False)

        self.__load()
        ghlp.change_cursor(None)
Пример #23
0
    def do_realize(self):
        """ Realize the widget """
        self.set_flags(self.flags() | gtk.REALIZED)

        self.window = gdk.Window(self.get_parent_window(),
                                 width=self.allocation.width,
                                 height=self.allocation.height,
                                 window_type=gdk.WINDOW_CHILD,
                                 wclass=gdk.INPUT_OUTPUT,
                                 event_mask=self.get_events()
                                 | gdk.EXPOSURE_MASK
                                 | gdk.BUTTON1_MOTION_MASK
                                 | gdk.BUTTON_PRESS_MASK
                                 | gdk.BUTTON_RELEASE_MASK
                                 | gdk.POINTER_MOTION_MASK
                                 | gdk.POINTER_MOTION_HINT_MASK)

        self.window.set_user_data(self)
        self.style.attach(self.window)
        self.style.set_background(self.window, gtk.STATE_NORMAL)
        self.window.move_resize(*self.allocation)
        self.gc = self.window.new_gc()
        self.color_changed(self.color)

        pbuf = gdk.pixbuf_new_from_file(
            os.path.join(self.icon_path, "dropper.png"))
        if pbuf:
            self.cursor = gdk.Cursor(self.window.get_display(), pbuf, 8, 21)

        self.set_tooltip_text(
            'Click and drag:\n  Left: drag-n-drop color\n\nLeft click: add to palette'
        )

        self.connect("motion-notify-event", self.cb_motion_notify)
        self.connect("button-press-event", self.cb_button_press)
        self.connect("button-release-event", self.cb_button_release)
        self.connect("drag-begin", self.cb_drag_begin)

        self.dnd_helper = ColorDndHelper(self, self.cb_drag_set_color,
                                         self.cb_drag_get_color,
                                         gtk.gdk.BUTTON1_MASK)

        self.raw_width = 1
        self.raw_height = 1
        self.raw_pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8,
                                     self.raw_width, self.raw_height)
Пример #24
0
 def do_button_press_event(self, event):
     if event.button == 1:
         root = gdk.get_default_root_window()
         try:
             desktop = root.property_get("_NET_CURRENT_DESKTOP")[2][0]
             self.__workarea = root.property_get(
                 "_NET_WORKAREA")[2][desktop * 4:(desktop + 1) * 4]
         except:
             self.__workarea = None
         self.__move_begined = True
         toplevel = self.get_toplevel()
         x, y = toplevel.get_position()
         self.__press_pos = event.x_root - x, event.y_root - y
         self.window.set_cursor(gdk.Cursor(gdk.FLEUR))
         self.emit("move-begin")
         return True
     return False
Пример #25
0
 def drag_stop_cb(self):
     """UI and model updates at the end of a drag"""
     # Stop the update idler running on its next scheduling
     self._drag_update_idler_srcid = None
     # This will leave a non-cleaned-up move if one is still active,
     # so finalize it in its own idle routine.
     if self._cmd is not None:
         # Arrange for the background work to be done, and look busy
         tdw = self._drag_tdw
         tdw.set_sensitive(False)
         tdw.set_override_cursor(gdk.Cursor(gdk.WATCH))
         self.final_modifiers = self.current_modifiers()
         gobject.idle_add(self._finalize_move_idler)
     else:
         # Still need cleanup for tracking state, cursors etc.
         self._drag_cleanup()
     return super(LayerMoveMode, self).drag_stop_cb()
Пример #26
0
    def _hide_drawing_cursor(self, tdw):
        """Hide the cursor while painting, if configured to.

        :param tdw: Canvas widget to hide the cursor on.
        :type tdw: gui.tileddrawwindow.TiledDrawWindow

        """
        if tdw in self._cursor_hidden_tdws:
            return
        if not tdw.app:
            return
        if not tdw.app.preferences.get("ui.hide_cursor_while_painting"):
            return
        cursor = self._cursor_hidden
        if not cursor:
            cursor = gdk.Cursor(gdk.CursorType.BLANK_CURSOR)
            self._cursor_hidden = cursor
        tdw.set_override_cursor(cursor)
        self._cursor_hidden_tdws.add(tdw)
Пример #27
0
def get_brush_cursor(radius, style, prefs={}):
    """Returns a gdk.Cursor for use with a brush of a particular size+type.
    """
    global last_cursor, last_cursor_info, max_cursor_size

    display = gtk2compat.gdk.display_get_default()
    if not max_cursor_size:
        max_cursor_size = max(display.get_maximal_cursor_size())
    d = int(radius * 2)
    min_size = max(prefs.get("cursor.freehand.min_size", 4),
                   BRUSH_CURSOR_MIN_SIZE)
    if d < min_size:
        d = min_size
    if d + 1 > max_cursor_size:
        d = max_cursor_size - 1
    cursor_info = (d, style, min_size)
    if cursor_info != last_cursor_info:
        last_cursor_info = cursor_info
        surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, d + 1, d + 1)
        cr = cairo.Context(surf)
        cr.set_source_rgba(1, 1, 1, 0)
        cr.paint()
        draw_brush_cursor(cr, d, style, prefs)
        surf.flush()

        # Calculate hotspot. Zero means topmost or leftmost. Cursors with an
        # even pixel diameter are interesting because they can never be
        # perfectly centred on their hotspot. Rounding down and not up may be
        # more "arrow-cursor" like in this case.
        #
        # NOTE: is it worth adjusting the freehand drawing code to add half a
        # pixel to the position passed on to brushlib for the even case?
        hot_x = hot_y = int(d / 2)

        pixbuf = image_surface_to_pixbuf(surf)
        if gtk2compat.USE_GTK3:
            last_cursor = gdk.Cursor.new_from_pixbuf(display, pixbuf, hot_x,
                                                     hot_y)
        else:
            last_cursor = gdk.Cursor(display, pixbuf, hot_x, hot_y)

    return last_cursor
Пример #28
0
 def wrapper(self, *args, **kwargs):
     toplevels = gtk.Window.list_toplevels()
     toplevels = [t for t in toplevels if t.get_window() is not None]
     for toplevel in toplevels:
         toplevel_win = toplevel.get_window()
         if toplevel_win is not None:
             toplevel_win.set_cursor(gdk.Cursor(gdk.WATCH))
         toplevel.set_sensitive(False)
     self.app.doc.tdw.grab_add()
     try:
         func(self, *args, **kwargs)
         # gtk main loop may be called in here...
     finally:
         for toplevel in toplevels:
             toplevel.set_sensitive(True)
             # ... which is why we need this check:
             toplevel_win = toplevel.get_window()
             if toplevel_win is not None:
                 toplevel_win.set_cursor(None)
         self.app.doc.tdw.grab_remove()
Пример #29
0
    def enter(self):
        mgr = self.app.brush_color_manager
        hist = mgr.get_history()
        if self.selection is None:
            self.selection = len(hist) - 1
            color = mgr.get_color()
            if hist[self.selection] == color:
                self.selection -= 1
        else:
            self.selection = (self.selection - 1) % len(hist)

        mgr.set_color(hist[self.selection])

        # popup placement
        x, y = self.get_position()
        bigcolor_center_x = self.selection * smallcolor_width + bigcolor_width / 2
        self.move(x + self.popup_width / 2 - bigcolor_center_x,
                  y + bigcolor_width)
        self.show_all()

        self.get_window().set_cursor(gdk.Cursor(gdk.CROSSHAIR))
Пример #30
0
    def get_overlay_cursor(self, icon_pixbuf, cursor_name="cursor_arrow"):
        """Returns an overlay cursor. Not cached.

        :param icon_pixbuf: a gdk.Pixbuf containing a small (~22px) image,
           or None
        :param cursor_name: name of a pixmaps/ cursor image to use for the
           pointer part, minus the .png

        The overlay icon will be overlaid to the bottom and right of the
        returned cursor image.

        """

        pointer_pixbuf = getattr(self.app.pixmaps, cursor_name)
        pointer_w = pointer_pixbuf.get_width()
        pointer_h = pointer_pixbuf.get_height()
        hot_x, hot_y = self.CURSOR_HOTSPOTS.get(cursor_name, (None, None))
        if hot_x is None:
            hot_x = 1
            hot_y = 1

        cursor_pixbuf = gtk2compat.GdkPixbufCompat.new(gdk.COLORSPACE_RGB,
                                                       True, 8, 32, 32)
        cursor_pixbuf.fill(0x00000000)

        pointer_pixbuf.composite(cursor_pixbuf, 0, 0, pointer_w, pointer_h, 0,
                                 0, 1, 1, gdk.INTERP_NEAREST, 255)
        if icon_pixbuf is not None:
            icon_w = icon_pixbuf.get_width()
            icon_h = icon_pixbuf.get_height()
            icon_x = 32 - icon_w
            icon_y = 32 - icon_h
            icon_pixbuf.composite(cursor_pixbuf, icon_x, icon_y, icon_w,
                                  icon_h, icon_x, icon_y, 1, 1,
                                  gdk.INTERP_NEAREST, 255)

        display = self.app.drawWindow.get_display()
        cursor = gdk.Cursor(display, cursor_pixbuf, hot_x, hot_y)
        return cursor