我正在尝试使用PyGObject和python 3编写简单的图形编辑器.我需要使用鼠标绘制不同颜色和宽度的线条.我找到了许多像这样的例子,但没有更复杂.
如何在"绘制"事件之间保存绘制的图像?是否有增量绘图方式或是否必须在每个'draw'事件上重绘窗格?我发现我可以保存路径但是如何保存绘制线条的宽度和颜色?有没有办法在'draw'回调之外创建图像并且只在回调中应用(绘制)它?
这就是我现在所拥有的.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gtk, Gdk
import os
class App(object):
main_ui = os.path.join(os.path.dirname(__file__), 'gui.glade')
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(self.main_ui)
self.main_window.connect('destroy', self.quit)
self.mw_quit_button.connect('clicked', self.quit)
self.mw_graph_editor_button.connect('clicked', self.show_window, self.graph_editor_window)
self.graph_editor_window.connect('delete-event', self.hide_window_delete)
self.ge_menubar_file_quit.connect('activate', self.hide_window, self.graph_editor_window)
self.ge_toolbar_quit.connect('clicked', self.hide_window, self.graph_editor_window)
self.ge_drawingarea.connect('motion-notify-event', self.pointer_motion)
self.ge_drawingarea.connect('motion-notify-event', self.show_coordinates)
self.ge_drawingarea.connect('draw', self.draw_callback)
self.path = None
self.coord = (0, 0)
self.rgb = (0, 0, 0)
def __getattr__(self, name):
obj = self.builder.get_object(name)
if not obj:
raise AttributeError("Object {0} has no …Run Code Online (Sandbox Code Playgroud)