1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Kivy/Android

- size of menu unified to 0.333 for landscape and 0.5 for portrait mode

- added code to hopefully prevent black screen on resume
- removed old outdated workarounds
This commit is contained in:
lufebe16 2023-12-21 16:15:11 +01:00
parent 2c48745781
commit 2017b4f23b
7 changed files with 60 additions and 74 deletions

View file

@ -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(): def get_screen_ori():
if get_platform() == 'android': if get_platform() == 'android':
from jnius import autoclass from jnius import autoclass
@ -1040,7 +1049,7 @@ class LTopLevelContent(BoxLayout, LBase):
def __init__(self, **kw): def __init__(self, **kw):
super(LTopLevelContent, self).__init__(**kw) super(LTopLevelContent, self).__init__(**kw)
# beispiel zu canvas (hintergrund) # Macht die Hintergrundfarbe der TopLevel (Dialog-) Fenster.
with self.canvas.before: with self.canvas.before:
Color(0.45, 0.5, 0.5, 1.0) Color(0.45, 0.5, 0.5, 1.0)
self.rect = Rectangle(pos=self.pos, size=self.size) self.rect = Rectangle(pos=self.pos, size=self.size)
@ -1086,30 +1095,12 @@ class LTopLevel0(BoxLayout, LBase):
super(LTopLevel0, self).__init__( super(LTopLevel0, self).__init__(
orientation="vertical", **kw) 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.title = title
self.titleline = LTopLine(text=title, size_hint=[1.0, 0.15])
# self.content = BoxLayout(orientation="vertical", **kw)
self.content = LTopLevelContent(orientation="vertical", **kw) self.content = LTopLevelContent(orientation="vertical", **kw)
self.add_widget(self.titleline) self.add_widget(self.titleline)
self.add_widget(self.content) self.add_widget(self.content)
'''
self.button.bind(on_press=self.onClick)
'''
self.titleline.bind(on_press=self.onClick) self.titleline.bind(on_press=self.onClick)
self.main.pushWork(self.title, self) self.main.pushWork(self.title, self)
@ -1126,12 +1117,7 @@ class LTopLevel(BoxLayout, LBase):
super(LTopLevel, self).__init__( super(LTopLevel, self).__init__(
orientation="vertical", **kw) 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.titleline = LTopLine(text=title, size_hint=(1.0, 0.10))
self.content = LTopLevelContent(orientation="vertical", **kw) self.content = LTopLevelContent(orientation="vertical", **kw)
self.add_widget(self.titleline) self.add_widget(self.titleline)
self.add_widget(self.content) self.add_widget(self.content)
@ -1156,7 +1142,6 @@ class LTopLevel(BoxLayout, LBase):
pass pass
return ret return ret
# ============================================================================= # =============================================================================
@ -1782,23 +1767,6 @@ class LApp(App):
else: else:
return False # delegate 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): def __init__(self, args):
super(LApp, self).__init__() super(LApp, self).__init__()
self.args = args self.args = args
@ -1835,7 +1803,6 @@ class LApp(App):
Cache.append('LAppCache', 'mainApp', self, timeout=0) Cache.append('LAppCache', 'mainApp', self, timeout=0)
self.startCode = 0 self.startCode = 0
Window.bind(on_keyboard=self.key_input) Window.bind(on_keyboard=self.key_input)
Window.bind(size=self.doSize)
from pysollib.app import Application from pysollib.app import Application
from pysollib.main import pysol_init from pysollib.main import pysol_init
@ -1962,6 +1929,17 @@ class LApp(App):
# wieder falsch aufstellt. (woher kommt die und warum ist sie # wieder falsch aufstellt. (woher kommt die und warum ist sie
# oft falsch ?) # 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: if app.game.pause:
Clock.schedule_once(self.makeEndPauseCmd(app), 3.0) Clock.schedule_once(self.makeEndPauseCmd(app), 3.0)

View file

@ -207,6 +207,13 @@ class LMenuDialog(LMenuBase):
self.window = window self.window = window
self.running = True 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: if self.persist:
self.dialogCache[title] = window self.dialogCache[title] = window
@ -241,7 +248,6 @@ class LMenuDialog(LMenuBase):
class MainMenuDialog(LMenuDialog): class MainMenuDialog(LMenuDialog):
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.2, 1)
kw['persist'] = True kw['persist'] = True
super(MainMenuDialog, self).__init__( super(MainMenuDialog, self).__init__(
menubar, parent, title, app, **kw) menubar, parent, title, app, **kw)
@ -289,7 +295,6 @@ class MainMenuDialog(LMenuDialog):
class FileMenuDialog(LMenuDialog): class FileMenuDialog(LMenuDialog):
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.3, 1)
super(FileMenuDialog, self).__init__( super(FileMenuDialog, self).__init__(
menubar, parent, title, app, **kw) menubar, parent, title, app, **kw)
@ -358,7 +363,6 @@ class FileMenuDialog(LMenuDialog):
class EditMenuDialog(LMenuDialog): # Tools class EditMenuDialog(LMenuDialog): # Tools
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.2, 1)
kw['persist'] = True kw['persist'] = True
super(EditMenuDialog, self).__init__( super(EditMenuDialog, self).__init__(
menubar, parent, title, app, **kw) menubar, parent, title, app, **kw)
@ -431,7 +435,6 @@ class EditMenuDialog(LMenuDialog): # Tools
class GameMenuDialog(LMenuDialog): class GameMenuDialog(LMenuDialog):
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.2, 1)
kw['persist'] = True kw['persist'] = True
super(GameMenuDialog, self).__init__( super(GameMenuDialog, self).__init__(
menubar, parent, title, app, **kw) menubar, parent, title, app, **kw)
@ -502,7 +505,6 @@ class GameMenuDialog(LMenuDialog):
class AssistMenuDialog(LMenuDialog): class AssistMenuDialog(LMenuDialog):
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.2, 1)
kw['persist'] = True kw['persist'] = True
super(AssistMenuDialog, self).__init__( super(AssistMenuDialog, self).__init__(
menubar, parent, title, app, **kw) menubar, parent, title, app, **kw)
@ -1279,7 +1281,6 @@ class LOptionsMenuGenerator(LTreeGenerator):
class OptionsMenuDialog(LMenuDialog): class OptionsMenuDialog(LMenuDialog):
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.5, 1)
kw['persist'] = True kw['persist'] = True
super(OptionsMenuDialog, self).__init__( super(OptionsMenuDialog, self).__init__(
menubar, parent, title, app, **kw) menubar, parent, title, app, **kw)
@ -1295,7 +1296,6 @@ class OptionsMenuDialog(LMenuDialog):
class HelpMenuDialog(LMenuDialog): class HelpMenuDialog(LMenuDialog):
def __init__(self, menubar, parent, title, app, **kw): def __init__(self, menubar, parent, title, app, **kw):
kw['size_hint'] = (0.3, 1)
kw['persist'] = True kw['persist'] = True
super(HelpMenuDialog, self).__init__(menubar, parent, title, app, **kw) super(HelpMenuDialog, self).__init__(menubar, parent, title, app, **kw)

