omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. robinsiebler112

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 11
    • Posts 28
    • Best 0
    • Controversial 0
    • Groups 0

    robinsiebler112

    @robinsiebler112

    0
    Reputation
    674
    Profile views
    28
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    robinsiebler112 Unfollow Follow

    Latest posts made by robinsiebler112

    • Create subview in UI Editor

      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
      robinsiebler112
      robinsiebler112
    • Action being triggered twice

      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
      robinsiebler112
      robinsiebler112
    • RE: Action being triggered twice

      Thanks! I got that to work.

      posted in Pythonista
      robinsiebler112
      robinsiebler112
    • RE: Action being triggered twice

      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
      robinsiebler112
      robinsiebler112
    • RE: Action being triggered twice

      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
      robinsiebler112
      robinsiebler112
    • Class/instance variable not set to zero when restarting a Pythonista program

      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
      robinsiebler112
      robinsiebler112
    • RE: Class/instance variable not set to zero when restarting a Pythonista program

      Thanks! I chose the reload route.

      posted in Pythonista
      robinsiebler112
      robinsiebler112
    • RE: Class/instance variable not set to zero when restarting a Pythonista program

      You can see my script at github

      posted in Pythonista
      robinsiebler112
      robinsiebler112
    • RE: How to set the focus on a TextField?

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

      posted in Pythonista
      robinsiebler112
      robinsiebler112
    • RE: How to set the focus on a TextField?

      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
      robinsiebler112
      robinsiebler112