Is it possible to create subviews in the UI Editor? If so, a) how and b) how would I name them? I basically want to create several "pop-up dialogs" to use in my app.
Thanks!
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.
Is it possible to create subviews in the UI Editor? If so, a) how and b) how would I name them? I basically want to create several "pop-up dialogs" to use in my app.
Thanks!
I have 2 different controls on the same form calling the same action. The 2 ways of triggering the action are a) Pressing enter after entering text into the textfield and b) clicking the Select button. Unfortunately, if you click the Select button, both actions are being triggered and I'm not sure how to fix this. The full code is available on [github][1]
The action being triggered twice is self.process_speak_request
which is set once in a form and once below.
class TextDelegate(object):```
def textfield_did_change(self, textfield):
view = textfield.superview
button = view['button_select']
button.enabled = textfield.text != ''
class Menu:
def prompt_speak(self, sender):
"""Prompt the user for the task(s) to speak."""
self.prompt_dialog = ui.load_view('dialogs/speak_task_number')
self.prompt_dialog['button_select'].enabled = False
td = TextDelegate()
self.prompt_dialog['textfield1'].delegate = td
self.prompt_dialog["segmentedcontrol1"].action = self.display_speak_options
self.prompt_dialog['textfield1'].begin_editing()
self.prompt_dialog['textfield1'].action = self.process_speak_request
self.prompt_dialog.present('popover', popover_location=(500, 500))
def display_speak_options(self, sender):
"""Display the controls to enter a number"""
if self.prompt_dialog["segmentedcontrol1"].selected_index == 0:
self.prompt_dialog["label1"].hidden = False
self.prompt_dialog["textfield1"].hidden = False
if self.prompt_dialog["textfield1"].text == '':
self.prompt_dialog['button_select'].enabled = False
else:
self.prompt_dialog["button_select"].enabled = True
else:
self.prompt_dialog["label1"].hidden = True
self.prompt_dialog["textfield1"].hidden = True
self.prompt_dialog['button_select'].enabled = True
def enable_select(self, sender):
"""Enable the Select button after a task # has been provided."""
self.prompt_dialog['button_select'].enabled = True
self.main_view.set_needs_display()
def process_speak_request(self, sender):
"""""Determine which task(s) to recite"""
recite = self.prompt_dialog["segmentedcontrol1"].selected_index
if recite == 0:
task_id = self._validate_task_id(self.prompt_dialog['textfield1'].text)
if task_id:
self.prompt_dialog.close()
self.current_task = self.tasklist._find_task(task_id)
self.speak_task(self.current_task)
else:
self.prompt_dialog['textfield1'].text = ''
self.prompt_dialog['button_select'].enabled = False
else:
self.prompt_dialog.close()
for task in self.tasklist.tasks:
self.speak_task(task)
speech.say('Recitation complete.', self.language, self.speech_rate)
def speak_task(self, task):
"""""Recite the provided task"""
if not task:
return
if len(task.tags) > 0:
fmt = "Task number {}, priority: {}, {}, This task has the following tags: {}"
msg = fmt.format(task.id, task.priority, task.note, ' and '.join(task.tags.split()))
else:
fmt = "Task number {}, priority: {}, {}, This task does not have any tags."
msg = fmt.format(task.id, task.priority, task.note)
speech.say(msg, self.language, self.speech_rate)
[1]: http://github.com/robinsiebler/Task-List
Now I have the below and I get the following error: AttributeError: 'TextDelegate' object has no attribute 'process_speak_request
class TextDelegate(object):
def textfield_did_change(self, textfield):
view = textfield.superview
button = view['button_select']
button.enabled = textfield.text != ''
def textfield_should_return(self, textfield):
self.process_speak_request(None) <-- AttributeError: ...
return True
How exactly would I do that? I added the below code to the TextDelegate() function, but it does nothing.
def textfield_should_return(self, textfield):
return True
I have definition like this:
class Task():
last_id = 0
def __init__(self, note, priority, tags=' '):
Task.last_id += 1
self.id = Task.last_id
I use the variable to number tasks in my program. The 1st task will be number 1, the 2nd, number 2, etc. However, if I create 2 tasks, then stop the program and restart the program, the 1st task I create is given the number 3 instead of 1. I can't figure out how to fix this. If I kill Pythonista, I always get the correct numbers, but it is a pain to kill Pythonista between runs.
Thanks! I chose the reload route.
You can see my script at github
It works. I don't know what I was thinking before.
I'm glad that works for him, but for me the original problem remains: How to I set the focus to a TextField or TextView when loading a sheet?
I have a view. On the view, I have a textfield and a button. Until the textfield has text, the button is disabled. Currently, I have to enter text into the textfield and THEN press Enter in order to trigger the textfield action to enable the button.
Is there a way to use the textview_did_end_editing
method to enable the button?
When I try to use the push command after a commit, I get the above mentioned error.
Sadly, the Tab key does not work, at least not in a Pythonista app.
This is my version of 'Hello World'. It is a simple app to keep track of tasks. I added a GUI to it thanks to Pythonista.
I am trying export a folder to Gist. When I do it, I get 422 error code. I don't have a problem exporting a single file.
In the below code, I have a form open. Clicking on the 'search' button loads another form in the 'prompt_search' function. Interacting with that form triggers the 'search_tasks' function. If the results of the search are negative, I want to close the search dialog and display a popover stating as much. However, I get a ValueError when I try to load the last screen. How do I fix this?
def prompt_search(self, sender):
"""Prompt the user for a search string."""
self.search_dialog = ui.load_view('dialogs/search_dialog')
self.search_dialog.present('sheet')
def search_tasks(self, sender):
"""Search the task list for a task whose note or tag contains the user provided search string."""
search_string = self.search_dialog['textfield1'].text.lower()
tasks = self.tasklist.search(search_string)
if tasks:
self.search_dialog.close()
self.show_tasks(sender,tasks=tasks)
else:
self.search_dialog.close()
self.message_dialog = ui.load_view('dialogs/message_dialog')
self.message_dialog['label1'].text = 'There were no tasks containing "{}".'.format(search_string)
self.message_dialog.present('popover', popover_location = (500,500))
I commented out the 2nd self.search_dialog.close()
and I no longer get the error.
'View is already being presented or animation is in progress"