# HG changeset patch # User Goffi # Date 1483051633 -3600 # Node ID f67b9baa81f0fc586ac07c5bab4bfd16b1db37b0 # Parent 4d8c122b86a6905583d40391185078116a31ad68 xmlui: FileDialog first draft implemented a basic file dialog. Really basic and ugly, need improvments! diff -r 4d8c122b86a6 -r f67b9baa81f0 src/cagou/core/xmlui.py --- a/src/cagou/core/xmlui.py Thu Dec 29 23:47:10 2016 +0100 +++ b/src/cagou/core/xmlui.py Thu Dec 29 23:47:13 2016 +0100 @@ -23,6 +23,7 @@ log = getLogger(__name__) from sat_frontends.tools import xmlui from kivy.uix.scrollview import ScrollView +from kivy.uix.boxlayout import BoxLayout from kivy.uix.gridlayout import GridLayout from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem from kivy.uix.textinput import TextInput @@ -414,6 +415,38 @@ G.host.addNote(self.title, self.message, self.level) +class FileDialog(xmlui.FileDialog, BoxLayout): + message = properties.ObjectProperty() + + def __init__(self, _xmlui_parent, title, message, level, filetype): + xmlui.FileDialog.__init__(self, _xmlui_parent) + BoxLayout.__init__(self) + self.message.text = message + if filetype == C.XMLUI_DATA_FILETYPE_DIR: + self.file_chooser.dirselect = True + + def _xmluiShow(self): + G.host.addNotifUI(self) + + def _xmluiClose(self): + # FIXME: notif UI is not removed if dialog is not shown yet + G.host.closeUI() + + def onSelect(self, path): + try: + path = path[0] + except IndexError: + path = None + if not path: + self._xmluiCancelled() + else: + self._xmluiValidated({'path': path}) + + def show(self, *args, **kwargs): + assert kwargs["force"] + G.host.showUI(self) + + ## Factory ## diff -r 4d8c122b86a6 -r f67b9baa81f0 src/cagou/kv/xmlui.kv --- a/src/cagou/kv/xmlui.kv Thu Dec 29 23:47:10 2016 +0100 +++ b/src/cagou/kv/xmlui.kv Thu Dec 29 23:47:13 2016 +0100 @@ -21,13 +21,16 @@ size_hint: 1, None height: dp(common_height) + : size_hint: 1, None height: dp(button_height) + : size_hint: 1, 1 + : size_hint: 1, None height: dp(20) @@ -38,14 +41,17 @@ points: 0, dp(10), self.width, dp(10) width: dp(3) + : size_hint_y: None height: dp(button_height) + : size_hint: 1, None height: dp(button_height) + : canvas.before: Color: @@ -63,29 +69,59 @@ pos: self.pos size: self.size + : cols: 1 size_hint: 1, None height: self.minimum_height + : cols: 1 size_hint: 1, None height: self.minimum_height + : cols: 2 size_hint: 1, None height: self.minimum_height + : size_hint: 1, None height: 100 + : size_hint: 1, None height: dp(button_height) + +: + orientation: "vertical" + message: message + file_chooser: file_chooser + Label: + id: message + size_hint: 1, None + text_size: root.width, None + size: self.texture_size + FileChooserListView: + id: file_chooser + Button: + size_hint: 1, None + height: dp(50) + text: "choose" + on_release: root.onSelect(file_chooser.selection) + Button: + size_hint: 1, None + height: dp(50) + text: "cancel" + on_release: root.onCancel() + + + : cols: 1 size_hint: 1, None