comparison cagou/core/cagou_main.py @ 154:a5e8833184c6

widget handler: refactoring: - replaced proof of concept implementation with cleaner one based on custom layout - removed proof of concept big bars in favor of thin line to separate widgets, with a 3 dots area in the center where user can touch/click more easily - when in delete zone, the line + half circle become red, so user knows that she's about to delete a widget - carousel is now created in kv - ignore perpendicular swipes. This was not working before but is know working well, and the swipe is far more easy to do on desktop or mobile - each new widget of the handler has an id (its creation number), which is displayed in debug logs on touch - handler's widgets keep track of which widgets are on sides (left, top, right, bottom)
author Goffi <goffi@goffi.org>
date Fri, 27 Apr 2018 16:45:09 +0200
parents b9fd83292fc4
children e6ec8ff62d87
comparison
equal deleted inserted replaced
153:e0985834f8eb 154:a5e8833184c6
44 from kivy.app import App 44 from kivy.app import App
45 from kivy.lang import Builder 45 from kivy.lang import Builder
46 from kivy import properties 46 from kivy import properties
47 import xmlui 47 import xmlui
48 from profile_manager import ProfileManager 48 from profile_manager import ProfileManager
49 from widgets_handler import WidgetsHandler
50 from kivy.clock import Clock 49 from kivy.clock import Clock
51 from kivy.uix.label import Label 50 from kivy.uix.label import Label
52 from kivy.uix.boxlayout import BoxLayout 51 from kivy.uix.boxlayout import BoxLayout
53 from kivy.uix.floatlayout import FloatLayout 52 from kivy.uix.floatlayout import FloatLayout
54 from kivy.uix.screenmanager import ScreenManager, Screen, FallOutTransition, RiseInTransition 53 from kivy.uix.screenmanager import ScreenManager, Screen, FallOutTransition, RiseInTransition
569 def newWidget(self, widget): 568 def newWidget(self, widget):
570 log.debug(u"new widget created: {}".format(widget)) 569 log.debug(u"new widget created: {}".format(widget))
571 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP: 570 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP:
572 self.addNote(u"", _(u"room {} has been joined").format(widget.target)) 571 self.addNote(u"", _(u"room {} has been joined").format(widget.target))
573 572
574 def getParentHandler(self, widget):
575 """Return handler holding this widget
576
577 @return (WidgetsHandler): handler
578 """
579 w_handler = widget.parent
580 while w_handler and not(isinstance(w_handler, widgets_handler.WidgetsHandler)):
581 w_handler = w_handler.parent
582 return w_handler
583
584 def switchWidget(self, old, new): 573 def switchWidget(self, old, new):
585 """Replace old widget by new one 574 """Replace old widget by new one
586 575
587 old(CagouWidget): CagouWidget instance or a child 576 old(CagouWidget): CagouWidget instance or a child
588 new(CagouWidget): new widget instance 577 new(CagouWidget): new widget instance
596 to_change = w 585 to_change = w
597 break 586 break
598 587
599 if to_change is None: 588 if to_change is None:
600 raise exceptions.InternalError(u"no CagouWidget found when trying to switch widget") 589 raise exceptions.InternalError(u"no CagouWidget found when trying to switch widget")
601 handler = self.getParentHandler(to_change) 590
602 handler.changeWidget(new) 591 wrapper = to_change.parent
592 while wrapper is not None and not(isinstance(wrapper, widgets_handler.WHWrapper)):
593 wrapper = wrapper.parent
594
595 if wrapper is None:
596 raise exceptions.InternalError(u"no wrapper found")
597
598 wrapper.changeWidget(new)
603 599
604 def addVisibleWidget(self, widget): 600 def addVisibleWidget(self, widget):
605 """declare a widget visible 601 """declare a widget visible
606 602
607 for internal use only! 603 for internal use only!
656 widget.onOTRState(state, dest_jid, profile) 652 widget.onOTRState(state, dest_jid, profile)
657 653
658 ## misc ## 654 ## misc ##
659 655
660 def plugging_profiles(self): 656 def plugging_profiles(self):
661 self.app.root.changeWidget(WidgetsHandler()) 657 self.app.root.changeWidget(widgets_handler.WidgetsHandler())
662 self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb) 658 self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb)
663 659
664 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): 660 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
665 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status)) 661 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status))
666 662