diff options
author | James Henstridge <james@daa.com.au> | 1999-02-02 15:26:53 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 1999-02-02 15:26:53 +0000 |
commit | 4f0384643c42af7399c6a3755947fd37c88e07b5 (patch) | |
tree | e2a8498aaab3c60765f31ca6591bf9af098c21d1 /examples | |
parent | 2f41cb630fbf3d2fa4c230ad079b16fd754f8a06 (diff) | |
download | pygtk-4f0384643c42af7399c6a3755947fd37c88e07b5.tar.gz |
added GtkCList.focus_row.
1999-02-02 James Henstridge <james@daa.com.au>
* generate/gtklists.defs, gtk.py: added GtkCList.focus_row.
* _gdkimlibmodule.c, GdkImlib.py: added push_visual and pop_visual,
that can be used to easily set GTK to use the imlib visual/colormap
combination.
* gtkmodule.c: the PyObject -> GtkArg conversion routines were not
catching some exceptions that they generated. This would cause
wierd problems if you passed the wrong argument types to signal
handlers. This was found by Chi-Deok Hwang <cdhwang@sr.hei.co.kr>
* examples/simple/dnd.py, examples/simple/dndpixmaps.py: and example
of drag and drop contributed by Chi-Deok Hwang <cdhwang@sr.hei.co.kr>
* gtkmodule.c: added gtk_ctree_get_selection, that returns nodes
rather than pointers.
* gtk.py: made changes to reflect those below. Also added
GtkWidget.get_colormap() (it was missing previously).
* generate/gtkedit.defs (gtk_spin_button_update): added function.
* generate/gtkmenus.defs (gtk_check_menu_item_set_active): function
renaming.
(gtk_menu_set_title): added function.
* generate/gtkmisc.defs (gtk_toggle_button_[sg]et_active): added
functions, and removed gtk_toggle_button_set_state.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/simple/dnd.py | 229 | ||||
-rw-r--r-- | examples/simple/dndpixmap.py | 260 |
2 files changed, 424 insertions, 65 deletions
diff --git a/examples/simple/dnd.py b/examples/simple/dnd.py index 91e2a6b0..5481fa9b 100644 --- a/examples/simple/dnd.py +++ b/examples/simple/dnd.py @@ -1,77 +1,176 @@ -#!/usr/bin/env python -from gtk import * - -# a nice easy to read fixed spacing font. -font = load_font("-*-lucidatypewriter-medium-r-*-*-14-*-*-*-*-*-*-*") - -list = "abcdefghijklmnopqrstuvwxyz" + \ - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + \ - "0123456789" + \ - "`~!@#$%^&*()-_=+\|[]{};:'\",.<>/? " -printable = '' -for c in map(chr, range(256)): - if c in list: - printable = printable + c - else: - printable = printable + '.' -del list, c - -def format_line(str): - hexstr = reduce(lambda x, a: x + hex(256+ord(a))[-2:] + ' ', str, '') - if len(hexstr) < 48: - hexstr = (hexstr + ' '*48)[:48] - return hexstr + ' ' + reduce(lambda x, a: x + printable[ord(a)],str,'') +#! /usr/bin/env python -def format_data(str): - ret = '' - while len(str) > 16: - line = str[:16] - str = str[16:] - ret = ret + format_line(line) + '\n' - if str: ret = ret + format_line(str) - return ret +from gtk import * +from GDK import * +from dndpixmap import * -def dnd_drop(b, event): - data_type.set_text(event.data_type) - data.delete_text(0, data.get_length()) - data.insert(font, black, white, format_data(event.data)) - pass +trashcan_open = None +trashcan_open_mask = None +trashcan_closed = None +trashcan_closed_mask = None -win = GtkWindow() -win.set_title("Drag to Me") -win.border_width(10) +have_drag = FALSE; +popped_up = FALSE +in_popup = FALSE +popup_timer = 0 +popdown_timer = 0 +popup_win = None -t = GtkTable(5,4) -win.add(t) -t.show() -l = GtkLabel("Data Type") -l.set_justify(JUSTIFY_RIGHT) -t.attach(l, 0,1, 0,1, xoptions=FILL) -l.show() +TARGET_STRING = 0 +TARGET_ROOTWIN = 1 -data_type = GtkLabel("*None*") -data_type.set_justify(JUSTIFY_LEFT) -t.attach(data_type, 1,2, 0,1) -data_type.show() +target = [ +('STRING', 0, TARGET_STRING), +('text/plain', 0, TARGET_STRING), +('application/x-rootwin-drop', 0, TARGET_ROOTWIN)] -l = GtkLabel("Data") -l.set_justify(JUSTIFY_RIGHT) -t.attach(l, 0,1, 1,2, xoptions=FILL) -l.show() +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) +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 +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 +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) +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) +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!") -data = GtkText() -data.set_usize(600, -1) -style = data.get_style() -white = style.white -black = style.black -t.attach(data, 1,2, 1,2) -data.show() +def popdown_cb(): + 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 +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) +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 +def popsite_motion(w, context, x, y, time): + global popup_timer + if not popup_timer: + popup_timer = 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 +def source_drag_data_delete(w, context, data): + print 'Delete the data!' +def create_pixmap(w, xpm): + return create_pixmap_from_xpm_d(w, 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) -win.connect("drop_data_available_event", dnd_drop) -win.dnd_drop_set(TRUE, ['text/plain', 'application/x-color', 'ALL'], FALSE) + 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) -win.connect("destroy", mainquit) -win.show() + 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) + 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() +main() mainloop() diff --git a/examples/simple/dndpixmap.py b/examples/simple/dndpixmap.py new file mode 100644 index 00000000..8912365a --- /dev/null +++ b/examples/simple/dndpixmap.py @@ -0,0 +1,260 @@ +drag_icon_xpm = [ +"36 48 9 1", +" c None", +". c #020204", +"+ c #8F8F90", +"@ c #D3D3D2", +"# c #AEAEAC", +"$ c #ECECEC", +"% c #A2A2A4", +"& c #FEFEFC", +"* c #BEBEBC", +" .....................", +" ..&&&&&&&&&&&&&&&&&&&.", +" ...&&&&&&&&&&&&&&&&&&&.", +" ..&.&&&&&&&&&&&&&&&&&&&.", +" ..&&.&&&&&&&&&&&&&&&&&&&.", +" ..&&&.&&&&&&&&&&&&&&&&&&&.", +" ..&&&&.&&&&&&&&&&&&&&&&&&&.", +" ..&&&&&.&&&@&&&&&&&&&&&&&&&.", +" ..&&&&&&.*$%$+$&&&&&&&&&&&&&.", +" ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.", +" ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.", +" ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.", +" ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.", +" ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.", +" ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.", +"................&$@&&&@&&&&&&&&&&&&.", +".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&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&&.", +".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", +".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", +".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", +"...................................."] + +trashcan_closed_xpm = [ +"64 80 17 1", +" c None", +". c #030304", +"+ c #5A5A5C", +"@ c #323231", +"# c #888888", +"$ c #1E1E1F", +"% c #767677", +"& c #494949", +"* c #9E9E9C", +"= c #111111", +"- c #3C3C3D", +"; c #6B6B6B", +"> c #949494", +", c #282828", +"' c #808080", +") c #545454", +"! c #AEAEAC", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ==......=$$...=== ", +" ..$------)+++++++++++++@$$... ", +" ..=@@-------&+++++++++++++++++++-.... ", +" =.$$@@@-&&)++++)-,$$$$=@@&+++++++++++++,..$ ", +" .$$$$@@&+++++++&$$$@@@@-&,$,-++++++++++;;;&.. ", +" $$$$,@--&++++++&$$)++++++++-,$&++++++;%%'%%;;$@ ", +" .-@@-@-&++++++++-@++++++++++++,-++++++;''%;;;%*-$ ", +" +------++++++++++++++++++++++++++++++;;%%%;;##*!. ", +" =+----+++++++++++++++++++++++;;;;;;;;;;;;%'>>). ", +" .=)&+++++++++++++++++;;;;;;;;;;;;;;%''>>#>#@. ", +" =..=&++++++++++++;;;;;;;;;;;;;%###>>###+%== ", +" .&....=-+++++%;;####''''''''''##'%%%)..#. ", +" .+-++@....=,+%#####'%%%%%%%%%;@$-@-@*++!. ", +" .+-++-+++-&-@$$=$=......$,,,@;&)+!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" =+-++-+++-+++++++++!++++!++++!+++!++!+++= ", +" $.++-+++-+++++++++!++++!++++!+++!++!+.$ ", +" =.++++++++++++++!++++!++++!+++!++.= ", +" $..+++++++++++++++!++++++...$ ", +" $$=.............=$$ ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "] + +trashcan_open_xpm = [ +"64 80 17 1", +" c None", +". c #030304", +"+ c #5A5A5C", +"@ c #323231", +"# c #888888", +"$ c #1E1E1F", +"% c #767677", +"& c #494949", +"* c #9E9E9C", +"= c #111111", +"- c #3C3C3D", +"; c #6B6B6B", +"> c #949494", +", c #282828", +"' c #808080", +") c #545454", +"! c #AEAEAC", +" ", +" ", +" ", +" ", +" ", +" ", +" .=.==.,@ ", +" ==.,@-&&&)-= ", +" .$@,&++;;;%>*- ", +" $,-+)+++%%;;'#+. ", +" =---+++++;%%%;%##@. ", +" @)++++++++;%%%%'#%$ ", +" $&++++++++++;%%;%##@= ", +" ,-++++)+++++++;;;'#%) ", +" @+++&&--&)++++;;%'#'-. ", +" ,&++-@@,,,,-)++;;;'>'+, ", +" =-++&@$@&&&&-&+;;;%##%+@ ", +" =,)+)-,@@&+++++;;;;%##%&@ ", +" @--&&,,@&)++++++;;;;'#)@ ", +" ---&)-,@)+++++++;;;%''+, ", +" $--&)+&$-+++++++;;;%%'';- ", +" .,-&+++-$&++++++;;;%''%&= ", +" $,-&)++)-@++++++;;%''%), ", +" =,@&)++++&&+++++;%'''+$@&++++++ ", +" .$@-++++++++++++;'#';,........=$@&++++ ", +" =$@@&)+++++++++++'##-.................=&++ ", +" .$$@-&)+++++++++;%#+$.....................=)+ ", +" $$,@-)+++++++++;%;@=........................,+ ", +" .$$@@-++++++++)-)@=............................ ", +" $,@---)++++&)@===............................,. ", +" $-@---&)))-$$=..............................=)!. ", +" --&-&&,,$=,==...........................=&+++!. ", +" =,=$..=$+)+++++&@$=.............=$@&+++++!++!. ", +" .)-++-+++++++++++++++++++++++++++!++!++!. ", +" .+-++-+++++++++++++++++++++++!+++!++!++!. ", +" .+-++-+++-+++++++++!+++!!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", +" =+-++-+++-+++++++++!++++!++++!+++!++!+++= ", +" $.++-+++-+++++++++!++++!++++!+++!++!+.$ ", +" =.++++++++++++++!++++!++++!+++!++.= ", +" $..+++++++++++++++!++++++...$ ", +" $$==...........==$$ ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "] + |