This commit is contained in:
yumoqing 2022-09-26 13:23:00 +08:00
parent 3efde148c8
commit 4700ba32a3
2 changed files with 19 additions and 7 deletions

View File

@ -256,11 +256,13 @@ class Modal(VBox):
content = DictProperty(None) content = DictProperty(None)
auto_open = BooleanProperty(True) auto_open = BooleanProperty(True)
auto_dismiss = BooleanProperty(True) auto_dismiss = BooleanProperty(True)
position = OptionProperty('tc',options=['tl', 'tc', 'tr', target = StringProperty(None)
position = OptionProperty('cc',options=['tl', 'tc', 'tr',
'cl', 'cc', 'cr', 'cl', 'cc', 'cr',
'bl', 'bc', 'br']) 'bl', 'bc', 'br'])
def __init__(self, **kw): def __init__(self, **kw):
self._target = None
SUPER(Modal, self, kw) SUPER(Modal, self, kw)
self.register_event_type('on_open') self.register_event_type('on_open')
self.register_event_type('on_pre_open') self.register_event_type('on_pre_open')
@ -283,7 +285,15 @@ class Modal(VBox):
return super().on_touch_down(touch) return super().on_touch_down(touch)
def set_modal_position(self, w): def set_modal_position(self):
if self._target is None:
if self.target is None:
w = Window
else:
w = Factory.Blocks.getWidgetById(self.target)
if w is None:
w = Window
self._target = w
xn = self.position[1] xn = self.position[1]
yn = self.position[0] yn = self.position[0]
x, y = 0, 0 x, y = 0, 0
@ -295,7 +305,7 @@ class Modal(VBox):
x = 0 x = 0
if yn == 'c': if yn == 'c':
y = (w.height - self.height) / 2 y = (w.height - self.height) / 2
elif yn == 'b': elif yn == 't':
y = w.height - self.height y = w.height - self.height
if y < 0: if y < 0:
y = 0 y = 0
@ -308,16 +318,18 @@ class Modal(VBox):
if self.parent: if self.parent:
return return
self.dispatch('on_pre_open') self.dispatch('on_pre_open')
if widget is None: self.set_modal_position()
widget = Window
self.set_modal_position(widget)
Window.add_widget(self) Window.add_widget(self)
self.dispatch('on_open') self.dispatch('on_open')
if self._target != Window:
self._target.disable()
def dismiss(self, *args): def dismiss(self, *args):
self.dispatch('on_pre_dismiss') self.dispatch('on_pre_dismiss')
self.dispatch('on_dismiss') self.dispatch('on_dismiss')
Window.remove_widget(self) Window.remove_widget(self)
if self._target != Window:
self._Target.enable()
def on_open(self, *args): def on_open(self, *args):
pass pass

View File

@ -129,7 +129,7 @@ class DataLoader(EventDispatcher):
class HttpDataLoader(DataLoader): class HttpDataLoader(DataLoader):
def load(self, *args, **kw): def load(self, *args, **kw):
app = App.get_running_app() app = App.get_running_app()
url = app.realurl(self.data_user.url) url = self.data_user.url
method = self.data_user.method method = self.data_user.method
params = self.data_user.params.copy() params = self.data_user.params.copy()
params.update({ params.update({