• robinsiebler112

    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!

    posted in Editorial read more
  • robinsiebler112

    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

    posted in Pythonista read more
  • robinsiebler112

    Thanks! I got that to work.

    posted in Pythonista read more
  • robinsiebler112

    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

    posted in Pythonista read more
  • robinsiebler112

    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

    posted in Pythonista read more
  • robinsiebler112

    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.

    posted in Pythonista read more
  • robinsiebler112

    Thanks! I chose the reload route.

    posted in Pythonista read more
  • robinsiebler112

    You can see my script at github

    posted in Pythonista read more
  • robinsiebler112

    It works. I don't know what I was thinking before.

    posted in Pythonista read more
  • robinsiebler112

    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?

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!