Debian Codegraph @

fltk/test/preferences.py

raw symbols SCIP
1 #
2 # "$Id: preferences.py 495 2013-03-30 09:39:45Z andreasheld $"
3 #
4 # Preferences 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 import sys, time
28 from fltk import *
29
30 myWindow = None
31 wAmPm = None
32
33 def closeWindowCB(widget):
34 global myWindow
35 myWindow.hide()
36 sys.exit(0)
37
38 def saveAndCloseCB(widget):
39 global myWindow
40 writePrefs()
41 myWindow.hide()
42 sys.exit(0)
43
44 def readPrefs():
45 global wAmPm
46 app = Fl_Preferences(Fl_Preferences.USER, "fltk.org", "test/preferences")
47 #app = Fl_Preferences("C:/", "fltk.org", "test/preferences")
48
49 #path = ""
50 (status, path) = app.getUserdataPath(128)
51 print("Path = ", path)
52
53 bed = Fl_Preferences(app, "Bed")
54 buffer = ""
55 (status, buffer) = bed.get("alarm", "8:00", 79)
56 wAlarm.value(buffer)
57
58 (status, intValue) = bed.get("ampm", 0)
59 wAmPm.value(intValue)
60
61 (status, intValue) = bed.get("wear", 1)
62 wWear.value(intValue)
63
64 (status, side) = bed.get("side", 2)
65 if side == 1:
66 wLeft.value(1)
67 elif side == 2:
68 wRight.value(1)
69
70 (status, tasks) = bed.get("taskFlags", 0x05)
71 if tasks & 0x01:
72 wShower.value( 1 )
73 if tasks & 0x02:
74 wShave.value( 1 )
75 if tasks & 0x04:
76 wBrush.value( 1 )
77
78 eat = Fl_Preferences(app, "Breakfast")
79 (status, intValue) = eat.get("drink", 1)
80 wDrink.value(intValue)
81
82 (status, boolValue) = eat.get("wMilk", 0 )
83 wMilk.value(boolValue)
84
85 (status, intValue) = eat.get("bread", 0 )
86 wBread.value(intValue)
87
88 (status, boolValue) = eat.get("wButter", 1 )
89 wButter.value(boolValue)
90
91 (status, intValue) = eat.get( "nEggs", 2 )
92 buffer = str(intValue)
93 wEggs.value(buffer)
94
95 (status, doubleValue) = eat.get( "minutes", 3.2 )
96 wMinutes.value(doubleValue)
97
98 flexBuffer = ""
99 (status, flexBuffer) = eat.get( "newspaper", "NY Tymes", 80)
100 wPaper.value(flexBuffer);
101
102 # destruct children first
103 eat = None
104 bed = None
105 #app = None
106
107
108 def writePrefs():
109 app = Fl_Preferences(Fl_Preferences.USER, "fltk.org", "test/preferences")
110 #app = Fl_Preferences("C:/", "fltk.org", "test/preferences")
111 bed = Fl_Preferences(app, "Bed" )
112
113 bed.set( "alarm", wAlarm.value() )
114 bed.set( "ampm", wAmPm.value() )
115 bed.set( "wear", wWear.value() )
116
117 side = 0
118 if wLeft.value() != 0:
119 side = 1
120 if wRight.value() != 0:
121 side = 2
122 bed.set("side", side)
123
124 tasks = 0;
125 if wShower.value() != 0:
126 tasks |= 0x01
127 if wShave.value() != 0:
128 tasks |= 0x02
129 if wBrush.value() != 0:
130 tasks |= 0x04
131 bed.set("taskFlags", tasks)
132 eat = Fl_Preferences(app, "Breakfast")
133 eat.set("drink", wDrink.value() )
134 eat.set("wMilk", wMilk.value() )
135 eat.set("bread", wBread.value() )
136 eat.set("wButter", wButter.value() )
137 eat.set("nEggs", wEggs.value() )
138 eat.set("minutes", wMinutes.value() )
139 eat.set("newspaper", wPaper.value() )
140
141 # destruct children first
142 bed = None
143 eat = None
144
145 # app.flush()
146
147
148 menu_wAmPm = (("a.m.", 0, 0, 0, 0, 0, 0, 14, 56),
149 ("p.m.", 0, 0, 0, 0, 0, 0, 14, 56),
150 (None,))
151
152 menu_wWear = (("shoes", 0, 0, 0, 0, 0, 0, 14, 56),
153 ("sandals", 0, 0, 0, 0, 0, 0, 14, 56),
154 ("flip flops", 0, 0, 0, 0, 0, 0, 14, 56),
155 ("bare foot", 0, 0, 0, 0, 0, 0, 14, 56),
156 (None, ))
157
158 menu_wDrink = (("coffee", 0, 0, 0, 0, 0, 0, 14, 56),
159 ("tea", 0, 0, 0, 0, 0, 0, 14, 56),
160 ("juice", 0, 0, 0, 0, 0, 0, 14, 56),
161 (None, ))
162
163 menu_wBread = (("wheat", 0, 0, 0, 0, 0, 0, 14, 56),
164 ("white", 0, 0, 0, 0, 0, 0, 14, 56),
165 ("rye", 0, 0, 0, 0, 0, 0, 14, 56),
166 ("sour doh", 0, 0, 0, 0, 0, 0, 14, 56),
167 (None, ))
168
169 myWindow = Fl_Double_Window(298, 311, "My Preferences")
170 #myWindow = Fl_Window(298, 311, "My Preferences")
171 myWindow.callback(closeWindowCB)
172 b1 = Fl_Button(210, 275, 75, 25, "Cancel")
173 b1.callback(closeWindowCB)
174 b2 = Fl_Button(125, 275, 75, 25, "OK")
175 b2.callback(saveAndCloseCB)
176
177 grp1 = Fl_Group(20, 30, 115, 225, "get Up:")
178 grp1.box(FL_ENGRAVED_BOX)
179 grp1.align(FL_ALIGN_TOP_LEFT)
180 wAlarm = Fl_Input(25, 55, 45, 20, "Alarm at:")
181 wAlarm.align(FL_ALIGN_TOP_LEFT)
182 wAmPm = Fl_Choice(75, 55, 55, 20)
183 wAmPm.down_box(FL_BORDER_BOX)
184 wAmPm.menu(menu_wAmPm)
185 wWear = Fl_Choice(25, 100, 105, 20, "Wear:")
186 wWear.down_box(FL_BORDER_BOX)
187 wWear.align(FL_ALIGN_TOP_LEFT)
188 wWear.menu(menu_wWear)
189 wLeft = Fl_Round_Button(35, 120, 95, 25, "left side")
190 wLeft.down_box(FL_ROUND_DOWN_BOX)
191 wRight = Fl_Round_Button(35, 140, 95, 25, "right side")
192 wRight.down_box(FL_ROUND_DOWN_BOX)
193
194 b3 = Fl_Box(38, 160, 95, 20, "of the bed")
195 wShower = Fl_Check_Button(25, 180, 105, 25, "shower")
196 wShower.down_box(FL_DOWN_BOX)
197 wShave = Fl_Check_Button(25, 200, 105, 25, "shave")
198 wShave.down_box(FL_DOWN_BOX);
199 wBrush = Fl_Check_Button(25, 220, 105, 25, "brush teeth")
200 wBrush.down_box(FL_DOWN_BOX);
201 grp1.end()
202
203 grp2 = Fl_Group(160, 30, 115, 225, "Breakfast::")
204 grp2.box(FL_ENGRAVED_FRAME)
205 grp2.align(FL_ALIGN_TOP_LEFT)
206 wDrink = Fl_Choice(165, 50, 105, 20, "Drink:")
207 wDrink.down_box(FL_BORDER_BOX)
208 wDrink.align(FL_ALIGN_TOP_LEFT)
209 wDrink.menu(menu_wDrink)
210 wMilk = Fl_Check_Button(170, 70, 100, 25, "with milk")
211 wMilk.down_box(FL_DOWN_BOX)
212 wBread = Fl_Choice(165, 110, 105, 20, "Bread:")
213 wBread.down_box(FL_BORDER_BOX)
214 wBread.align(FL_ALIGN_TOP_LEFT)
215 wBread.menu(menu_wBread)
216 wButter = Fl_Check_Button(170, 130, 100, 25, "with butter")
217 wButter.down_box(FL_DOWN_BOX)
218 wEggs = Fl_Input(165, 163, 30, 20, "eggs")
219 wEggs.type(2)
220 wEggs.align(FL_ALIGN_RIGHT)
221 wMinutes = Fl_Value_Slider(175, 185, 70, 20, "min.")
222 wMinutes.type(1)
223 wMinutes.minimum(2)
224 wMinutes.maximum(6)
225 wMinutes.value(3.1)
226 wMinutes.align(FL_ALIGN_RIGHT)
227 wPaper = Fl_Input(165, 225, 105, 20, "Newspaper:")
228 wPaper.align(FL_ALIGN_TOP_LEFT)
229 grp2.end();
230
231 myWindow.end()
232 readPrefs()
233 myWindow.show(sys.argv)
234 Fl.run()