Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Title of date_dialog is not displayed
-
Title of dialogs.date_dialog(title='title') is not displayed...
-
I ask me if the date_picker object has a "name" attribute to which is assigned the title parameter in the dialogs.py source.
Then I use the done_button_title, non documented, parameter... -
@cvp , I think you are right it appears not to work. But that API should also have a date param as a starting date. Here is a simple example, it's not 100% because if you hit the X it should return None. I worked this out before, just can't remember at the moment.
But in the mean time I hope this helpsimport ui import datetime class CustomDatePicker(ui.View): def __init__(self, date = None, *args, **kwargs): ui.View.__init__(self, *args, **kwargs) self.date = date self.dp = None self.make_view() m_btn = ui.ButtonItem(title = 'Select') m_btn.action = self.hit self.right_button_items = (m_btn, ) def make_view(self): obj = ui.DatePicker(name = 'dp') if self.date: obj.date = self.date obj.mode = ui.DATE_PICKER_MODE_DATE obj.frame = self.frame obj.flex = 'WH' self.add_subview(obj) self.dp = obj def hit(self, sender): self.close() if __name__ == '__main__': f = (0, 0, 400, 300) d = datetime.datetime.now() d += datetime.timedelta(days = -7 ) cdp = CustomDatePicker(frame = f , bg_color = 'orange', date = d, name ='Please select a date') cdp.present('sheet') cdp.wait_modal() print cdp.dp.date
Edit, I forgot the mode. Is updated now
-
@omz , in beta 2.x in the help file, the DatePicker.mode entry has single quotes around the link. So it does not work
DatePicker.mode
The date picker’s current mode (one of theDate Picker Mode
_ constants defined below). -
Thanks for your help.
I've tried by copying the standard dialogs.py in my folder, changing it to print my title parameter just before the assign view.name=title and it was ok. I don't understand that, if the date_picker object does not have any name attribute, why no error occurs during the execution...
Hoping @omz will explain it. -
@cvp , if you start using **jwargs yourself, I think the answer will be clear. Not saying this is the way it is, but I suspect so. When you receive **kwargs into your function/method etc, you iterate though them and see if your object has that attr. If not is ignored
In below, you can see I commented out passing the **kwargs/dict to ui.View. But then I pass **kwargs to my own method handle_kwargs. It's doing what ui.View.init is doing. This would be the same for ui.DatePicker (well I am pretty sure)# coding: utf-8 import ui import datetime class CustomDatePicker(ui.View): def __init__(self, date = None, *args, **kwargs): #ui.View.__init__(self, *args, **kwargs) self.date = date self.dp = None self.handle_kwargs(**kwargs) self.make_view() m_btn = ui.ButtonItem(title = 'Select') m_btn.action = self.hit self.right_button_items = (m_btn, ) def handle_kwargs(self, **kwargs): for k, v in kwargs.iteritems(): if hasattr(self, k): setattr(self, k, v) def make_view(self): obj = ui.DatePicker(name = 'dp') if self.date: obj.date = self.date obj.frame = self.frame obj.mode = ui.DATE_PICKER_MODE_DATE obj.flex = 'WH' self.add_subview(obj) self.dp = obj def hit(self, sender): self.close() if __name__ == '__main__': f = (0, 0, 400, 300) d = datetime.datetime.now() d += datetime.timedelta(days = -7 ) cdp = CustomDatePicker(frame = f , bg_color = 'orange', date = d, name ='Please select a date') cdp.present('sheet') cdp.wait_modal() print cdp.dp.date
-
Complex but clear, thanks for the explanation.
-
I think it's a bug in dialogs.py, the UIdatepicker of Apple does not have any name property.
If I modify it by adding "container_" before view.name, it's ok...class _DateDialogController (object): def __init__(self, mode=ui.DATE_PICKER_MODE_DATE, title='', done_button_title='Done'): self.was_canceled = True self.container_view = ui.View(background_color='white') self.view = ui.DatePicker() self.container_view.name = title self.view.mode = mode self.view.background_color = 'white' self.view.frame = (0, 0, 500, 500) self.view.flex = 'WH' self.container_view.frame = self.view.frame self.container_view.add_subview(self.view)
-
The name/title is being passed on to the ui.View. with the exception of 1 or 2 the ui gui objects are sub classed from ui.View. (Eg. ui.ButtonItem is special) So they are ui.Views.
You can do the below. I think it's important to remember, dialogs is a wrapper class to just simplify some tasks, but with the cost of not being flexible. But as far as I can see there are still some bugs there. I would say just better off to write your own for now.
import ui dp = ui.DatePicker(name = 'test') dp.present('sheet')
-
Thanks, but if a give a long text as button_title, it takes also the room of an eventual make (title), thus I'm not sure this object has a name property.