Debian Codegraph @

fltk/test/menu_label.py

raw symbols SCIP
1 #
2 # "$Id: menu_label.py 536 2020-10-30 15:20:32Z andreasheld $"
3 #
4 # Menu label test program for pyFLTK the Python bindings
5 # for the Fast Light Tool Kit (FLTK).
6 #
7 # FLTK copyright 1998-1999 by Bill Spitzak and others.
8 # pyFLTK copyright 2003 by Andreas Held and others.
9 #
10 # This library is free software you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License, version 2.0 as published by the Free Software Foundation.
13 #
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Library General Public License for more details.
18 #
19 # You should have received a copy of the GNU Library General Public
20 # License along with this library if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 # USA.
23 #
24 # Please report all bugs and problems to "[email protected]".
25 #
26
27
28 from fltk import *
29
30
31 # global object names
32 L_document_xpm=[
33 "13 11 3 1",
34 " c None",
35 "x c #d8d8f8",
36 "@ c #202060",
37 " @@@@@@@@@ ",
38 " @xxxxxxx@ ",
39 " @xxxxxxx@ ",
40 " @xxxxxxx@ ",
41 " @xxxxxxx@ ",
42 " @xxxxxxx@ ",
43 " @xxxxxxx@ ",
44 " @xxxxxxx@ ",
45 " @xxxxxxx@ ",
46 " @xxxxxxx@ ",
47 " @@@@@@@@@ "]
48 L_document_pixmap = Fl_Pixmap(L_document_xpm)
49
50 # Folder icon
51 L_folder_xpm=[
52 "13 11 3 1",
53 " c None",
54 "x c #d8d833",
55 "@ c #808011",
56 " ",
57 " @@@@ ",
58 " @xxxx@ ",
59 "@@@@@xxxx@@ ",
60 "@xxxxxxxxx@ ",
61 "@xxxxxxxxx@ ",
62 "@xxxxxxxxx@ ",
63 "@xxxxxxxxx@ ",
64 "@xxxxxxxxx@ ",
65 "@xxxxxxxxx@ ",
66 "@@@@@@@@@@@ "]
67 L_folder_pixmap = Fl_Pixmap(L_folder_xpm)
68
69 # Red "X"
70 L_redx_xpm=[
71 "13 11 5 1",
72 " c None",
73 "+ c #222222",
74 "x c #555555",
75 "- c #882222",
76 "@ c #ffffff",
77 " x+++x ",
78 " ++---++ ",
79 " ++-----++ ",
80 "++-@@-@@-++ ",
81 "++--@@@--++ ",
82 "++---@---++ ",
83 "++--@@@--++ ",
84 "++-@@-@@-++ ",
85 " ++-----++ ",
86 " ++---++ ",
87 " x+++x "]
88 L_redx_pixmap = Fl_Pixmap(L_redx_xpm)
89
90 # Handle the different menu items..
91 def onMenu(ptr, data):
92 fl_message("'%s' would happen here"%data)
93
94 def onFileQuit(ptr, data):
95 menuItem = ptr
96 print(f'onFileQuit({str(menuItem)}, "{str(data)}")')
97 import sys # code
98 sys.exit(0) # code
99
100 # Add an image in front of item's text
101 def addItemToMenu(menu, # menu to add item to
102 labeltext, # label text
103 shortcut, # shortcut (e.g. FL_COMMAND+'a')
104 cb, # callback to invoke
105 userdata, # userdata for callback
106 pixmap, # image (if any) to add to item
107 flags=0 # menu flags (e.g. FL_MENU_DIVIDER..)
108 ):
109 # Add a new menu item
110 menu.add(labeltext, shortcut, cb, userdata, flags)
111 item = menu.find_item(labeltext)
112 item.add_multi_label(pixmap);
113
114
115
116 def createMenuItems(menu):
117 # Add items with LABELS AND IMAGES using Fl_Multi_Label..
118 addItemToMenu(menu, "File/New", FL_COMMAND | ord('n'), onMenu, "New", L_document_pixmap)
119 addItemToMenu(menu, "File/Open", FL_COMMAND | ord('o'), onMenu, "Open", L_folder_pixmap, FL_MENU_DIVIDER)
120 addItemToMenu(menu, "File/Quit", FL_COMMAND | ord('q'), onFileQuit, "Quit", L_redx_pixmap)
121
122 # Create menu bar items with JUST LABELS
123 menu.add("Edit/Copy", FL_COMMAND | ord('c'), onMenu, "Copy")
124 menu.add("Edit/Paste", FL_COMMAND | ord('v'), onMenu, "Paste")
125
126 menu.add("Images/One", 0, onMenu, "One");
127 item = menu.find_item("Images/One")
128 item.image(L_document_pixmap.copy())
129
130 menu.add("Images/Two", 0, onMenu, "Two")
131 item = menu.find_item("Images/Two")
132 item.image(L_folder_pixmap.copy())
133
134 menu.add("Images/Three", 0, onMenu, "Three")
135 item = menu.find_item("Images/Three")
136 item.image(L_redx_pixmap.copy())
137
138
139 def main():
140
141 win = Fl_Window(0, 0, 400, 400)
142
143 # menu bar
144 mb = Fl_Menu_Bar(0, 0, win.w(), 25)
145 createMenuItems(mb)
146
147 # Right click context menu
148 menubutt = Fl_Menu_Button(0, 25, win.w(), win.h() - 25);
149 createMenuItems(menubutt)
150 menubutt.type(Fl_Menu_Button.POPUP3)
151
152 # Chooser menu
153 choice = Fl_Choice(140, 50, 200, 25, "Choice")
154 createMenuItems(choice)
155 choice.value(1)
156
157 return win
158
159
160
161 if __name__=='__main__':
162 import sys
163 window = main()
164 window.show(len(sys.argv), sys.argv)
165 Fl.run()