theme_creator.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:XFWM_theme_creator 作者: Sjc1000 项目源码 文件源码
def press(self, widget, event):
        """press
        Called when the user presses a mouse button.
        Left click: Paint the currently active foreground color.
        Right Click: Remove the pixel under the mouse.
        Middle Click: Fill with the active foreground color.
        """
        if self.image is None:
            return None
        main_window = self.get_toplevel()
        var_name = main_window.var_list.active
        image_width = len(self.image[0])
        image_height = len(self.image)
        x = math.floor((event.x)/self.scale)
        y = math.floor((event.y)/self.scale)
        if x+1 > image_width or y+1 > image_height or x < 0 or y < 0:
            return None

        if event.button == 2:
            r, g, b, a = main_window.paint_color.get_rgba()
            color = [Gdk.RGBA(r, g, b), var_name]
            original = self.image[y][x]
            for yi, y in enumerate(self.image):
                for xi, x in enumerate(y):
                    if str(self.image[yi][xi]) != str(original):
                        continue
                    self.image[yi][xi] = color
            self.view.queue_draw()
            return None

        elif event.button == 1 and self.get_color:
            color = self.image[y][x]
            main_window.var_list.active = None
            main_window.paint_color.set_rgba(color[0])
            for index, item in enumerate(main_window.var_list.list):
                path = Gtk.TreePath().new_from_string(str(index))
                if item[0] == color[1]:
                    item[1] = True
                    main_window.var_list.active = item[0]
                else:
                    item[1] = False

            return None
        if event.button == 1:
            color = main_window.paint_color.get_rgba()
        elif event.button == 3:
            color = None

        if self.last is not None and self.square:
            lx, ly = self.last
            for xi in range(image_width):
                for yi in range(image_height):
                    if ((x > lx and lx <= xi <= x or x < lx and lx >= xi >= x)
                            and (y > ly and ly <= yi <= y or y < ly
                            and ly >= yi >= y)):
                        self.image[yi][xi] = [color, var_name]
        else:
            self.image[y][x] = [color, var_name]
            self.last = [x, y]
        self.view.queue_draw()
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号