1# 2# "$Id: menubar.py 495 2013-03-30 09:39:45Z andreasheld $" 3# 4# Menubar 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 as published by the Free Software Foundation either 13# version 2 of the License, or (at your option) any later version. 14# 15# This library is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18# Library General Public License for more details. 19# 20# You should have received a copy of the GNU Library General Public 21# License along with this library if not, write to the Free Software 22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 23# USA. 24# 25# Please report all bugs and problems to "pyfltk-user@lists.sourceforge.net". 26# 27 28from fltk import * 29import sys 30 31hugemenu = [] 32 33def window_cb(win): 34 print("window callback called!") 35 win.hide() 36 37def test_cb(menu): 38 m = menu.mvalue() 39 if (not m): 40 print("menu.mvalue()=NULL") 41 else: 42 if (m.shortcut()): 43 print("%s - %s" % ( m.label(), fl_shortcut_label(m.shortcut()) )) 44 else: 45 print(m.label()) 46 47def quit_cb(ptr, data): 48 sys.exit(0) 49 50# hack alert: 51# nm - create Fl_Menu_Item from initializer list 52def nm(list): 53 m = Fl_Menu_Item() 54 try: 55 if not list[0]: 56 m.text = Null 57 else: 58 m.text = list[0] 59 m.shortcut_ = list[1] 60 m.callback_ = list[2] 61 m.user_data = list[3] 62 m.flags = list[4] 63 except: 64 pass 65 return m 66 67 68pulldown = [] 69pulldown.append(nm(("Red", FL_ALT+ord('r')))) 70pulldown.append(nm(("Green", FL_ALT+ord('g')))) 71pulldown.append(nm(("Blue", FL_ALT+ord('b')))) 72pulldown.append(nm(("Strange", FL_ALT+ord('s')))) 73pulldown.append(nm(("&Charm", FL_ALT+ord('c')))) 74pulldown.append(nm(("Truth", FL_ALT+ord('t')))) 75pulldown.append(nm(("Beauty", FL_ALT+ord('b')))) 76pulldown.append(nm((0,))) 77 78 79 80WIDTH=600 81 82menus = [0,0,0,0] 83 84# turn MicroSoft style on/off 85def button_cb(btn): 86 if (btn.value() == 0): 87 for i in range(4): 88 menus[i].down_box(FL_FLAT_BOX) 89 menus[i].selection_color(137) 90 menus[i].textfont(FL_HELVETICA) 91 else: 92 for i in range(4): 93 menus[i].down_box(FL_NO_BOX) 94 menus[i].selection_color(FL_WHITE) 95 menus[i].textfont(FL_BOLD|FL_ITALIC) 96 menus[0].parent().redraw() 97 98for i in range(0, 99, 1): 99 hugemenu.append( nm("item %d"%i) ) 100 101window = Fl_Window(0,0, WIDTH, 400) 102 103menubar = Fl_Menu_Bar(0,0,WIDTH,30) 104 105 106pulldown= ( ("Red", FL_ALT+ord('r')), 107 ("Green", FL_ALT+ord('g')), 108 ("Blue", FL_ALT+ord('b')), 109 ("Strange",FL_ALT+ord('s')), 110 ("&Charm", FL_ALT+ord('c')), 111 ("Truth", FL_ALT+ord('t')), 112 ("Beauty", FL_ALT+ord('b')), 113 (None,)) 114 115menutable = ( ("foo",0,0,0,FL_MENU_INACTIVE), 116 ("&File",0,0,0,FL_SUBMENU), 117 ("&Open", FL_ALT+ord('o'), 0, 0, FL_MENU_INACTIVE), 118 ("&Close", 0, 0), 119 ("&Quit", FL_ALT+ord('q'), quit_cb, 0, FL_MENU_DIVIDER), 120 ("shortcut",ord('a')), 121 ("shortcut",FL_SHIFT+ord('a')), 122 ("shortcut",FL_CTRL+ord('a')), 123 ("shortcut",FL_CTRL+FL_SHIFT+ord('a')), 124 ("shortcut",FL_ALT+ord('a')), 125 ("shortcut",FL_ALT+FL_SHIFT+ord('a')), 126 ("shortcut",FL_ALT+FL_CTRL+ord('a')), 127 ("shortcut",FL_ALT+FL_SHIFT+FL_CTRL+ord('a'), 0,0, FL_MENU_DIVIDER), 128 ("shortcut",ord('\r')), 129 ("shortcut",FL_CTRL+FL_Enter, 0,0, FL_MENU_DIVIDER), 130 ("shortcut",FL_F+1), 131 ("shortcut",FL_SHIFT+FL_F+1), 132 ("shortcut",FL_CTRL+FL_F+1), 133 ("shortcut",FL_SHIFT+FL_CTRL+FL_F+1), 134 ("shortcut",FL_ALT+FL_F+1), 135 ("shortcut",FL_ALT+FL_SHIFT+FL_F+1), 136 ("shortcut",FL_ALT+FL_CTRL+FL_F+1), 137 ("shortcut",FL_ALT+FL_SHIFT+FL_CTRL+FL_F+1, 0,0, FL_MENU_DIVIDER), 138 ("&Submenus", FL_ALT+ord('S'), 0, "Submenu1", FL_SUBMENU), 139 ("A very long menu item", 0), 140 ("&submenu",FL_CTRL+ord('S'), 0, "submenu2", FL_SUBMENU), 141 ("item 1", 0), 142 ("item 2", 0), 143 ("item 3", 0), 144 ("item 4", 0), 145 (None, 0), 146 ("after submenu", 0), 147 (None, 0), 148 (None, 0), 149 ("&Edit",0,0,0,FL_SUBMENU), 150 ("Undo", FL_ALT+ord('z'), 0), 151 ("Redo", FL_ALT+ord('r'), 0, 0, FL_MENU_DIVIDER), 152 ("Cut", FL_ALT+ord('x'), 0), 153 ("Copy", FL_ALT+ord('c'), 0), 154 ("Paste", FL_ALT+ord('v'), 0), 155 ("Inactive",FL_ALT+ord('d'), 0, 0, FL_MENU_INACTIVE), 156 ("Clear", 0, 0, 0, FL_MENU_DIVIDER), 157 ("Invisible",FL_ALT+ord('e'), 0, 0, FL_MENU_INVISIBLE), 158 ("Preferences",0, 0), 159 ("Size", 0, 0), 160 (None, 0), 161 ("&Checkbox",0,0,0,FL_SUBMENU), 162 ("&Alpha", FL_F+2, 0, 1, FL_MENU_TOGGLE), 163 ("&Beta", 0, 0, 2, FL_MENU_TOGGLE), 164 ("&Gamma", 0, 0, 3, FL_MENU_TOGGLE), 165 ("&Delta", 0, 0, 4, FL_MENU_TOGGLE|FL_MENU_VALUE), 166 ("&Epsilon",0, 0, 5, FL_MENU_TOGGLE), 167 ("&Pi", 0, 0, 6, FL_MENU_TOGGLE), 168 ("&Mu", 0, 0, 7, FL_MENU_TOGGLE|FL_MENU_DIVIDER), 169 ("Red", 0, 0, 1, FL_MENU_TOGGLE, 0, 0, 0, 1), 170 ("Black", 0, 0, 1, FL_MENU_TOGGLE|FL_MENU_DIVIDER), 171 ("00", 0, 0, 1, FL_MENU_TOGGLE), 172 ("000", 0, 0, 1, FL_MENU_TOGGLE), 173 (None, 0), 174 ("&Radio",0,0,0,FL_SUBMENU), 175 ("&Alpha", 0, 0, 1, FL_MENU_RADIO), 176 ("&Beta", 0, 0, 2, FL_MENU_RADIO), 177 ("&Gamma", 0, 0, 3, FL_MENU_RADIO), 178 ("&Delta", 0, 0, 4, FL_MENU_RADIO|FL_MENU_VALUE), 179 ("&Epsilon",0, 0, 5, FL_MENU_RADIO), 180 ("&Pi", 0, 0, 6, FL_MENU_RADIO), 181 ("&Mu", 0, 0, 7, FL_MENU_RADIO|FL_MENU_DIVIDER), 182 ("Red", 0, 0, 1, FL_MENU_RADIO), 183 ("Black", 0, 0, 1, FL_MENU_RADIO|FL_MENU_DIVIDER), 184 ("00", 0, 0, 1, FL_MENU_RADIO), 185 ("000", 0, 0, 1, FL_MENU_RADIO), 186 (None, 0), 187 ("&Font",0,0,0,FL_SUBMENU), 188 ("Normal", 0, 0, 0, 0, 0, 0, 14), 189 ("Bold", 0, 0, 0, 0, 0, FL_BOLD, 14), 190 ("Italic", 0, 0, 0, 0, 0, FL_ITALIC, 14), 191 ("BoldItalic",0,0,0, 0, 0, FL_BOLD+FL_ITALIC, 14), 192 ("Small", 0, 0, 0, 0, 0, FL_BOLD+FL_ITALIC, 10), 193 ("Emboss", 0, 0, 0, 0, FL_EMBOSSED_LABEL), 194 ("Engrave", 0, 0, 0, 0, FL_ENGRAVED_LABEL), 195 ("Shadow", 0, 0, 0, 0, FL_SHADOW_LABEL), 196 ("@->", 0, 0, 0, 0, FL_SYMBOL_LABEL), 197 (None, 0), 198 ("E&mpty",0,0,0,FL_SUBMENU), 199 (None, 0), 200 ("&Inactive", 0, 0, 0, FL_MENU_INACTIVE|FL_SUBMENU), 201 ("A very long menu item", 0), 202 ("A very long menu item", 0), 203 (None, 0), 204 ("Invisible",0, 0, 0, FL_MENU_INVISIBLE|FL_SUBMENU), 205 ("A very long menu item", 0), 206 ("A very long menu item", 0), 207 (None, 0), 208# ("&Huge", 0, 0, hugemenu, FL_SUBMENU_POINTER), 209 ("button",0, 0, 0, FL_MENU_TOGGLE), 210 (None,) ) 211 212menubar.copy(menutable) 213menubar.callback(test_cb) 214menus[0] = menubar 215 216mb1 = Fl_Menu_Button (50,100,120,25,"&menubutton") 217mb1.text = "&menubutton" 218mb1.copy(pulldown) 219mb1.callback(test_cb) 220menus[1] = mb1 221 222ch = Fl_Choice (250,100,80,25,"&choice:") 223ch.copy(pulldown) 224ch.callback(test_cb) 225menus[2] = ch 226 227ic = Fl_Input_Choice(400,100,80,25,"input") 228ic.add("item1") 229ic.add("item2") 230ic.add("item3") 231 232 233mb = Fl_Menu_Button (0,0,WIDTH,400,"&popup") 234mb.type(Fl_Menu_Button.POPUP3) 235mb.copy(menutable) 236mb.callback(test_cb) 237menus[3] = mb 238 239sp = Fl_Spinner(100, 200, 80, 25, "spinner") 240sp.format("%.1f") 241sp.maximum(113) 242sp.minimum(101) 243sp.step(0.5) 244sp.value(101.5) 245print("Min/Max = ", sp.minimum(), sp.maximum()) 246 247b = Fl_Box(200,200,200,100,"Press right button\nfor a pop-up menu") 248t = Fl_Toggle_Button(250,50,150,25,"MicroSoft Style") 249t.callback(button_cb) 250 251 252 253 254window.resizable(mb) 255window.size_range(300,400,0,400) 256window.end() 257 258window.show(len(sys.argv), sys.argv) 259 260Fl.run() 261