trackplacer: paste in the simplescribble demo code...
...so we have basic event capture working.
This commit is contained in:
parent
8c314bc016
commit
be7411fc8b
1 changed files with 89 additions and 1 deletions
|
@ -116,6 +116,52 @@ class ModalFileSelector:
|
|||
def destroy(self, widget):
|
||||
sys.exit(0)
|
||||
|
||||
# Backing pixmap for drawing area
|
||||
pixmap = None
|
||||
|
||||
# Create a new backing pixmap of the appropriate size
|
||||
def configure_event(widget, event):
|
||||
global pixmap
|
||||
|
||||
x, y, width, height = widget.get_allocation()
|
||||
pixmap = gtk.gdk.Pixmap(widget.window, width, height)
|
||||
pixmap.draw_rectangle(widget.get_style().white_gc,
|
||||
True, 0, 0, width, height)
|
||||
|
||||
return True
|
||||
|
||||
# Redraw the screen from the backing pixmap
|
||||
def expose_event(widget, event):
|
||||
x , y, width, height = event.area
|
||||
widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
|
||||
pixmap, x, y, x, y, width, height)
|
||||
return False
|
||||
|
||||
# Draw a rectangle on the screen
|
||||
def draw_brush(widget, x, y):
|
||||
rect = (int(x-5), int(y-5), 10, 10)
|
||||
pixmap.draw_rectangle(widget.get_style().black_gc, True,
|
||||
rect[0], rect[1], rect[2], rect[3])
|
||||
widget.queue_draw_area(rect[0], rect[1], rect[2], rect[3])
|
||||
|
||||
def button_press_event(widget, event):
|
||||
if event.button == 1 and pixmap != None:
|
||||
draw_brush(widget, event.x, event.y)
|
||||
return True
|
||||
|
||||
def motion_notify_event(widget, event):
|
||||
if event.is_hint:
|
||||
x, y, state = event.window.get_pointer()
|
||||
else:
|
||||
x = event.x
|
||||
y = event.y
|
||||
state = event.state
|
||||
|
||||
if state & gtk.gdk.BUTTON1_MASK and pixmap != None:
|
||||
draw_brush(widget, x, y)
|
||||
|
||||
return True
|
||||
|
||||
class TrackEditor:
|
||||
def __init__(self, filename=None, verbose=False):
|
||||
self.verbose = verbose
|
||||
|
@ -142,7 +188,49 @@ class TrackEditor:
|
|||
self.rest_image.set_from_file(rest_icon)
|
||||
except:
|
||||
self.fatal_error("error while reading icons")
|
||||
# FIXME: Set up editing window
|
||||
# FIXME: This is a copy of simplescribble.py from the tutorial.
|
||||
# It will need to be edited to do what we really want.
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
window.set_name ("Test Input")
|
||||
|
||||
vbox = gtk.VBox(False, 0)
|
||||
window.add(vbox)
|
||||
vbox.show()
|
||||
|
||||
window.connect("destroy", lambda w: gtk.main_quit())
|
||||
|
||||
# Create the drawing area
|
||||
drawing_area = gtk.DrawingArea()
|
||||
drawing_area.set_size_request(200, 200)
|
||||
vbox.pack_start(drawing_area, True, True, 0)
|
||||
|
||||
drawing_area.show()
|
||||
|
||||
# Signals used to handle backing pixmap
|
||||
drawing_area.connect("expose_event", expose_event)
|
||||
drawing_area.connect("configure_event", configure_event)
|
||||
|
||||
# Event signals
|
||||
drawing_area.connect("motion_notify_event", motion_notify_event)
|
||||
drawing_area.connect("button_press_event", button_press_event)
|
||||
|
||||
drawing_area.set_events(gtk.gdk.EXPOSURE_MASK
|
||||
| gtk.gdk.LEAVE_NOTIFY_MASK
|
||||
| gtk.gdk.BUTTON_PRESS_MASK
|
||||
| gtk.gdk.POINTER_MOTION_MASK
|
||||
| gtk.gdk.POINTER_MOTION_HINT_MASK)
|
||||
|
||||
# .. And a quit button
|
||||
button = gtk.Button("Quit")
|
||||
vbox.pack_start(button, False, False, 0)
|
||||
|
||||
button.connect_object("clicked", lambda w: w.destroy(), window)
|
||||
button.show()
|
||||
|
||||
window.show()
|
||||
|
||||
gtk.main()
|
||||
|
||||
self.log("initialization successful")
|
||||
|
||||
def log(self, msg):
|
||||
|
|
Loading…
Add table
Reference in a new issue