View file

@ -28,6 +28,7 @@ from pysollib.kivy.LApp import LScrollView
from pysollib.kivy.LApp import LTopLevel from pysollib.kivy.LApp import LTopLevel
from pysollib.kivy.LApp import LTreeNode from pysollib.kivy.LApp import LTreeNode
from pysollib.kivy.LApp import LTreeRoot 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 SelectDialogTreeData
from pysollib.kivy.selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode from pysollib.kivy.selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode
from pysollib.mygettext import _ from pysollib.mygettext import _
@ -382,7 +383,6 @@ class SelectGameDialog(object):
def onClick(self, event): def onClick(self, event):
print('LTopLevel: onClick') print('LTopLevel: onClick')
SelectGameDialog.SingleInstance.parent.popWork('SelectGame') SelectGameDialog.SingleInstance.parent.popWork('SelectGame')
SelectGameDialog.SingleInstance.running = False
def selectCmd(self, gameid): def selectCmd(self, gameid):
self.app.menubar._mSelectGame(gameid) self.app.menubar._mSelectGame(gameid)
@ -394,31 +394,31 @@ class SelectGameDialog(object):
self.app = app self.app = app
self.gameid = gameid self.gameid = gameid
self.random = None self.random = None
self.running = False
self.window = None self.window = None
# bestehenden Dialog rezyklieren. # bestehenden Dialog rezyklieren.
si = SelectGameDialog.SingleInstance si = SelectGameDialog.SingleInstance
# if (si and si.running): return if si and si.parent.workStack.peek('SelectGame') is not None:
if (si and si.running): parent.popWork('SelectGame')
si.parent.popWork('SelectGame')
si.running = False
return return
if (si): if (si):
si.parent.pushWork('SelectGame', si.window) si.parent.pushWork('SelectGame', si.window)
si.running = True
return return
# neuen Dialog aufbauen. # neuen Dialog aufbauen.
window = LTopLevel(parent, title) self.window = window = LTopLevel(parent, title)
window.titleline.bind(on_press=self.onClick) self.window.titleline.bind(on_press=self.onClick)
self.parent.pushWork('SelectGame', window)
self.window = window self.parent.pushWork('SelectGame', self.window)
self.running = True
SelectGameDialog.SingleInstance = self 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. # Asynchron laden.
def loaderCB(treeview, node): def loaderCB(treeview, node):
@ -477,7 +477,7 @@ class SelectGameDialog(object):
tree, tree,
self.app.canvas, self.app.canvas,
root_options=dict(text='Tree One')) root_options=dict(text='Tree One'))
tv.size_hint = 1, None tv.size_hint = (1, None)
tv.hide_root = True tv.hide_root = True
tv.load_func = loaderCB tv.load_func = loaderCB
tv.bind(minimum_height=tv.setter('height')) tv.bind(minimum_height=tv.setter('height'))

