Beispiel #1
0
    def pop_cursor(self, cursor):

        try:
            self.__cursor_stack.remove(cursor.upper())
        except:
            pass
        utils.request_call(self.__set_cursor)
    def __on_observe_size(self, src, cmd, *args):

        x, y, w, h = src.get_geometry()
        if (cmd == src.OBS_GEOMETRY and
            (w.as_px(), h.as_px()) != self.__old_size):
            utils.request_call(self.__redraw)
            self.__old_size = (w.as_px(), h.as_px())
Beispiel #3
0
    def __compute_size(self):

        # get image-width, image-height
        imgwidth = self._getp("width")
        imgheight = self._getp("height")
        origwidth, origheight = self.__original_size
        width = imgwidth.as_px()
        height = imgheight.as_px()

        # scale aspect-ratio
        if (imgwidth.is_unset() and imgheight.is_unset()):
            width = origwidth
            height = origheight
        elif (imgwidth.is_unset() and origheight > 0):
            width = height * (origwidth / float(origheight))
        elif (imgheight.is_unset() and origwidth > 0):
            height = (width * origheight) / float(origwidth)

        # apply scale
        scale = self.get_prop("scale")
        # some authors don't pay attention, let's catch it
        if (scale <= 0.0): scale = 1.0
        width = int(width * scale)
        height = int(height * scale)

        # set size
        self.set_size(Unit.Unit(width, Unit.UNIT_PX),
                      Unit.Unit(height, Unit.UNIT_PX))
        utils.request_call(self.__render_image)
Beispiel #4
0
    def _setp_opacity(self, key, value):

        value = min(1.0, max(0.0, value))
        old_opac = self.get_prop("opacity")
        if (abs(value - old_opac) > 0.01):
            self._setp(key, value)
            utils.request_call(self.__render_image)
    def set(self, *args):

        path = ".".join(args[:-1])
        value = args[-1]

        self.__db.set_key(path, value)
        utils.request_call(self.update_observer, self.OBS_UPDATE, path, value)
Beispiel #6
0
    def __on_observe_size(self, src, cmd, *args):

        x, y, w, h = src.get_geometry()
        if (cmd == src.OBS_GEOMETRY and
            (w.as_px(), h.as_px()) != self.__size):
            self.__compute_size()
            utils.request_call(self.__render_image)
            self.__size = (w.as_px(), h.as_px())
Beispiel #7
0
    def __on_observe_children(self, src, cmd):

        def f():
            x, y, w, h = src.get_geometry()
            self.__layout.move(src.get_widget(), x.as_px(), y.as_px())


        if (cmd == src.OBS_GEOMETRY and self.__children):
            utils.request_call(f)
Beispiel #8
0
    def __on_motion(self, src, event, is_leave):

        if (self.__is_dragging): return

        if (is_leave):
            utils.request_call(self.__display.send_event,
                               self.__display.EVENT_LEAVE)
        else:
            utils.request_call(self.__display.send_event,
                               self.__display.EVENT_MOTION, event.x, event.y)
Beispiel #9
0
        def set_menu(menu):

            m = []
            cnt = 0
            for entry in menu[:-1]:
                if (not entry):
                    m.append(MenuItem("/sep%d" % cnt))
                else:
                    callback = entry[3]
                    args = [None] + list(entry[4])
                    m.append(MenuItem("/item%d" % cnt, entry[0], None,
                                      callback, args))
                cnt += 1

            utils.request_call(self.open_menu, m)
Beispiel #10
0
    def set_position(self, x, y, dont_set = False):

        if (self.__window_pos != (x, y) and not self.__is_dragging):
            utils.request_call(self.move, x, y)
            self.__window_pos = (x, y)
            if (not dont_set): self.__display.set_position(x, y)

            bx, by, bw, bh = self.__window_bbox
            if (not self.__managed_mode):
                self.__window_snapper.remove(bx, by, bw, bh)
            w, h = self.__window_size
            if (not self.__managed_mode):
                self.__window_snapper.insert(x, y, w, h)

            self.__window_bbox = (x, y, w, h)
            self.__set_struts()
            gobject.timeout_add(0, self.show)
Beispiel #11
0
    def __on_observe_display(self, src, cmd, *args):

        if (cmd == src.OBS_GEOMETRY):
            x, y, w, h = args
            if (x == UNSET_COORD or y == UNSET_COORD):
                # let the user place the window
                self.__begin_dragging()
            else:
                self.set_position(x, y, True)
                self.set_size(w, h)

        elif (cmd == src.OBS_BORDERS):
            x, y = args[0]
            self.__desktop_borders = (x, y)
            self.__set_struts()

        elif (cmd == src.OBS_FLAGS):
            flags = args[0]
            utils.request_call(self.__set_window_flags, flags)

        elif (cmd == src.OBS_ICON):
            icon = args[0]
            self.set_icon(icon)

        elif (cmd == src.OBS_SHAPE):
            shape = args[0]
            self.__set_shape(shape)

        elif (cmd == src.OBS_TITLE):
            title = args[0]
            self.set_title(title)

        elif (cmd == src.OBS_CURSOR):
            cursor = args[0]
            if (cursor):
                self.__cursor = gtk.gdk.Cursor(_CURSORS.get(cursor))
            else:
                self.__cursor = None

            self.window.set_cursor(self.__cursor)

        elif (cmd == src.OBS_CLOSED):
            wx, wy, w, h = self.__window_bbox
            self.__window_snapper.remove(wx, wy, w, h)
            self.destroy()
    def _setp_relative_to(self, key, value):

        name, mode = value
        if (mode == "x"): rx, ry = True, False
        elif (mode == "y"): rx, ry = False, True
        elif (mode == "xy"): rx, ry = True, True
        else: rx, ry = False, False

        def f():
            try:
                parent = self._get_parent()
                my_id = self._getp("id")

                if (not parent or not parent.get_child_by_id(my_id)):
                    return

                obj = self._get_parent().get_child_by_id(name)

                # if it is not a child of our parent and not the parent itself, something is wrong
                if (not obj and not (parent._getp("id") == name)):
                    raise UserError(_("Element \"%s\" does not exist") % name,
                                   _("The <tt>relative-to</tt> property "
                                     "requires a reference to an existing "
                                     "display element within the same parent "
                                     "container."))

                # FIXME ?! So far 'relative-to' only works for "siblings".
                #          Would a 'relative-to' parents make any sense ?!
                if obj:
                    relative = obj.get_layout_object()
                    self.__layout_object.set_relative_to(relative, rx, ry)
            except:
                import traceback; traceback.print_exc()
                pass

        # we have to delay because the relative might not be available at that
        # time
        utils.request_call(f)

        self._setp(key, value)
    def __geometry_callback(self, src, x, y, w, h):

        self.get_widget().set_size_request(w.as_px(), h.as_px())
        utils.request_call(self.update_observer, self.OBS_GEOMETRY)
Beispiel #14
0
    def push_cursor(self, cursor):

        self.__cursor_stack.append(cursor.upper())
        utils.request_call(self.__set_cursor)
Beispiel #15
0
    def __do_move_window(self):

        x, y = self.__window_pos
        utils.request_call(self.move, x, y)

        return self.__is_dragging
Beispiel #16
0
    def _setp_saturation(self, key, value):

        old_sat = self.get_prop("saturation")
        if (abs(value - old_sat) > 0.01 ):
            self._setp(key, value)
            utils.request_call(self.__render_image)
    def _setp_menu(self, key, value):

        dsp = self._get_display()
        utils.request_call(dsp.open_menu, value)
Beispiel #18
0
 def f():
     utils.request_call(self.__redraw)