Skip to content

Commit c9194ea

Browse files
committed
Kivy/Android
- Introduced tree view generators in menubar.py - applied to the option menu.
1 parent 1df1f6a commit c9194ea

File tree

2 files changed

+81
-91
lines changed

2 files changed

+81
-91
lines changed

pysollib/kivy/LApp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def addEndCallback(self, cb):
147147

148148
def taskEnd(self, task, value):
149149
if value:
150-
print('LAnimationMgr: taskEnd = %s %s' % (task, value))
150+
# print('LAnimationMgr: taskEnd = %s %s' % (task, value))
151151
self.tasks.remove(task)
152152
if not self.checkRunning():
153153
# print('LAnimationMgr: taskEnd ->', len(self.callbacks), 'callbacks') # noqa
@@ -156,7 +156,7 @@ def taskEnd(self, task, value):
156156
# print('LAnimationMgr: taskEnd -> callbacks done')
157157
self.callbacks = []
158158

159-
print('Clock.get_fps() ->', Clock.get_fps())
159+
# print('Clock.get_fps() ->', Clock.get_fps())
160160

161161
def create(self, spos, widget, **kw):
162162
x = 0.0

pysollib/kivy/menubar.py

+79-89
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,23 @@ class StringVar(TkVarObj):
9090
value = StringProperty('')
9191

9292
# ************************************************************************
93-
# * Tree Generators
93+
# * Common base
9494
# ************************************************************************
95-
# project study, currently unused
9695

9796

98-
class LTreeGenerator(object):
97+
class LMenuBase(object):
9998
def __init__(self, menubar, parent, title, app):
10099
self.menubar = menubar
101100
self.parent = parent
102101
self.app = app
103102
self.title = title
104103

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+
105110
def closeWindow(self, event):
106111
self.parent.popWork(self.title)
107112

@@ -154,90 +159,53 @@ def _command():
154159
command()
155160
return _command
156161

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+
157171
def generate(self):
158172
tv = LTreeRoot(root_options=dict(text='EditTree'))
159173
tv.hide_root = True
160174
tv.size_hint = 1, None
161175
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)
163188
return tv
164189

165190
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
169196

170197
# ************************************************************************
171198
# * Menu Dialogs
172199
# ************************************************************************
173200

174201

175-
class LMenuDialog(object):
202+
class LMenuDialog(LMenuBase):
176203

177204
dialogCache = {}
178205

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-
234206
def __init__(self, menubar, parent, title, app, **kw):
235-
super(LMenuDialog, self).__init__()
207+
super(LMenuDialog, self).__init__(menubar, parent, title, app)
236208

237-
self.menubar = menubar
238-
self.parent = parent
239-
self.app = app
240-
self.title = title
241209
self.window = None
242210
self.running = False
243211
self.persist = False
@@ -270,29 +238,29 @@ def __init__(self, menubar, parent, title, app, **kw):
270238
if self.persist:
271239
self.dialogCache[title] = window
272240

273-
# Tree skelett.
241+
# Tree construct or assign.
274242

275243
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()
283245
self.buildTree(tv, None)
284246
else:
285247
tv = self.tvroot
286248

287-
# tree in einem Scrollwindow präsentieren.
249+
# show the tree in a scroll window
288250

289251
root = LScrollView(pos=(0, 0))
290252
root.add_widget(tv)
291253
self.window.content.add_widget(root)
292254

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+
293262
def buildTree(self, tree, node):
294-
print('buildTree base')
295-
# to implement in dervied class
263+
# to implement in dervied class if needed
296264
pass
297265

298266
# ************************************************************************
@@ -584,16 +552,12 @@ def buildTree(self, tv, node):
584552
# ************************************************************************
585553

586554

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)
594559

595560
def buildTree(self, tv, node):
596-
597561
# -------------------------------------------
598562
# Automatic play settings
599563

@@ -622,6 +586,7 @@ def buildTree(self, tv, node):
622586
self.menubar.tkopt.quickplay,
623587
self.menubar.mOptQuickPlay)
624588

589+
yield
625590
# -------------------------------------------
626591
# Player assistance
627592

@@ -707,6 +672,7 @@ def buildTree(self, tv, node):
707672

708673
# submenu.add_separator()
709674

675+
yield
710676
# -------------------------------------------
711677
# Language options
712678

@@ -738,6 +704,7 @@ def buildTree(self, tv, node):
738704
self.menubar.tkopt.language, 'ru',
739705
self.menubar.mOptLanguage)
740706

707+
yield
741708
# -------------------------------------------
742709
# Sound options
743710

@@ -899,6 +866,7 @@ def buildTree(self, tv, node):
899866
self.menubar.tkopt.sound_sample_vars[key],
900867
self.make_vars_command(self.menubar.mOptSoundSample, key))
901868

869+
yield
902870
# -------------------------------------------
903871
# Cardsets and card backside options
904872

@@ -914,10 +882,12 @@ def buildTree(self, tv, node):
914882
cs = csm.get(i)
915883
if cs is None:
916884
break
885+
917886
rg1 = self.addRadioNode(tv, rg,
918887
cs.name,
919888
self.menubar.tkopt.cardset, i,
920889
self.menubar.mOptCardset)
890+
921891
if rg1:
922892
cbs = cs.backnames
923893
self.menubar.tkopt.cardbacks[i] = IntVar()
@@ -939,6 +909,7 @@ def buildTree(self, tv, node):
939909

940910
i += 1
941911

912+
yield
942913
# -------------------------------------------
943914
# Table background settings
944915

@@ -1066,6 +1037,7 @@ def buildTree(self, tv, node):
10661037
self.menubar.mOptTileSet)
10671038
i += 1
10681039

1040+
yield
10691041
# -------------------------------------------
10701042
# Card view options
10711043

@@ -1097,6 +1069,7 @@ def buildTree(self, tv, node):
10971069
self.menubar.tkopt.shade_filled_stacks,
10981070
self.menubar.mOptShadeFilledStacks)
10991071

1072+
yield
11001073
# -------------------------------------------
11011074
# Animation settins
11021075

@@ -1145,6 +1118,7 @@ def buildTree(self, tv, node):
11451118
self.menubar.tkopt.win_animation,
11461119
self.menubar.mWinAnimation)
11471120

1121+
yield
11481122
# -------------------------------------------
11491123
# Touch mode settings
11501124

@@ -1187,6 +1161,7 @@ def buildTree(self, tv, node):
11871161
menu.add_separator()
11881162
'''
11891163

1164+
yield
11901165
# -------------------------------------------
11911166
# Toolbar options
11921167

@@ -1317,6 +1292,22 @@ def buildTree(self, tv, node):
13171292
self.menubar.tkopt.display_win_message,
13181293
self.menubar.mWinDialog)
13191294

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
13201311

13211312
# ************************************************************************
13221313

@@ -1926,8 +1917,7 @@ def mOptionsMenuDialog(self, *event):
19261917
self.game.setCursor(cursor=CURSOR_WATCH)
19271918
after_idle(self.top, self.__restoreCursor)
19281919

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)
19311921
return EVENT_HANDLED
19321922

19331923
def mHelpMenuDialog(self, *event):

0 commit comments

Comments
 (0)