comparison cagou/core/xmlui.py @ 305:b2727877bad4

remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands: the XMLUI panel was added to the StackLayout used for discovery, resulting in a bad sizing. This patch fixes this by moving discovery panel to a new widget, and adding a main BoxLayout where the XMLUI panel are added. The XMLUI close callback is now handled properly. fix 325
author Goffi <goffi@goffi.org>
date Fri, 19 Jul 2019 17:13:05 +0200
parents 4772ba26623f
children 772c170b47a9
comparison
equal deleted inserted replaced
304:00e2bcf0d9df 305:b2727877bad4
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from .constants import Const as C 21 from .constants import Const as C
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 log = getLogger(__name__)
24 from sat_frontends.tools import xmlui 23 from sat_frontends.tools import xmlui
25 from kivy.uix.scrollview import ScrollView 24 from kivy.uix.scrollview import ScrollView
26 from kivy.uix.boxlayout import BoxLayout 25 from kivy.uix.boxlayout import BoxLayout
27 from kivy.uix.gridlayout import GridLayout 26 from kivy.uix.gridlayout import GridLayout
28 from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem 27 from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem
35 from kivy import properties 34 from kivy import properties
36 from cagou import G 35 from cagou import G
37 from cagou.core import dialog 36 from cagou.core import dialog
38 from functools import partial 37 from functools import partial
39 38
39 log = getLogger(__name__)
40 40
41 ## Widgets ## 41 ## Widgets ##
42 42
43 43
44 class TextInputOnChange(object): 44 class TextInputOnChange(object):
403 self._xmluiClose() 403 self._xmluiClose()
404 404
405 def _xmluiShow(self): 405 def _xmluiShow(self):
406 G.host.addNotifUI(self) 406 G.host.addNotifUI(self)
407 407
408 def _xmluiClose(self): 408 def _xmluiClose(self, reason=None):
409 G.host.closeUI() 409 G.host.closeUI()
410 410
411 def show(self, *args, **kwargs): 411 def show(self, *args, **kwargs):
412 G.host.showUI(self) 412 G.host.showUI(self)
413 413
431 self._xmluiValidated() 431 self._xmluiValidated()
432 432
433 def _xmluiShow(self): 433 def _xmluiShow(self):
434 G.host.addNotifUI(self) 434 G.host.addNotifUI(self)
435 435
436 def _xmluiClose(self): 436 def _xmluiClose(self, reason=None):
437 G.host.closeUI() 437 G.host.closeUI()
438 438
439 def show(self, *args, **kwargs): 439 def show(self, *args, **kwargs):
440 assert kwargs["force"] 440 assert kwargs["force"]
441 G.host.showUI(self) 441 G.host.showUI(self)
452 self.file_chooser.dirselect = True 452 self.file_chooser.dirselect = True
453 453
454 def _xmluiShow(self): 454 def _xmluiShow(self):
455 G.host.addNotifUI(self) 455 G.host.addNotifUI(self)
456 456
457 def _xmluiClose(self): 457 def _xmluiClose(self, reason=None):
458 # FIXME: notif UI is not removed if dialog is not shown yet 458 # FIXME: notif UI is not removed if dialog is not shown yet
459 G.host.closeUI() 459 G.host.closeUI()
460 460
461 def onSelect(self, path): 461 def onSelect(self, path):
462 try: 462 try:
552 return super(XMLUIPanel, self).on_touch_move(touch) 552 return super(XMLUIPanel, self).on_touch_move(touch)
553 553
554 def setCloseCb(self, close_cb): 554 def setCloseCb(self, close_cb):
555 self.close_cb = close_cb 555 self.close_cb = close_cb
556 556
557 def _xmluiClose(self, *__): 557 def _xmluiClose(self, __=None, reason=None):
558 if self.close_cb is not None: 558 if self.close_cb is not None:
559 self.close_cb(self) 559 self.close_cb(self, reason)
560 else: 560 else:
561 G.host.closeUI() 561 G.host.closeUI()
562 562
563 def onParamChange(self, ctrl): 563 def onParamChange(self, ctrl):
564 super(XMLUIPanel, self).onParamChange(ctrl) 564 super(XMLUIPanel, self).onParamChange(ctrl)
596 self.save_btn = SaveButton(text=_(u"Save"), disabled=True) 596 self.save_btn = SaveButton(text=_(u"Save"), disabled=True)
597 self.save_btn.bind(on_press=self._saveButtonCb) 597 self.save_btn.bind(on_press=self._saveButtonCb)
598 self.layout.add_widget(self.save_btn) 598 self.layout.add_widget(self.save_btn)
599 elif self.type == 'window': 599 elif self.type == 'window':
600 cancel_btn = CancelButton(text=_(u"Cancel")) 600 cancel_btn = CancelButton(text=_(u"Cancel"))
601 cancel_btn.bind(on_press=self._xmluiClose) 601 cancel_btn.bind(
602 on_press=partial(self._xmluiClose, reason=C.XMLUI_DATA_CANCELLED))
602 self.layout.add_widget(cancel_btn) 603 self.layout.add_widget(cancel_btn)
603 604
604 def onHeight(self, __, height): 605 def onHeight(self, __, height):
605 if isinstance(self.main_cont, TabsContainer): 606 if isinstance(self.main_cont, TabsContainer):
606 # when the main
607 other_children_height = sum([c.height for c in self.layout.children 607 other_children_height = sum([c.height for c in self.layout.children
608 if c is not self.main_cont]) 608 if c is not self.main_cont])
609 self.main_cont.height = height - other_children_height 609 self.main_cont.height = height - other_children_height
610 610
611 def show(self, *args, **kwargs): 611 def show(self, *args, **kwargs):