View file

@ -692,7 +692,7 @@ class MfxCanvas(LImage):
def psize(s): def psize(s):
return "({:1.2f}, {:1.2f})".format(s[0], s[1]) 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)' % # print('MfxCanvas: update_widget size=(%s, %s)' %
# (self.size[0], self.size[1])) # (self.size[0], self.size[1]))
@ -701,7 +701,7 @@ class MfxCanvas(LImage):
# oldscale = self.scale # oldscale = self.scale
newscale = self.scalefactor() newscale = self.scalefactor()
logging.info('MfxCanvas: scale factor: {:1.2f})'.format(newscale)) # logging.info('MfxCanvas: scale factor: {:1.2f})'.format(newscale))
self.scale = newscale self.scale = newscale
# Anpassung Skalierung. # Anpassung Skalierung.
@ -848,8 +848,8 @@ class MfxCanvas(LImage):
else: else:
lumi = LColorToLuminance(self._bg_color) lumi = LColorToLuminance(self._bg_color)
self._text_color = ("#000000", "#ffffff")[lumi < 0.5] self._text_color = ("#000000", "#ffffff")[lumi < 0.4]
print('average luminance =', lumi) # print('average luminance =', lumi)
def setTile(self, image, stretch=0, save_aspect=0): def setTile(self, image, stretch=0, save_aspect=0):

View file

@ -128,9 +128,9 @@ class LPieChart(Widget):
# * # *
# ************************************************************************ # ************************************************************************
class SingleGame_StatsDialog(MfxDialog): class SingleGame_StatsDialog(MfxDialog):
def __init__(self, parent, title, app, player, gameid, **kw): def __init__(self, parent, title, app, player, gameid, **kw):
kw['size_hint'] = (0.5, 1)
self.app = app self.app = app
self.selected_game = None self.selected_game = None
kw = self.initKw(kw) kw = self.initKw(kw)
@ -142,8 +142,6 @@ class SingleGame_StatsDialog(MfxDialog):
MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw) top_frame, bottom_frame = self.createFrames(kw)
self.top_frame = top_frame self.top_frame = top_frame
# self.createBitmaps(top_frame, kw)
# #
self.player = player or _("Demo games") self.player = player or _("Demo games")
self.top.wm_minsize(200, 200) self.top.wm_minsize(200, 200)

View file

@ -68,6 +68,9 @@ def setTransient(window, parent, relx=None, rely=None, expose=1):
return return
# ANM: werden ev. immer noch vom pysollib core benötigt/referenziert:
# (intern in kivy bitte nicht direkt benutzen).
def makeToplevel(parent, title=None): def makeToplevel(parent, title=None):
print('tkutil: makeTopLevel') print('tkutil: makeTopLevel')

View file

@ -39,10 +39,11 @@ from kivy.uix.label import Label
from pysollib.kivy.LApp import LBoxLayout from pysollib.kivy.LApp import LBoxLayout
from pysollib.kivy.LApp import LScrollView from pysollib.kivy.LApp import LScrollView
from pysollib.kivy.LApp import LTopLevel 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.LImage import LImage
from pysollib.kivy.tkcanvas import MfxCanvas from pysollib.kivy.tkcanvas import MfxCanvas
from pysollib.kivy.tkutil import bind, unbind_destroy from pysollib.kivy.tkutil import bind, unbind_destroy
from pysollib.kivy.tkutil import makeToplevel
from pysollib.mfxutil import KwStruct, kwdefault from pysollib.mfxutil import KwStruct, kwdefault
from pysollib.mygettext import _ from pysollib.mygettext import _
from pysollib.settings import WIN_SYSTEM from pysollib.settings import WIN_SYSTEM
@ -63,7 +64,13 @@ class MfxDialog: # ex. _ToplevelDialog
self.timer = None self.timer = None
self.buttons = [] self.buttons = []
self.accel_keys = {} 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): def wmDeleteWindow(self, *event):
self.status = 1 self.status = 1