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

Kivy/Android:

- Added new menu option to adjust font size in general.
- Fixed a bug with doubleclick moves addressed in #117.
This commit is contained in:
lufebe16 2024-11-28 16:58:01 +01:00
parent 4471a8a623
commit c9c315818d
6 changed files with 108 additions and 23 deletions

View file

@ -48,8 +48,10 @@ from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from kivy.uix.treeview import TreeView from kivy.uix.treeview import TreeView
from kivy.uix.treeview import TreeViewLabel from kivy.uix.treeview import TreeViewLabel
from kivy.uix.treeview import TreeViewNode
from kivy.uix.widget import Widget from kivy.uix.widget import Widget
from kivy.utils import platform from kivy.utils import platform
@ -986,6 +988,31 @@ class LTreeRoot(TreeView, LBase):
return ret 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): class LTreeNode(ButtonBehavior, TreeViewLabel, LBase):
@ -1710,13 +1737,12 @@ class LMainWindow(BoxLayout, LTkBase):
# print(' - interval is', touch.double_tap_time) # print(' - interval is', touch.double_tap_time)
# print(' - distance betw. previous is', touch.double_tap_distance) # print(' - distance betw. previous is', touch.double_tap_distance)
AndroidScreenRotation.unlock() AndroidScreenRotation.unlock()
''' '''
if touch.is_triple_tap: if touch.is_triple_tap:
print('Touch is a triple tap !') print('Touch is a triple tap !')
print(' - interval is', touch.triple_tap_time) AndroidScreenRotation.unlock()
print(' - distance between previous is', touch.triple_tap_distance)
''' '''
# (Eventloop reentrancy check) # (Eventloop reentrancy check)
if self.in_loop: if self.in_loop:
return ret return ret

View file

@ -37,6 +37,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 LTreeSliderNode
from pysollib.kivy.LObjWrap import LBoolWrap from pysollib.kivy.LObjWrap import LBoolWrap
from pysollib.kivy.LObjWrap import LListWrap from pysollib.kivy.LObjWrap import LListWrap
from pysollib.kivy.LObjWrap import LNumWrap from pysollib.kivy.LObjWrap import LNumWrap
@ -133,6 +134,11 @@ class LMenuBase(object):
variable=auto_var, value=auto_val), rg) variable=auto_var, value=auto_val), rg)
return rg1 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 # * Tree Generators
# ************************************************************************ # ************************************************************************
@ -1259,6 +1265,38 @@ class LOptionsMenuGenerator(LTreeGenerator):
# ------------------------------------------- # -------------------------------------------
# general options # 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, # self.addCheckNode(tv, None,
# 'Save games geometry', # 'Save games geometry',
# self.menubar.tkopt.save_games_geometry, # self.menubar.tkopt.save_games_geometry,
@ -1433,6 +1471,25 @@ class PysolMenubarTk:
AndroidScreenRotation.unlock(toaster=False) AndroidScreenRotation.unlock(toaster=False)
print('unlock screen rotation') 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): def _createTkOpt(self):
opt = self.app.opt opt = self.app.opt
@ -1536,6 +1593,8 @@ class PysolMenubarTk:
save_games_geometry=LBoolWrap(opt, "save_games_geometry"), save_games_geometry=LBoolWrap(opt, "save_games_geometry"),
pause=LBoolWrap(self, "pause"), pause=LBoolWrap(self, "pause"),
table_zoom=LListWrap(opt, "table_zoom"), table_zoom=LListWrap(opt, "table_zoom"),
fontscale=LStringWrap(opt, "fontscale", self.setFontScale),
# fontsizefactor=LNumWrap(opt, "fontsizefactor", self.setFontSize),
# cards # cards
cardset=LNumWrap(self, "cardset"), cardset=LNumWrap(self, "cardset"),
cardback=LNumWrap(self, "cardback"), cardback=LNumWrap(self, "cardback"),
@ -1554,9 +1613,10 @@ class PysolMenubarTk:
self.tkopt.color_vars[k] = LStringWrap(self.cvo, k) self.tkopt.color_vars[k] = LStringWrap(self.cvo, k)
def _setOptions(self): def _setOptions(self):
# not supported
self.tkopt.save_games_geometry.value = False self.tkopt.save_games_geometry.value = False
self.getToolbarPos(None, Window.size) self.getToolbarPos(None, Window.size)
self.setFontScale(None, self.tkopt.fontscale.value)
# self.setFontSize(None, self.tkopt.fontsizefactor.value)
Window.bind(size=self.getToolbarPos) Window.bind(size=self.getToolbarPos)
def getToolbarPos(self, obj, size): def getToolbarPos(self, obj, size):

View file

@ -653,21 +653,6 @@ class MfxCanvas(LImage):
self.bind(pos=self.pos_update_widget) self.bind(pos=self.pos_update_widget)
self.bind(size=self.size_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): def KivyToCoreP(self, pos, size, scale):
cpos = pos cpos = pos
cpos = (cpos[0] - self.pos[0], self.pos[1] + cpos = (cpos[0] - self.pos[0], self.pos[1] +

View file

@ -441,11 +441,21 @@ class LScatterFrame(Scatter):
return False return False
def on_touch_down(self, touch): def on_touch_down(self, touch):
if touch.is_double_tap: return False ret = False
x,y = touch.pos x,y = touch.pos
if self.collide_point(x,y): if self.collide_point(x,y):
return super(LScatterFrame, self).on_touch_down(touch) if touch.is_double_tap:
return False # 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): def on_touch_up(self, touch):
if touch.grab_current == self: if touch.grab_current == self:

View file

@ -324,6 +324,8 @@ class Options:
('display_win_message', 'bool'), ('display_win_message', 'bool'),
('language', 'str'), ('language', 'str'),
# ('table_zoom', 'list'), # ('table_zoom', 'list'),
('fontscale', 'str'),
# ('fontsizefactor', 'float'),
] ]
def __init__(self): def __init__(self):
@ -420,6 +422,8 @@ class Options:
self.display_win_message = True self.display_win_message = True
self.language = '' self.language = ''
self.table_zoom = [1.0, 0.0, 0.0] self.table_zoom = [1.0, 0.0, 0.0]
self.fontscale = 'default' # (kivy, platform defaults)
# self.fontsizefactor = 1.0
# sound # sound
self.sound = True self.sound = True
self.sound_mode = 1 self.sound_mode = 1

View file

@ -7,7 +7,7 @@ use_bzip2 = 1
[flake8] [flake8]
extend-ignore = H101,H104,H201,H237,H301,H306,H403,H404,H405, extend-ignore = H101,H104,H201,H237,H301,H306,H403,H404,H405,
# remove some most ugly flakes: # remove some most ugly flakes:
E211,E225,E231,E302,E305,E701,E741,W293 E211,E221,E222,E225,E231,E302,E305,E701,E741,W293
[sdist] [sdist]
force_manifest = 1 force_manifest = 1