diff options
author | John Finlay <finlay@src.gnome.org> | 2004-08-20 05:41:33 +0000 |
---|---|---|
committer | John Finlay <finlay@src.gnome.org> | 2004-08-20 05:41:33 +0000 |
commit | 1c3493a2e1d4a26d7d3a7a404ea4f3a858dd6cec (patch) | |
tree | 4cab7d1cc953fec2ac1028c7fe7822ecc47d44a0 /examples/simple | |
parent | 029f46fb5893d7fd7a27da8c68ea384437693e04 (diff) | |
download | pygtk-1c3493a2e1d4a26d7d3a7a404ea4f3a858dd6cec.tar.gz |
examples/simple/dnd.py examples/simple.scribble.py Update.
* examples/simple/dnd.py
* examples/simple.scribble.py Update.
Diffstat (limited to 'examples/simple')
-rw-r--r-- | examples/simple/dnd.py | 276 | ||||
-rwxr-xr-x | examples/simple/scribble.py | 4 |
2 files changed, 142 insertions, 138 deletions
diff --git a/examples/simple/dnd.py b/examples/simple/dnd.py index 5481fa9b..6621a87d 100644 --- a/examples/simple/dnd.py +++ b/examples/simple/dnd.py @@ -1,17 +1,16 @@ #! /usr/bin/env python -from gtk import * -from GDK import * +import pygtk +pygtk.require('2.0') +import gtk, gobject from dndpixmap import * trashcan_open = None -trashcan_open_mask = None trashcan_closed = None -trashcan_closed_mask = None -have_drag = FALSE; -popped_up = FALSE -in_popup = FALSE +have_drag = False; +popped_up = False +in_popup = False popup_timer = 0 popdown_timer = 0 popup_win = None @@ -26,151 +25,156 @@ target = [ ('application/x-rootwin-drop', 0, TARGET_ROOTWIN)] def target_drag_leave(w, context, time): - global trashcan_closed, trashcan_closed_mask - global have_drag - print 'leave' - have_drag = FALSE - w.set(trashcan_closed, trashcan_closed_mask) + global trashcan_closed + global have_drag + print 'leave' + have_drag = False + w.set_from_pixbuf(trashcan_closed) def target_drag_motion(w, context, x, y, time): - global trashcan_open, trashcan_open_mask - global have_drag - if not have_drag: - have_drag = TRUE - w.set(trashcan_open, trashcan_open_mask) - source_widget = w.drag_get_source_widget(context) - print 'motion, source ', - if source_widget: - print source_widget.__class__.__name__ - else: - print 'unknown' - w.drag_status(context, context.suggested_action, time) - return TRUE + global trashcan_open + global have_drag + if not have_drag: + have_drag = True + w.set_from_pixbuf(trashcan_open) + source_widget = context.get_source_widget() + print 'motion, source ', + if source_widget: + print source_widget.__class__.__name__ + else: + print 'unknown' + context.drag_status(context.suggested_action, time) + return True def target_drag_drop(w, context, x, y, time): - global trashcan_closed, trashcan_closed_mask - global have_drag - print 'drop' - have_drag = FALSE - w.set(trashcan_closed, trashcan_closed_mask) - if context.targets: - w.drag_get_data(context, context.targets[0], time) - return TRUE - return FALSE + global trashcan_closed + global have_drag + print 'drop' + have_drag = False + w.set_from_pixbuf(trashcan_closed) + if context.targets: + w.drag_get_data(context, context.targets[0], time) + return True + return False def target_drag_data_received(w, context, x, y, data, info, time): - if data.format == 8: - print 'Received "%s" in trashcan' % data.data - w.drag_finish(context, TRUE, FALSE, time) - else: - w.drag_finish(context, FALSE, FALSE, time) + if data.format == 8: + print 'Received "%s" in trashcan' % data.data + context.finish(True, False, time) + else: + context.finish(False, False, time) def label_drag_data_received(w, context, x, y, data, info, time): - if data and data.format == 8: - print 'Received "%s" in label' % data.data - w.drag_finish(context, TRUE, FALSE, time) - else: - w.drag_finish(context, FALSE, FALSE, time) + if data and data.format == 8: + print 'Received "%s" in label' % data.data + context.finish(True, False, time) + else: + context.finish(False, False, time) def source_drag_data_get(w, context, selection_data, info, time): - if info == TARGET_ROOTWIN: - print 'I was dropped on the rootwin' - else: - selection_data.set(selection_data.target, 8, "I'm Data!") + if info == TARGET_ROOTWIN: + print 'I was dropped on the rootwin' + else: + selection_data.set(selection_data.target, 8, "I'm Data!") def popdown_cb(): - global popdown_timer, popped_up - global popup_win - popdown_timer = 0 - popup_win.hide() - popped_up = FALSE - return FALSE + global popdown_timer, popped_up + global popup_win + popdown_timer = 0 + popup_win.hide() + popped_up = False + return False def popup_motion(w, context, x, y, time): - global in_popup, popdown_timer - if not in_popup: - in_popup = TRUE - if popdown_timer: - print 'removed popdown' - timeout_remove(popdown_timer) - popdown_timer = 0 - return TRUE + global in_popup, popdown_timer + if not in_popup: + in_popup = True + if popdown_timer: + print 'removed popdown' + gobject.source_remove(popdown_timer) + popdown_timer = 0 + return True def popup_leave(w, context, time): - global in_popup, popdown_timer - print 'popup_leave' - if in_popup: - in_popup = FALSE - if not popdown_timer: - print 'added popdown' - popdown_timer = timeout_add(500, popdown_cb) + global in_popup, popdown_timer + print 'popup_leave' + if in_popup: + in_popup = False + if not popdown_timer: + print 'added popdown' + popdown_timer = gobject.timeout_add(500, popdown_cb) def popup_cb(): - global popped_up, popup_win - global popup_timer, popdown_timer - if not popped_up: - if not popup_win: - popup_win = GtkWindow(WINDOW_POPUP) - popup_win.set_position(WIN_POS_MOUSE) - table = GtkTable(3,3,FALSE) - for k in range(9): - i, j = divmod(k, 3) - b = GtkButton("%d,%d" % (i,j)) - table.attach(b, i,i+1,j,j+1) - b.drag_dest_set(DEST_DEFAULT_ALL, target, - ACTION_COPY | ACTION_MOVE) - b.connect('drag_motion', popup_motion) - b.connect('drag_leave', popup_leave) - table.show_all() - popup_win.add(table) - popup_win.show() - popped_up = TRUE - popdown_timer = timeout_add(500, popdown_cb) - print 'added popdown' - popup_timer = 0 - return FALSE + global popped_up, popup_win + global popup_timer, popdown_timer + if not popped_up: + if not popup_win: + popup_win = gtk.Window(gtk.WINDOW_POPUP) + popup_win.set_position(gtk.WIN_POS_MOUSE) + table = gtk.Table(3,3,False) + for k in range(9): + i, j = divmod(k, 3) + b = gtk.Button("%d,%d" % (i,j)) + table.attach(b, i,i+1,j,j+1) + b.drag_dest_set(gtk.DEST_DEFAULT_ALL, target, + gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE) + b.connect('drag_motion', popup_motion) + b.connect('drag_leave', popup_leave) + table.show_all() + popup_win.add(table) + popup_win.show() + popped_up = True + popdown_timer = gobject.timeout_add(500, popdown_cb) + print 'added popdown' + popup_timer = 0 + return False def popsite_motion(w, context, x, y, time): - global popup_timer - if not popup_timer: - popup_timer = timeout_add(500, popup_cb) - return TRUE + global popup_timer + if not popup_timer: + popup_timer = gobject.timeout_add(500, popup_cb) + return True def popsite_leave(w, context, time): - global popup_timer - if popup_timer: - timeout_remove(popup_timer) - popup_timer = 0 + global popup_timer + if popup_timer: + gobject.source_remove(popup_timer) + popup_timer = 0 def source_drag_data_delete(w, context, data): - print 'Delete the data!' + print 'Delete the data!' def create_pixmap(w, xpm): - return create_pixmap_from_xpm_d(w, None, xpm) + return gtk.gdk.pixmap_create_from_xpm_d(w.window, None, xpm) def main(): - global trashcan_open, trashcan_open_mask - global trashcan_closed, trashcan_closed_mask - global drag_icon, drag_mask - win = GtkWindow() - win.connect('destroy', mainquit) - table = GtkTable(2,2) - win.add(table) - drag_icon, drag_mask = create_pixmap(win, drag_icon_xpm) - trashcan_open, trashcan_open_mask = create_pixmap(win, trashcan_open_xpm) - trashcan_closed, trashcan_closed_mask = create_pixmap(win, trashcan_closed_xpm) - label = GtkLabel('Drop Here!\n') - label.drag_dest_set(DEST_DEFAULT_ALL, target[:-1], ACTION_COPY | ACTION_MOVE) - label.connect('drag_data_received', label_drag_data_received) - table.attach(label, 0, 1, 0, 1) + global trashcan_open + global trashcan_closed + global drag_icon + win = gtk.Window() + win.realize() + win.connect('destroy', lambda w: gtk.main_quit()) + table = gtk.Table(2,2) + win.add(table) + drag_icon = gtk.gdk.pixbuf_new_from_xpm_data(drag_icon_xpm) + trashcan_open = gtk.gdk.pixbuf_new_from_xpm_data(trashcan_open_xpm) + trashcan_closed = gtk.gdk.pixbuf_new_from_xpm_data(trashcan_closed_xpm) + label = gtk.Label('Drop Here!\n') + label.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1], + gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE) + label.connect('drag_data_received', label_drag_data_received) + table.attach(label, 0, 1, 0, 1) - label = GtkLabel('Popup\n') - label.drag_dest_set(DEST_DEFAULT_ALL, target[:-1], ACTION_COPY | ACTION_MOVE) - table.attach(label, 1, 2, 1, 2) - label.connect('drag_motion', popsite_motion) - label.connect('drag_leave', popsite_leave) + label = gtk.Label('Popup\n') + label.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1], + gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE) + table.attach(label, 1, 2, 1, 2) + label.connect('drag_motion', popsite_motion) + label.connect('drag_leave', popsite_leave) - pixmap = GtkPixmap(trashcan_closed, trashcan_closed_mask) - pixmap.drag_dest_set(0, [], 0) - table.attach(pixmap, 1, 2, 0, 1) - pixmap.connect('drag_leave', target_drag_leave) - pixmap.connect('drag_motion', target_drag_motion) - pixmap.connect('drag_drop', target_drag_drop) - pixmap.connect('drag_data_received', target_drag_data_received) + image = gtk.Image() + image.set_from_pixbuf(trashcan_closed) + image.drag_dest_set(0, [], 0) + table.attach(image, 1, 2, 0, 1) + image.connect('drag_leave', target_drag_leave) + image.connect('drag_motion', target_drag_motion) + image.connect('drag_drop', target_drag_drop) + image.connect('drag_data_received', target_drag_data_received) - b = GtkButton('Drag Here\n') - b.drag_source_set(BUTTON1_MASK|BUTTON3_MASK, target, ACTION_COPY|ACTION_MOVE) - b.drag_source_set_icon(win.get_colormap(), drag_icon, drag_mask) - table.attach(b, 0, 1, 1, 2) - b.connect('drag_data_get', source_drag_data_get) - b.connect('drag_data_delete', source_drag_data_delete) - win.show_all() + b = gtk.Button('Drag Here\n') + b.drag_source_set(gtk.gdk.BUTTON1_MASK|gtk.gdk.BUTTON3_MASK, target, + gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE) + b.drag_source_set_icon_pixbuf(drag_icon) + table.attach(b, 0, 1, 1, 2) + b.connect('drag_data_get', source_drag_data_get) + b.connect('drag_data_delete', source_drag_data_delete) + win.show_all() main() -mainloop() +gtk.main() diff --git a/examples/simple/scribble.py b/examples/simple/scribble.py index 7e2331bb..23cb48fc 100755 --- a/examples/simple/scribble.py +++ b/examples/simple/scribble.py @@ -24,7 +24,7 @@ def expose_event(widget, event): return gtk.FALSE def draw_brush(widget, x, y): - rect = (x-5, y-5, 10, 10) + x, y = int(x), int(y) pixmap.draw_rectangle(widget.get_style().black_gc, gtk.TRUE, x-5, y-5, 10, 10) widget.queue_draw() @@ -47,7 +47,7 @@ def motion_notify_event(widget, event): def main(): win = gtk.Window() win.set_name("Test Input") - win.connect("destroy", gtk.mainquit) + win.connect("destroy", lambda w: gtk.main_quit()) win.set_border_width(5) vbox = gtk.VBox(spacing=3) |