diff --git a/pysollib/kivy/LApp.py b/pysollib/kivy/LApp.py index e3d3a3bec..152711e09 100644 --- a/pysollib/kivy/LApp.py +++ b/pysollib/kivy/LApp.py @@ -71,6 +71,15 @@ def get_platform(): # ============================================================================= +def get_menu_size_hint(): + sh = (0.5, 1.0) + if Window.size[0] < Window.size[1]: + sh = (1.0, 1.0) + return sh + +# ============================================================================= + + def get_screen_ori(): if get_platform() == 'android': from jnius import autoclass @@ -1040,7 +1049,7 @@ class LTopLevelContent(BoxLayout, LBase): def __init__(self, **kw): super(LTopLevelContent, self).__init__(**kw) - # beispiel zu canvas (hintergrund) + # Macht die Hintergrundfarbe der TopLevel (Dialog-) Fenster. with self.canvas.before: Color(0.45, 0.5, 0.5, 1.0) self.rect = Rectangle(pos=self.pos, size=self.size) @@ -1086,30 +1095,12 @@ def __init__(self, top, title=None, **kw): super(LTopLevel0, self).__init__( orientation="vertical", **kw) - # self.canvas.add(Color(0, 1, 0, 0.4)) - # self.canvas.add(Rectangle(pos=(100, 100), size=(100, 100))) - - self.size_hint = (0.5, 1.0) - ''' - self.titleline = BoxLayout( - orientation="horizontal", size_hint=[1.0, 0.15], **kw) - self.button = Button(text="X", size_hint=[0.15, 1.0], **kw) - if not title: - title = '<>' - self.title = Label(text=title, **kw) - self.titleline.add_widget(self.title) - self.titleline.add_widget(self.button) - ''' - self.titleline = LTopLine(text=title, size_hint=[1.0, 0.15]) self.title = title - - # self.content = BoxLayout(orientation="vertical", **kw) + self.titleline = LTopLine(text=title, size_hint=[1.0, 0.15]) self.content = LTopLevelContent(orientation="vertical", **kw) self.add_widget(self.titleline) self.add_widget(self.content) - ''' - self.button.bind(on_press=self.onClick) - ''' + self.titleline.bind(on_press=self.onClick) self.main.pushWork(self.title, self) @@ -1126,12 +1117,7 @@ def __init__(self, parent, title=None, **kw): super(LTopLevel, self).__init__( orientation="vertical", **kw) - if ('size_hint' not in kw): - self.size_hint = (0.5, 1.0) - else: - del kw['size_hint'] self.titleline = LTopLine(text=title, size_hint=(1.0, 0.10)) - self.content = LTopLevelContent(orientation="vertical", **kw) self.add_widget(self.titleline) self.add_widget(self.content) @@ -1156,7 +1142,6 @@ def processAndroidBack(self): pass return ret - # ============================================================================= @@ -1782,23 +1767,6 @@ def key_input(self, window, key, scancode, codepoint, modifier): else: return False # delegate - def delayedRebuild(self, dt): - logging.info("LApp: delayedRebuild") - self.mainWindow.rebuildContainer() - - def makeDelayedRebuild(self): - def delayedRebuild(dt): - # Clock.schedule_once(self.delayedRebuild, 0.01) - Clock.schedule_once(self.delayedRebuild, 0.5) - return delayedRebuild - - def doSize(self, obj, val): - mval = self.mainWindow.size - if (val[0] != mval[0] and val[1] != mval[1]): - logging.info("LApp: size changed %s - %s (%s)" % (obj, val, mval)) - Clock.schedule_once(self.makeDelayedRebuild(), 0.2) - pass - def __init__(self, args): super(LApp, self).__init__() self.args = args @@ -1835,7 +1803,6 @@ def app_start(self, dt): Cache.append('LAppCache', 'mainApp', self, timeout=0) self.startCode = 0 Window.bind(on_keyboard=self.key_input) - Window.bind(size=self.doSize) from pysollib.app import Application from pysollib.main import pysol_init @@ -1962,6 +1929,17 @@ def on_resume(self): # wieder falsch aufstellt. (woher kommt die und warum ist sie # oft falsch ?) + # Gelegentlich beobachtet: Schwarzer Bilschirm nach resume. Und + # das bleibt dann so auf ewig. Aber die app läuft stabil. Die + # einzige Interaktion mit der App ist über die Android buttons + # für hintrgrund und resume. Diese funktioneren gemäss logcat + # einwandfrei. Daher versuchen wir ... um den graphik context + # wieder zu aktivieren/auszurichten: + Clock.schedule_once(lambda dt: Window.update_viewport(), 2.0) + # (Es gibt auch Beispiele in den kivy issues die nahelegen, dass + # das nützlich sein könnte) + + # Pause modus abschalten nach resume: if app.game.pause: Clock.schedule_once(self.makeEndPauseCmd(app), 3.0) diff --git a/pysollib/kivy/menubar.py b/pysollib/kivy/menubar.py index 9fc54c6a7..6fed19715 100644 --- a/pysollib/kivy/menubar.py +++ b/pysollib/kivy/menubar.py @@ -207,6 +207,13 @@ def __init__(self, menubar, parent, title, app, **kw): self.window = window self.running = True + from pysollib.kivy.LApp import get_menu_size_hint + + def updrule(obj, val): + self.window.size_hint = get_menu_size_hint() + updrule(0, 0) + self.parent.bind(size=updrule) + if self.persist: self.dialogCache[title] = window @@ -241,7 +248,6 @@ def buildTree(self, tree, node): class MainMenuDialog(LMenuDialog): def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.2, 1) kw['persist'] = True super(MainMenuDialog, self).__init__( menubar, parent, title, app, **kw) @@ -289,7 +295,6 @@ def buildTree(self, tv, node): class FileMenuDialog(LMenuDialog): def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.3, 1) super(FileMenuDialog, self).__init__( menubar, parent, title, app, **kw) @@ -358,7 +363,6 @@ def buildTree(self, tv, node): class EditMenuDialog(LMenuDialog): # Tools def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.2, 1) kw['persist'] = True super(EditMenuDialog, self).__init__( menubar, parent, title, app, **kw) @@ -431,7 +435,6 @@ def buildTree(self, tv, node): class GameMenuDialog(LMenuDialog): def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.2, 1) kw['persist'] = True super(GameMenuDialog, self).__init__( menubar, parent, title, app, **kw) @@ -502,7 +505,6 @@ def buildTree(self, tv, node): class AssistMenuDialog(LMenuDialog): def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.2, 1) kw['persist'] = True super(AssistMenuDialog, self).__init__( menubar, parent, title, app, **kw) @@ -1279,7 +1281,6 @@ def buildTree(self, tv, node): class OptionsMenuDialog(LMenuDialog): def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.5, 1) kw['persist'] = True super(OptionsMenuDialog, self).__init__( menubar, parent, title, app, **kw) @@ -1295,7 +1296,6 @@ def initTree(self): class HelpMenuDialog(LMenuDialog): def __init__(self, menubar, parent, title, app, **kw): - kw['size_hint'] = (0.3, 1) kw['persist'] = True super(HelpMenuDialog, self).__init__(menubar, parent, title, app, **kw) diff --git a/pysollib/kivy/selectgame.py b/pysollib/kivy/selectgame.py index 82fcc0a4c..d28ce254b 100644 --- a/pysollib/kivy/selectgame.py +++ b/pysollib/kivy/selectgame.py @@ -28,6 +28,7 @@ from pysollib.kivy.LApp import LTopLevel from pysollib.kivy.LApp import LTreeNode from pysollib.kivy.LApp import LTreeRoot +from pysollib.kivy.LApp import get_menu_size_hint from pysollib.kivy.selecttree import SelectDialogTreeData from pysollib.kivy.selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode from pysollib.mygettext import _ @@ -382,7 +383,6 @@ class SelectGameDialog(object): def onClick(self, event): print('LTopLevel: onClick') SelectGameDialog.SingleInstance.parent.popWork('SelectGame') - SelectGameDialog.SingleInstance.running = False def selectCmd(self, gameid): self.app.menubar._mSelectGame(gameid) @@ -394,31 +394,31 @@ def __init__(self, parent, title, app, gameid, **kw): self.app = app self.gameid = gameid self.random = None - self.running = False self.window = None # bestehenden Dialog rezyklieren. si = SelectGameDialog.SingleInstance - # if (si and si.running): return - if (si and si.running): - si.parent.popWork('SelectGame') - si.running = False + if si and si.parent.workStack.peek('SelectGame') is not None: + parent.popWork('SelectGame') return if (si): si.parent.pushWork('SelectGame', si.window) - si.running = True return # neuen Dialog aufbauen. - window = LTopLevel(parent, title) - window.titleline.bind(on_press=self.onClick) - self.parent.pushWork('SelectGame', window) - self.window = window - self.running = True + self.window = window = LTopLevel(parent, title) + self.window.titleline.bind(on_press=self.onClick) + + self.parent.pushWork('SelectGame', self.window) SelectGameDialog.SingleInstance = self + def updrule(obj, val): + self.window.size_hint = get_menu_size_hint() + updrule(0, 0) + self.parent.bind(size=updrule) + # Asynchron laden. def loaderCB(treeview, node): @@ -477,7 +477,7 @@ def loaderCB(treeview, node): tree, self.app.canvas, root_options=dict(text='Tree One')) - tv.size_hint = 1, None + tv.size_hint = (1, None) tv.hide_root = True tv.load_func = loaderCB tv.bind(minimum_height=tv.setter('height')) diff --git a/pysollib/kivy/tkcanvas.py b/pysollib/kivy/tkcanvas.py index da6cb073e..927fab0bc 100644 --- a/pysollib/kivy/tkcanvas.py +++ b/pysollib/kivy/tkcanvas.py @@ -692,7 +692,7 @@ def update_widget(self, posorobj, size): def psize(s): return "({:1.2f}, {:1.2f})".format(s[0], s[1]) - logging.info('MfxCanvas: update_widget to: '+psize(size)) + # logging.info('MfxCanvas: update_widget to: '+psize(size)) # print('MfxCanvas: update_widget size=(%s, %s)' % # (self.size[0], self.size[1])) @@ -701,7 +701,7 @@ def psize(s): # oldscale = self.scale newscale = self.scalefactor() - logging.info('MfxCanvas: scale factor: {:1.2f})'.format(newscale)) + # logging.info('MfxCanvas: scale factor: {:1.2f})'.format(newscale)) self.scale = newscale # Anpassung Skalierung. @@ -848,8 +848,8 @@ def setTextColor(self, color): else: lumi = LColorToLuminance(self._bg_color) - self._text_color = ("#000000", "#ffffff")[lumi < 0.5] - print('average luminance =', lumi) + self._text_color = ("#000000", "#ffffff")[lumi < 0.4] + # print('average luminance =', lumi) def setTile(self, image, stretch=0, save_aspect=0): diff --git a/pysollib/kivy/tkstats.py b/pysollib/kivy/tkstats.py index 02aeac23f..04095f6bd 100644 --- a/pysollib/kivy/tkstats.py +++ b/pysollib/kivy/tkstats.py @@ -128,9 +128,9 @@ def updateCanvas(self, instance, value): # * # ************************************************************************ + class SingleGame_StatsDialog(MfxDialog): def __init__(self, parent, title, app, player, gameid, **kw): - kw['size_hint'] = (0.5, 1) self.app = app self.selected_game = None kw = self.initKw(kw) @@ -142,8 +142,6 @@ def __init__(self, parent, title, app, player, gameid, **kw): MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) top_frame, bottom_frame = self.createFrames(kw) self.top_frame = top_frame - -# self.createBitmaps(top_frame, kw) # self.player = player or _("Demo games") self.top.wm_minsize(200, 200) diff --git a/pysollib/kivy/tkutil.py b/pysollib/kivy/tkutil.py index e22bec053..5cfcc7d8d 100644 --- a/pysollib/kivy/tkutil.py +++ b/pysollib/kivy/tkutil.py @@ -68,6 +68,9 @@ def setTransient(window, parent, relx=None, rely=None, expose=1): return +# ANM: werden ev. immer noch vom pysollib core benötigt/referenziert: +# (intern in kivy bitte nicht direkt benutzen). + def makeToplevel(parent, title=None): print('tkutil: makeTopLevel') diff --git a/pysollib/kivy/tkwidget.py b/pysollib/kivy/tkwidget.py index ba251beee..be1184930 100644 --- a/pysollib/kivy/tkwidget.py +++ b/pysollib/kivy/tkwidget.py @@ -39,10 +39,11 @@ from pysollib.kivy.LApp import LBoxLayout from pysollib.kivy.LApp import LScrollView from pysollib.kivy.LApp import LTopLevel +from pysollib.kivy.LApp import LTopLevel0 +from pysollib.kivy.LApp import get_menu_size_hint from pysollib.kivy.LImage import LImage from pysollib.kivy.tkcanvas import MfxCanvas from pysollib.kivy.tkutil import bind, unbind_destroy -from pysollib.kivy.tkutil import makeToplevel from pysollib.mfxutil import KwStruct, kwdefault from pysollib.mygettext import _ from pysollib.settings import WIN_SYSTEM @@ -63,7 +64,13 @@ def __init__(self, parent, title="", resizable=False, default=-1): self.timer = None self.buttons = [] self.accel_keys = {} - self.top = makeToplevel(parent, title=title) + self.window = LTopLevel0(parent, title=title) + self.top = self.window.content + + def setSizeRule(obj, val): + self.window.size_hint = get_menu_size_hint() + self.parent.bind(size=setSizeRule) + setSizeRule(0, 0) def wmDeleteWindow(self, *event): self.status = 1