Skip to content

Commit

Permalink
Kivy/Android:
Browse files Browse the repository at this point in the history
- Added new menu option to adjust font size in general.
- Fixed a bug with doubleclick moves addressed in #117.
  • Loading branch information
lufebe16 committed Nov 29, 2024
1 parent 4471a8a commit c9c3158
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 23 deletions.
32 changes: 29 additions & 3 deletions pysollib/kivy/LApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
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

Expand Down Expand Up @@ -986,6 +988,31 @@ def closeLastNode(self):

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):

Expand Down Expand Up @@ -1710,13 +1737,12 @@ def on_touch_down(self, touch):
# 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
Expand Down
62 changes: 61 additions & 1 deletion pysollib/kivy/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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
Expand Down Expand Up @@ -133,6 +134,11 @@ def addRadioNode(self, tv, rg, title, auto_var, auto_val, auto_com):
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
# ************************************************************************
Expand Down Expand Up @@ -1259,6 +1265,38 @@ def buildTree(self, tv, node):
# -------------------------------------------
# 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,
Expand Down Expand Up @@ -1433,6 +1471,25 @@ def unlockScreenRotation(self, obj, val):
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

Expand Down Expand Up @@ -1536,6 +1593,8 @@ def _createTkOpt(self):
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"),
Expand All @@ -1554,9 +1613,10 @@ def _createTkOpt(self):
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):
Expand Down
15 changes: 0 additions & 15 deletions pysollib/kivy/tkcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,21 +653,6 @@ def __init__(self, wmain, *args, **kw):
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] +
Expand Down
16 changes: 13 additions & 3 deletions pysollib/kivy/tkwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,21 @@ def collide_point(self,x,y):
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:
Expand Down
4 changes: 4 additions & 0 deletions pysollib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ class Options:
('display_win_message', 'bool'),
('language', 'str'),
# ('table_zoom', 'list'),
('fontscale', 'str'),
# ('fontsizefactor', 'float'),
]

def __init__(self):
Expand Down Expand Up @@ -420,6 +422,8 @@ def __init__(self):
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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9c3158

Please sign in to comment.