@@ -90,18 +90,23 @@ class StringVar(TkVarObj):
90
90
value = StringProperty ('' )
91
91
92
92
# ************************************************************************
93
- # * Tree Generators
93
+ # * Common base
94
94
# ************************************************************************
95
- # project study, currently unused
96
95
97
96
98
- class LTreeGenerator (object ):
97
+ class LMenuBase (object ):
99
98
def __init__ (self , menubar , parent , title , app ):
100
99
self .menubar = menubar
101
100
self .parent = parent
102
101
self .app = app
103
102
self .title = title
104
103
104
+ def make_pop_command (self , parent , title ):
105
+ def pop_command (event ):
106
+ print ('event = %s' % event )
107
+ parent .popWork (title )
108
+ return pop_command
109
+
105
110
def closeWindow (self , event ):
106
111
self .parent .popWork (self .title )
107
112
@@ -154,90 +159,53 @@ def _command():
154
159
command ()
155
160
return _command
156
161
162
+ # ************************************************************************
163
+ # * Tree Generators
164
+ # ************************************************************************
165
+
166
+
167
+ class LTreeGenerator (LMenuBase ):
168
+ def __init__ (self , menubar , parent , title , app ):
169
+ super (LTreeGenerator , self ).__init__ (menubar , parent , title , app )
170
+
157
171
def generate (self ):
158
172
tv = LTreeRoot (root_options = dict (text = 'EditTree' ))
159
173
tv .hide_root = True
160
174
tv .size_hint = 1 , None
161
175
tv .bind (minimum_height = tv .setter ('height' ))
162
- self .buildTree (tv , None )
176
+
177
+ gen = self .buildTree (tv , None )
178
+
179
+ def process (dt ):
180
+ try :
181
+ gen .send (None )
182
+ Clock .schedule_once (process , 0.2 )
183
+ except StopIteration :
184
+ print ('generator: all jobs done' )
185
+ pass
186
+
187
+ Clock .schedule_once (process , 0.2 )
163
188
return tv
164
189
165
190
def buildTree (self , tv , node ):
166
- print ('buildTree base' )
167
- # to implement in dervied class
168
- pass
191
+ print ('buildTree generator function not implemented' )
192
+ # needs at least on 'yield' statement
193
+ # not reentrant: do not recurse !
194
+ # implement it in a dervied class
195
+ yield
169
196
170
197
# ************************************************************************
171
198
# * Menu Dialogs
172
199
# ************************************************************************
173
200
174
201
175
- class LMenuDialog (object ):
202
+ class LMenuDialog (LMenuBase ):
176
203
177
204
dialogCache = {}
178
205
179
- def make_pop_command (self , parent , title ):
180
- def pop_command (event ):
181
- print ('event = %s' % event )
182
- parent .popWork (title )
183
- return pop_command
184
-
185
- def auto_close (self , command ):
186
- def auto_close_command ():
187
- command ()
188
- self .closeWindow (0 )
189
- return auto_close_command
190
-
191
- def make_auto_command (self , variable , command ):
192
- def auto_command ():
193
- variable .set (not variable .get ())
194
- command ()
195
- return auto_command
196
-
197
- def addCheckNode (self , tv , rg , title , auto_var , auto_com ):
198
- command = self .make_auto_command (auto_var , auto_com )
199
- rg1 = tv .add_node (
200
- LTreeNode (text = title , command = command , variable = auto_var ), rg )
201
- return rg1
202
-
203
- def make_val_command (self , variable , value , command ):
204
- def val_command ():
205
- variable .set (value )
206
- command ()
207
- return val_command
208
-
209
- def make_vars_command (self , command , key ):
210
- def vars_command ():
211
- command (key )
212
- return vars_command
213
-
214
- def addRadioNode (self , tv , rg , title , auto_var , auto_val , auto_com ):
215
- command = self .make_val_command (auto_var , auto_val , auto_com )
216
- rg1 = tv .add_node (
217
- LTreeNode (text = title ,
218
- command = command ,
219
- variable = auto_var , value = auto_val ), rg )
220
- return rg1
221
-
222
- def make_game_command (self , key , command ):
223
- def game_command ():
224
- self .closeWindow (0 )
225
- command (key )
226
- return game_command
227
-
228
- def make_command (self , command ):
229
- def _command ():
230
- self .closeWindow (0 )
231
- command ()
232
- return _command
233
-
234
206
def __init__ (self , menubar , parent , title , app , ** kw ):
235
- super (LMenuDialog , self ).__init__ ()
207
+ super (LMenuDialog , self ).__init__ (menubar , parent , title , app )
236
208
237
- self .menubar = menubar
238
- self .parent = parent
239
- self .app = app
240
- self .title = title
241
209
self .window = None
242
210
self .running = False
243
211
self .persist = False
@@ -270,29 +238,29 @@ def __init__(self, menubar, parent, title, app, **kw):
270
238
if self .persist :
271
239
self .dialogCache [title ] = window
272
240
273
- # Tree skelett .
241
+ # Tree construct or assign .
274
242
275
243
if self .tvroot is None :
276
- tv = self .tvroot = LTreeRoot (root_options = dict (text = 'EditTree' ))
277
- tv .hide_root = True
278
- tv .size_hint = 1 , None
279
- tv .bind (minimum_height = tv .setter ('height' ))
280
-
281
- # menupunkte aufbauen.
282
-
244
+ tv = self .initTree ()
283
245
self .buildTree (tv , None )
284
246
else :
285
247
tv = self .tvroot
286
248
287
- # tree in einem Scrollwindow präsentieren.
249
+ # show the tree in a scroll window
288
250
289
251
root = LScrollView (pos = (0 , 0 ))
290
252
root .add_widget (tv )
291
253
self .window .content .add_widget (root )
292
254
255
+ def initTree (self ):
256
+ tv = self .tvroot = LTreeRoot (root_options = dict (text = 'EditTree' ))
257
+ tv .hide_root = True
258
+ tv .size_hint = 1 , None
259
+ tv .bind (minimum_height = tv .setter ('height' ))
260
+ return tv
261
+
293
262
def buildTree (self , tree , node ):
294
- print ('buildTree base' )
295
- # to implement in dervied class
263
+ # to implement in dervied class if needed
296
264
pass
297
265
298
266
# ************************************************************************
@@ -584,16 +552,12 @@ def buildTree(self, tv, node):
584
552
# ************************************************************************
585
553
586
554
587
- class OptionsMenuDialog (LMenuDialog ):
588
-
589
- def __init__ (self , menubar , parent , title , app , ** kw ):
590
- kw ['size_hint' ] = (0.5 , 1 )
591
- kw ['persist' ] = True
592
- super (OptionsMenuDialog , self ).__init__ (
593
- menubar , parent , title , app , ** kw )
555
+ class LOptionsMenuGenerator (LTreeGenerator ):
556
+ def __init__ (self , menubar , parent , title , app ):
557
+ super (LOptionsMenuGenerator , self ).__init__ (
558
+ menubar , parent , title , app )
594
559
595
560
def buildTree (self , tv , node ):
596
-
597
561
# -------------------------------------------
598
562
# Automatic play settings
599
563
@@ -622,6 +586,7 @@ def buildTree(self, tv, node):
622
586
self .menubar .tkopt .quickplay ,
623
587
self .menubar .mOptQuickPlay )
624
588
589
+ yield
625
590
# -------------------------------------------
626
591
# Player assistance
627
592
@@ -707,6 +672,7 @@ def buildTree(self, tv, node):
707
672
708
673
# submenu.add_separator()
709
674
675
+ yield
710
676
# -------------------------------------------
711
677
# Language options
712
678
@@ -738,6 +704,7 @@ def buildTree(self, tv, node):
738
704
self .menubar .tkopt .language , 'ru' ,
739
705
self .menubar .mOptLanguage )
740
706
707
+ yield
741
708
# -------------------------------------------
742
709
# Sound options
743
710
@@ -899,6 +866,7 @@ def buildTree(self, tv, node):
899
866
self .menubar .tkopt .sound_sample_vars [key ],
900
867
self .make_vars_command (self .menubar .mOptSoundSample , key ))
901
868
869
+ yield
902
870
# -------------------------------------------
903
871
# Cardsets and card backside options
904
872
@@ -914,10 +882,12 @@ def buildTree(self, tv, node):
914
882
cs = csm .get (i )
915
883
if cs is None :
916
884
break
885
+
917
886
rg1 = self .addRadioNode (tv , rg ,
918
887
cs .name ,
919
888
self .menubar .tkopt .cardset , i ,
920
889
self .menubar .mOptCardset )
890
+
921
891
if rg1 :
922
892
cbs = cs .backnames
923
893
self .menubar .tkopt .cardbacks [i ] = IntVar ()
@@ -939,6 +909,7 @@ def buildTree(self, tv, node):
939
909
940
910
i += 1
941
911
912
+ yield
942
913
# -------------------------------------------
943
914
# Table background settings
944
915
@@ -1066,6 +1037,7 @@ def buildTree(self, tv, node):
1066
1037
self .menubar .mOptTileSet )
1067
1038
i += 1
1068
1039
1040
+ yield
1069
1041
# -------------------------------------------
1070
1042
# Card view options
1071
1043
@@ -1097,6 +1069,7 @@ def buildTree(self, tv, node):
1097
1069
self .menubar .tkopt .shade_filled_stacks ,
1098
1070
self .menubar .mOptShadeFilledStacks )
1099
1071
1072
+ yield
1100
1073
# -------------------------------------------
1101
1074
# Animation settins
1102
1075
@@ -1145,6 +1118,7 @@ def buildTree(self, tv, node):
1145
1118
self .menubar .tkopt .win_animation ,
1146
1119
self .menubar .mWinAnimation )
1147
1120
1121
+ yield
1148
1122
# -------------------------------------------
1149
1123
# Touch mode settings
1150
1124
@@ -1187,6 +1161,7 @@ def buildTree(self, tv, node):
1187
1161
menu.add_separator()
1188
1162
'''
1189
1163
1164
+ yield
1190
1165
# -------------------------------------------
1191
1166
# Toolbar options
1192
1167
@@ -1317,6 +1292,22 @@ def buildTree(self, tv, node):
1317
1292
self .menubar .tkopt .display_win_message ,
1318
1293
self .menubar .mWinDialog )
1319
1294
1295
+ # ************************************************************************
1296
+
1297
+
1298
+ class OptionsMenuDialog (LMenuDialog ):
1299
+
1300
+ def __init__ (self , menubar , parent , title , app , ** kw ):
1301
+ kw ['size_hint' ] = (0.5 , 1 )
1302
+ kw ['persist' ] = True
1303
+ super (OptionsMenuDialog , self ).__init__ (
1304
+ menubar , parent , title , app , ** kw )
1305
+
1306
+ def initTree (self ):
1307
+ og = LOptionsMenuGenerator (
1308
+ self .menubar , self .parent , title = _ ("Options" ), app = self .app )
1309
+ tv = og .generate ()
1310
+ return tv
1320
1311
1321
1312
# ************************************************************************
1322
1313
@@ -1926,8 +1917,7 @@ def mOptionsMenuDialog(self, *event):
1926
1917
self .game .setCursor (cursor = CURSOR_WATCH )
1927
1918
after_idle (self .top , self .__restoreCursor )
1928
1919
1929
- tv = None
1930
- OptionsMenuDialog (self , self .top , title = _ ("Options" ), app = self .app , tv = tv ) # noqa
1920
+ OptionsMenuDialog (self , self .top , title = _ ("Options" ), app = self .app )
1931
1921
return EVENT_HANDLED
1932
1922
1933
1923
def mHelpMenuDialog (self , * event ):
0 commit comments