Skip to content

Commit 0135e38

Browse files
committed
Android/Kivy:
- Event handling: Pass through for empty stacks. - Menu entry to reset zoom.
1 parent 70909f6 commit 0135e38

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

pysollib/kivy/LApp.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,10 @@ def get_image_type(self):
806806
- Most events return EVENT_HANDLED even if they did not change anything
807807
in current situations. I would expect specifically for stack base cards
808808
that they return HANDLE_PROPAGATE if nothing happened.
809+
- stack __defaultclickhandler__ returns EVENT_HANDLED in any case so some
810+
code here is obsolete or for future.
811+
- A pragmatic way to handle this: If an empty stack is still empty
812+
after the click then we propagate otherwise not.
809813
LB241111.
810814
'''
811815

@@ -851,7 +855,6 @@ def on_touch_down(self, touch):
851855
self.dragstart = touch.pos
852856
event.cardid = i
853857
r = self.send_event_pressed(touch, event)
854-
# print("********* event return = ",r)
855858
if r == EVENT_HANDLED:
856859
AndroidScreenRotation.lock(toaster=False)
857860
print('grab')
@@ -869,7 +872,8 @@ def on_touch_down(self, touch):
869872
event.y = ppos[1]
870873
r = self.group.bindings['<1>'](event)
871874
if r == EVENT_HANDLED:
872-
return True
875+
if len(self.group.stack.cards) > 0:
876+
return True
873877
return False
874878

875879
if self.card is None:
@@ -907,7 +911,6 @@ def on_touch_up(self, touch):
907911
event.y = ppos[1]
908912
event.cardid = i
909913
r = self.send_event_released_1(event)
910-
# print("********* event return = ",r)
911914
if r == EVENT_HANDLED:
912915
return True
913916
return False
@@ -922,7 +925,8 @@ def on_touch_up(self, touch):
922925
event.y = ppos[1]
923926
r = self.group.bindings['<ButtonRelease-1>'](event)
924927
if r == EVENT_HANDLED:
925-
return True
928+
if len(self.group.stack.cards) > 0:
929+
return True
926930
return False
927931

928932
if self.card is None:

pysollib/kivy/menubar.py

+6
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ def buildTree(self, tv, node):
387387
text=_('Shuffle tiles'), command=self.menubar.mShuffle))
388388
tv.add_node(LTreeNode(
389389
text=_('Deal cards'), command=self.menubar.mDeal))
390+
tv.add_node(LTreeNode(
391+
text=_('Reset zoom'),
392+
command=self.auto_close(self.menubar.mResetZoom)))
390393

391394
self.addCheckNode(tv, None,
392395
_('Pause'),
@@ -2141,6 +2144,9 @@ def mSaveAs(self, *event):
21412144
toast.show(parent=baseWindow, duration=5.0)
21422145
self.updateMenus()
21432146

2147+
def mResetZoom(self, *args):
2148+
self.tkopt.table_zoom.value = [1.0, 0.0, 0.0]
2149+
21442150
def mPause(self, *args):
21452151
if not self.game:
21462152
return

pysollib/kivy/tkwidget.py

+5
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ def set_scale(self,zoom):
397397
yoff = zoom[2]
398398
self.offset = (xoff,yoff)
399399

400+
def _change_command(self,inst,val):
401+
if self.lock_pos is None:
402+
self.set_scale(val)
403+
400404
def _update(self):
401405
# initialisation
402406
if self.tkopt is None:
@@ -407,6 +411,7 @@ def _update(self):
407411
self.tkopt = tkopt
408412
self.set_scale(tkopt.table_zoom.value)
409413
print("table_zoom",tkopt.table_zoom.value)
414+
tkopt.table_zoom.bind(value=self._change_command)
410415

411416
# update
412417
if self.lock_pos is None:

0 commit comments

Comments
 (0)