mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Kivy/Android
- refactorings (menubar)
This commit is contained in:
parent
a36cb9ce12
commit
2f87a554be
1 changed files with 137 additions and 66 deletions
|
@ -89,6 +89,84 @@ class IntVar(TkVarObj):
|
||||||
class StringVar(TkVarObj):
|
class StringVar(TkVarObj):
|
||||||
value = StringProperty('')
|
value = StringProperty('')
|
||||||
|
|
||||||
|
# ************************************************************************
|
||||||
|
# * Tree Generators
|
||||||
|
# ************************************************************************
|
||||||
|
# project study, currently unused
|
||||||
|
|
||||||
|
|
||||||
|
class LTreeGenerator(object):
|
||||||
|
def __init__(self, menubar, parent, title, app):
|
||||||
|
self.menubar = menubar
|
||||||
|
self.parent = parent
|
||||||
|
self.app = app
|
||||||
|
self.title = title
|
||||||
|
|
||||||
|
def closeWindow(self, event):
|
||||||
|
self.parent.popWork(self.title)
|
||||||
|
|
||||||
|
def auto_close(self, command):
|
||||||
|
def auto_close_command():
|
||||||
|
command()
|
||||||
|
self.closeWindow(0)
|
||||||
|
return auto_close_command
|
||||||
|
|
||||||
|
def make_auto_command(self, variable, command):
|
||||||
|
def auto_command():
|
||||||
|
variable.set(not variable.get())
|
||||||
|
command()
|
||||||
|
return auto_command
|
||||||
|
|
||||||
|
def addCheckNode(self, tv, rg, title, auto_var, auto_com):
|
||||||
|
command = self.make_auto_command(auto_var, auto_com)
|
||||||
|
rg1 = tv.add_node(
|
||||||
|
LTreeNode(text=title, command=command, variable=auto_var), rg)
|
||||||
|
return rg1
|
||||||
|
|
||||||
|
def make_val_command(self, variable, value, command):
|
||||||
|
def val_command():
|
||||||
|
variable.set(value)
|
||||||
|
command()
|
||||||
|
return val_command
|
||||||
|
|
||||||
|
def make_vars_command(self, command, key):
|
||||||
|
def vars_command():
|
||||||
|
command(key)
|
||||||
|
return vars_command
|
||||||
|
|
||||||
|
def addRadioNode(self, tv, rg, title, auto_var, auto_val, auto_com):
|
||||||
|
command = self.make_val_command(auto_var, auto_val, auto_com)
|
||||||
|
rg1 = tv.add_node(
|
||||||
|
LTreeNode(text=title,
|
||||||
|
command=command,
|
||||||
|
variable=auto_var, value=auto_val), rg)
|
||||||
|
return rg1
|
||||||
|
|
||||||
|
def make_game_command(self, key, command):
|
||||||
|
def game_command():
|
||||||
|
self.closeWindow(0)
|
||||||
|
command(key)
|
||||||
|
return game_command
|
||||||
|
|
||||||
|
def make_command(self, command):
|
||||||
|
def _command():
|
||||||
|
self.closeWindow(0)
|
||||||
|
command()
|
||||||
|
return _command
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
tv = LTreeRoot(root_options=dict(text='EditTree'))
|
||||||
|
tv.hide_root = True
|
||||||
|
tv.size_hint = 1, None
|
||||||
|
tv.bind(minimum_height=tv.setter('height'))
|
||||||
|
self.buildTree(tv, None)
|
||||||
|
return tv
|
||||||
|
|
||||||
|
def buildTree(self, tv, node):
|
||||||
|
print('buildTree base')
|
||||||
|
# to implement in dervied class
|
||||||
|
pass
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# * Menu Dialogs
|
# * Menu Dialogs
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
@ -110,6 +188,49 @@ class LMenuDialog(object):
|
||||||
self.closeWindow(0)
|
self.closeWindow(0)
|
||||||
return auto_close_command
|
return auto_close_command
|
||||||
|
|
||||||
|
def make_auto_command(self, variable, command):
|
||||||
|
def auto_command():
|
||||||
|
variable.set(not variable.get())
|
||||||
|
command()
|
||||||
|
return auto_command
|
||||||
|
|
||||||
|
def addCheckNode(self, tv, rg, title, auto_var, auto_com):
|
||||||
|
command = self.make_auto_command(auto_var, auto_com)
|
||||||
|
rg1 = tv.add_node(
|
||||||
|
LTreeNode(text=title, command=command, variable=auto_var), rg)
|
||||||
|
return rg1
|
||||||
|
|
||||||
|
def make_val_command(self, variable, value, command):
|
||||||
|
def val_command():
|
||||||
|
variable.set(value)
|
||||||
|
command()
|
||||||
|
return val_command
|
||||||
|
|
||||||
|
def make_vars_command(self, command, key):
|
||||||
|
def vars_command():
|
||||||
|
command(key)
|
||||||
|
return vars_command
|
||||||
|
|
||||||
|
def addRadioNode(self, tv, rg, title, auto_var, auto_val, auto_com):
|
||||||
|
command = self.make_val_command(auto_var, auto_val, auto_com)
|
||||||
|
rg1 = tv.add_node(
|
||||||
|
LTreeNode(text=title,
|
||||||
|
command=command,
|
||||||
|
variable=auto_var, value=auto_val), rg)
|
||||||
|
return rg1
|
||||||
|
|
||||||
|
def make_game_command(self, key, command):
|
||||||
|
def game_command():
|
||||||
|
self.closeWindow(0)
|
||||||
|
command(key)
|
||||||
|
return game_command
|
||||||
|
|
||||||
|
def make_command(self, command):
|
||||||
|
def _command():
|
||||||
|
self.closeWindow(0)
|
||||||
|
command()
|
||||||
|
return _command
|
||||||
|
|
||||||
def __init__(self, menubar, parent, title, app, **kw):
|
def __init__(self, menubar, parent, title, app, **kw):
|
||||||
super(LMenuDialog, self).__init__()
|
super(LMenuDialog, self).__init__()
|
||||||
|
|
||||||
|
@ -122,6 +243,9 @@ class LMenuDialog(object):
|
||||||
self.persist = False
|
self.persist = False
|
||||||
if 'persist' in kw:
|
if 'persist' in kw:
|
||||||
self.persist = kw['persist']
|
self.persist = kw['persist']
|
||||||
|
self.tvroot = None
|
||||||
|
if 'tv' in kw:
|
||||||
|
self.tvroot = kw['tv']
|
||||||
|
|
||||||
# prüfen ob noch aktiv - toggle.
|
# prüfen ob noch aktiv - toggle.
|
||||||
|
|
||||||
|
@ -148,14 +272,17 @@ class LMenuDialog(object):
|
||||||
|
|
||||||
# Tree skelett.
|
# Tree skelett.
|
||||||
|
|
||||||
tv = self.tvroot = LTreeRoot(root_options=dict(text='EditTree'))
|
if self.tvroot is None:
|
||||||
tv.hide_root = True
|
tv = self.tvroot = LTreeRoot(root_options=dict(text='EditTree'))
|
||||||
tv.size_hint = 1, None
|
tv.hide_root = True
|
||||||
tv.bind(minimum_height=tv.setter('height'))
|
tv.size_hint = 1, None
|
||||||
|
tv.bind(minimum_height=tv.setter('height'))
|
||||||
|
|
||||||
# menupunkte aufbauen.
|
# menupunkte aufbauen.
|
||||||
|
|
||||||
self.buildTree(tv, None)
|
self.buildTree(tv, None)
|
||||||
|
else:
|
||||||
|
tv = self.tvroot
|
||||||
|
|
||||||
# tree in einem Scrollwindow präsentieren.
|
# tree in einem Scrollwindow präsentieren.
|
||||||
|
|
||||||
|
@ -226,18 +353,6 @@ class FileMenuDialog(LMenuDialog):
|
||||||
super(FileMenuDialog, self).__init__(
|
super(FileMenuDialog, self).__init__(
|
||||||
menubar, parent, title, app, **kw)
|
menubar, parent, title, app, **kw)
|
||||||
|
|
||||||
def make_game_command(self, key, command):
|
|
||||||
def game_command():
|
|
||||||
self.closeWindow(0)
|
|
||||||
command(key)
|
|
||||||
return game_command
|
|
||||||
|
|
||||||
def make_command(self, command):
|
|
||||||
def _command():
|
|
||||||
self.closeWindow(0)
|
|
||||||
command()
|
|
||||||
return _command
|
|
||||||
|
|
||||||
def buildTree(self, tv, node):
|
def buildTree(self, tv, node):
|
||||||
rg = tv.add_node(
|
rg = tv.add_node(
|
||||||
LTreeNode(text=_('Recent games')))
|
LTreeNode(text=_('Recent games')))
|
||||||
|
@ -290,18 +405,6 @@ class EditMenuDialog(LMenuDialog): # Tools
|
||||||
super(EditMenuDialog, self).__init__(
|
super(EditMenuDialog, self).__init__(
|
||||||
menubar, parent, title, app, **kw)
|
menubar, parent, title, app, **kw)
|
||||||
|
|
||||||
def make_auto_command(self, variable, command):
|
|
||||||
def auto_command():
|
|
||||||
variable.set(not variable.get())
|
|
||||||
command()
|
|
||||||
return auto_command
|
|
||||||
|
|
||||||
def addCheckNode(self, tv, rg, title, auto_var, auto_com):
|
|
||||||
command = self.make_auto_command(auto_var, auto_com)
|
|
||||||
rg1 = tv.add_node(
|
|
||||||
LTreeNode(text=title, command=command, variable=auto_var), rg)
|
|
||||||
return rg1
|
|
||||||
|
|
||||||
def buildTree(self, tv, node):
|
def buildTree(self, tv, node):
|
||||||
tv.add_node(LTreeNode(
|
tv.add_node(LTreeNode(
|
||||||
text=_('New game'), command=self.menubar.mNewGame))
|
text=_('New game'), command=self.menubar.mNewGame))
|
||||||
|
@ -489,37 +592,6 @@ class OptionsMenuDialog(LMenuDialog):
|
||||||
super(OptionsMenuDialog, self).__init__(
|
super(OptionsMenuDialog, self).__init__(
|
||||||
menubar, parent, title, app, **kw)
|
menubar, parent, title, app, **kw)
|
||||||
|
|
||||||
def make_auto_command(self, variable, command):
|
|
||||||
def auto_command():
|
|
||||||
variable.set(not variable.get())
|
|
||||||
command()
|
|
||||||
return auto_command
|
|
||||||
|
|
||||||
def addCheckNode(self, tv, rg, title, auto_var, auto_com):
|
|
||||||
command = self.make_auto_command(auto_var, auto_com)
|
|
||||||
rg1 = tv.add_node(
|
|
||||||
LTreeNode(text=title, command=command, variable=auto_var), rg)
|
|
||||||
return rg1
|
|
||||||
|
|
||||||
def make_val_command(self, variable, value, command):
|
|
||||||
def val_command():
|
|
||||||
variable.set(value)
|
|
||||||
command()
|
|
||||||
return val_command
|
|
||||||
|
|
||||||
def make_vars_command(self, command, key):
|
|
||||||
def vars_command():
|
|
||||||
command(key)
|
|
||||||
return vars_command
|
|
||||||
|
|
||||||
def addRadioNode(self, tv, rg, title, auto_var, auto_val, auto_com):
|
|
||||||
command = self.make_val_command(auto_var, auto_val, auto_com)
|
|
||||||
rg1 = tv.add_node(
|
|
||||||
LTreeNode(text=title,
|
|
||||||
command=command,
|
|
||||||
variable=auto_var, value=auto_val), rg)
|
|
||||||
return rg1
|
|
||||||
|
|
||||||
def buildTree(self, tv, node):
|
def buildTree(self, tv, node):
|
||||||
|
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
|
@ -1364,6 +1436,7 @@ class MfxMenubar(EmulTkMenu):
|
||||||
|
|
||||||
class PysolMenubarTk:
|
class PysolMenubarTk:
|
||||||
def __init__(self, app, top, progress=None):
|
def __init__(self, app, top, progress=None):
|
||||||
|
print('PysolMenubarTk: __init__()')
|
||||||
self._createTkOpt()
|
self._createTkOpt()
|
||||||
self._setOptions()
|
self._setOptions()
|
||||||
# init columnbreak
|
# init columnbreak
|
||||||
|
@ -1386,10 +1459,6 @@ class PysolMenubarTk:
|
||||||
if self.progress:
|
if self.progress:
|
||||||
self.progress.update(step=1)
|
self.progress.update(step=1)
|
||||||
|
|
||||||
# set the menubar
|
|
||||||
# self.updateBackgroundImagesMenu()
|
|
||||||
# self.top.config(menu=self.__menubar)
|
|
||||||
|
|
||||||
def _createTkOpt(self):
|
def _createTkOpt(self):
|
||||||
# structure to convert menu-options to Toolkit variables
|
# structure to convert menu-options to Toolkit variables
|
||||||
self.tkopt = Struct(
|
self.tkopt = Struct(
|
||||||
|
@ -1856,7 +1925,9 @@ class PysolMenubarTk:
|
||||||
return
|
return
|
||||||
self.game.setCursor(cursor=CURSOR_WATCH)
|
self.game.setCursor(cursor=CURSOR_WATCH)
|
||||||
after_idle(self.top, self.__restoreCursor)
|
after_idle(self.top, self.__restoreCursor)
|
||||||
OptionsMenuDialog(self, self.top, title=_("Options"), app=self.app)
|
|
||||||
|
tv = None
|
||||||
|
OptionsMenuDialog(self, self.top, title=_("Options"), app=self.app, tv=tv) # noqa
|
||||||
return EVENT_HANDLED
|
return EVENT_HANDLED
|
||||||
|
|
||||||
def mHelpMenuDialog(self, *event):
|
def mHelpMenuDialog(self, *event):
|
||||||
|
|
Loading…
Add table
Reference in a new issue