diff --git a/pysollib/kivy/LApp.py b/pysollib/kivy/LApp.py index d5965732..402933ff 100644 --- a/pysollib/kivy/LApp.py +++ b/pysollib/kivy/LApp.py @@ -48,8 +48,10 @@ from kivy.uix.boxlayout import BoxLayout from kivy.uix.floatlayout import FloatLayout from kivy.uix.label import Label from kivy.uix.scrollview import ScrollView +from kivy.uix.slider import Slider from kivy.uix.treeview import TreeView from kivy.uix.treeview import TreeViewLabel +from kivy.uix.treeview import TreeViewNode from kivy.uix.widget import Widget from kivy.utils import platform @@ -986,6 +988,31 @@ class LTreeRoot(TreeView, LBase): return ret +class LTreeSliderNode(Slider, TreeViewNode, LBase): + + def __init__(self, **kw): + self.variable = None + if 'variable' in kw: + self.variable = kw['variable'] + del kw['variable'] + if 'setup' in kw: + self.min = kw['setup'][0] + self.max = kw['setup'][1] + self.step = kw['setup'][2] + del kw['setup'] + + super(LTreeSliderNode, self).__init__(markup=True, **kw) + self.value = self.variable.value + self.height = '24sp' + self.background_width = '12sp' + self.background_height = '12sp' + self.cursor_height = '12sp' + self.cursor_width = '12sp' + + def on_value(self,obj,val): + print (val) + self.variable.value = val + class LTreeNode(ButtonBehavior, TreeViewLabel, LBase): @@ -1710,13 +1737,12 @@ class LMainWindow(BoxLayout, LTkBase): # print(' - interval is', touch.double_tap_time) # print(' - distance betw. previous is', touch.double_tap_distance) AndroidScreenRotation.unlock() - ''' if touch.is_triple_tap: print('Touch is a triple tap !') - print(' - interval is', touch.triple_tap_time) - print(' - distance between previous is', touch.triple_tap_distance) + AndroidScreenRotation.unlock() ''' + # (Eventloop reentrancy check) if self.in_loop: return ret diff --git a/pysollib/kivy/menubar.py b/pysollib/kivy/menubar.py index 13741273..e3e28770 100644 --- a/pysollib/kivy/menubar.py +++ b/pysollib/kivy/menubar.py @@ -37,6 +37,7 @@ from pysollib.kivy.LApp import LScrollView from pysollib.kivy.LApp import LTopLevel from pysollib.kivy.LApp import LTreeNode from pysollib.kivy.LApp import LTreeRoot +from pysollib.kivy.LApp import LTreeSliderNode from pysollib.kivy.LObjWrap import LBoolWrap from pysollib.kivy.LObjWrap import LListWrap from pysollib.kivy.LObjWrap import LNumWrap @@ -133,6 +134,11 @@ class LMenuBase(object): variable=auto_var, value=auto_val), rg) return rg1 + def addSliderNode(self, tv, rg, auto_var, auto_setup): + rg1 = tv.add_node( + LTreeSliderNode(variable=auto_var, setup=auto_setup), rg) + return rg1 + # ************************************************************************ # * Tree Generators # ************************************************************************ @@ -1259,6 +1265,38 @@ class LOptionsMenuGenerator(LTreeGenerator): # ------------------------------------------- # general options + rg = tv.add_node( + LTreeNode(text=_('Font size'))) + if rg: + self.addRadioNode(tv, rg, + _('default'), + self.menubar.tkopt.fontscale, 'default', + None) + self.addRadioNode(tv, rg, + _('tiny'), + self.menubar.tkopt.fontscale, 'tiny', + None) + self.addRadioNode(tv, rg, + _('small'), + self.menubar.tkopt.fontscale, 'small', + None) + self.addRadioNode(tv, rg, + _('normal'), + self.menubar.tkopt.fontscale, 'normal', + None) + self.addRadioNode(tv, rg, + _('large'), + self.menubar.tkopt.fontscale, 'large', + None) + self.addRadioNode(tv, rg, + _('huge'), + self.menubar.tkopt.fontscale, 'huge', + None) + ''' + self.addSliderNode(tv, rg, self.menubar.tkopt.fontsizefactor, + (0.7, 2.0, 0.1)) + ''' + # self.addCheckNode(tv, None, # 'Save games geometry', # self.menubar.tkopt.save_games_geometry, @@ -1433,6 +1471,25 @@ class PysolMenubarTk: AndroidScreenRotation.unlock(toaster=False) print('unlock screen rotation') + def setFontScale(self, obj, val): + from kivy.metrics import Metrics + vals = { + 'tiny': 0.833, + 'small': 1.0, + 'normal': 1.2, + 'large': 1.44, + 'huge': 1.728 + } + if val == 'default': + Metrics.reset_metrics() + else: + Metrics.fontscale = vals[val] + ''' + def setFontSize(self, obj, val): + from kivy.metrics import Metrics + Metrics.fontscale = val + ''' + def _createTkOpt(self): opt = self.app.opt @@ -1536,6 +1593,8 @@ class PysolMenubarTk: save_games_geometry=LBoolWrap(opt, "save_games_geometry"), pause=LBoolWrap(self, "pause"), table_zoom=LListWrap(opt, "table_zoom"), + fontscale=LStringWrap(opt, "fontscale", self.setFontScale), + # fontsizefactor=LNumWrap(opt, "fontsizefactor", self.setFontSize), # cards cardset=LNumWrap(self, "cardset"), cardback=LNumWrap(self, "cardback"), @@ -1554,9 +1613,10 @@ class PysolMenubarTk: self.tkopt.color_vars[k] = LStringWrap(self.cvo, k) def _setOptions(self): - # not supported self.tkopt.save_games_geometry.value = False self.getToolbarPos(None, Window.size) + self.setFontScale(None, self.tkopt.fontscale.value) + # self.setFontSize(None, self.tkopt.fontsizefactor.value) Window.bind(size=self.getToolbarPos) def getToolbarPos(self, obj, size): diff --git a/pysollib/kivy/tkcanvas.py b/pysollib/kivy/tkcanvas.py index 4d0b6f2c..14f7d6a6 100644 --- a/pysollib/kivy/tkcanvas.py +++ b/pysollib/kivy/tkcanvas.py @@ -653,21 +653,6 @@ class MfxCanvas(LImage): self.bind(pos=self.pos_update_widget) self.bind(size=self.size_update_widget) - def on_touch_down(self,touch): - ret = False - ret = super(MfxCanvas,self).on_touch_down(touch) - return ret - - def on_touch_up(self,touch): - ret = False - ret = super(MfxCanvas,self).on_touch_up(touch) - return ret - - def on_touch_move(self,touch): - ret = False - ret = super(MfxCanvas,self).on_touch_move(touch) - return ret - def KivyToCoreP(self, pos, size, scale): cpos = pos cpos = (cpos[0] - self.pos[0], self.pos[1] + diff --git a/pysollib/kivy/tkwidget.py b/pysollib/kivy/tkwidget.py index 68c07a30..0b48188e 100644 --- a/pysollib/kivy/tkwidget.py +++ b/pysollib/kivy/tkwidget.py @@ -441,11 +441,21 @@ class LScatterFrame(Scatter): return False def on_touch_down(self, touch): - if touch.is_double_tap: return False + ret = False x,y = touch.pos if self.collide_point(x,y): - return super(LScatterFrame, self).on_touch_down(touch) - return False + if touch.is_double_tap: + # Do not use the event handling of scatter because scatter + # does not allow to propagate an unhandled double tap back + # to parent (it grabs the touch unseen if not + # handled by a child!). + touch.push() + touch.apply_transform_2d(self.to_local) + ret = self.inner.on_touch_down(touch) + touch.pop() + else: + ret = super(LScatterFrame, self).on_touch_down(touch) + return ret def on_touch_up(self, touch): if touch.grab_current == self: diff --git a/pysollib/options.py b/pysollib/options.py index e1b2865a..f0b59a78 100644 --- a/pysollib/options.py +++ b/pysollib/options.py @@ -324,6 +324,8 @@ class Options: ('display_win_message', 'bool'), ('language', 'str'), # ('table_zoom', 'list'), + ('fontscale', 'str'), + # ('fontsizefactor', 'float'), ] def __init__(self): @@ -420,6 +422,8 @@ class Options: self.display_win_message = True self.language = '' self.table_zoom = [1.0, 0.0, 0.0] + self.fontscale = 'default' # (kivy, platform defaults) + # self.fontsizefactor = 1.0 # sound self.sound = True self.sound_mode = 1 diff --git a/setup.cfg b/setup.cfg index f367fd31..55c5c04d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,7 @@ use_bzip2 = 1 [flake8] extend-ignore = H101,H104,H201,H237,H301,H306,H403,H404,H405, # remove some most ugly flakes: - E211,E225,E231,E302,E305,E701,E741,W293 + E211,E221,E222,E225,E231,E302,E305,E701,E741,W293 [sdist] force_manifest = 1