Skip to content

Commit

Permalink
Kivy/Android
Browse files Browse the repository at this point in the history
- refactorings (menubar)
  • Loading branch information
lufebe16 committed Dec 4, 2023
1 parent a36cb9c commit 2f87a55
Showing 1 changed file with 137 additions and 66 deletions.
203 changes: 137 additions & 66 deletions pysollib/kivy/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,84 @@ class IntVar(TkVarObj):
class StringVar(TkVarObj):
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
# ************************************************************************
Expand All @@ -110,6 +188,49 @@ def auto_close_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 __init__(self, menubar, parent, title, app, **kw):
super(LMenuDialog, self).__init__()

Expand All @@ -122,6 +243,9 @@ def __init__(self, menubar, parent, title, app, **kw):
self.persist = False
if 'persist' in kw:
self.persist = kw['persist']
self.tvroot = None
if 'tv' in kw:
self.tvroot = kw['tv']

# prüfen ob noch aktiv - toggle.

Expand All @@ -148,14 +272,17 @@ def __init__(self, menubar, parent, title, app, **kw):

# Tree skelett.

tv = self.tvroot = LTreeRoot(root_options=dict(text='EditTree'))
tv.hide_root = True
tv.size_hint = 1, None
tv.bind(minimum_height=tv.setter('height'))
if self.tvroot is None:
tv = self.tvroot = LTreeRoot(root_options=dict(text='EditTree'))
tv.hide_root = True
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.

Expand Down Expand Up @@ -226,18 +353,6 @@ def __init__(self, menubar, parent, title, app, **kw):
super(FileMenuDialog, self).__init__(
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):
rg = tv.add_node(
LTreeNode(text=_('Recent games')))
Expand Down Expand Up @@ -290,18 +405,6 @@ def __init__(self, menubar, parent, title, app, **kw):
super(EditMenuDialog, self).__init__(
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):
tv.add_node(LTreeNode(
text=_('New game'), command=self.menubar.mNewGame))
Expand Down Expand Up @@ -489,37 +592,6 @@ def __init__(self, menubar, parent, title, app, **kw):
super(OptionsMenuDialog, self).__init__(
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):

# -------------------------------------------
Expand Down Expand Up @@ -1364,6 +1436,7 @@ def __init__(self, master, **kw):

class PysolMenubarTk:
def __init__(self, app, top, progress=None):
print('PysolMenubarTk: __init__()')
self._createTkOpt()
self._setOptions()
# init columnbreak
Expand All @@ -1386,10 +1459,6 @@ def __init__(self, app, top, progress=None):
if self.progress:
self.progress.update(step=1)

# set the menubar
# self.updateBackgroundImagesMenu()
# self.top.config(menu=self.__menubar)

def _createTkOpt(self):
# structure to convert menu-options to Toolkit variables
self.tkopt = Struct(
Expand Down Expand Up @@ -1856,7 +1925,9 @@ def mOptionsMenuDialog(self, *event):
return
self.game.setCursor(cursor=CURSOR_WATCH)
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

def mHelpMenuDialog(self, *event):
Expand Down

0 comments on commit 2f87a55

Please sign in to comment.