omz:forum

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

    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 3
    • Posts 12
    • Best 0
    • Controversial 0
    • Groups 0

    crazyfox

    @crazyfox

    0
    Reputation
    538
    Profile views
    12
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    crazyfox Unfollow Follow

    Latest posts made by crazyfox

    • RE: Popover location coordinates for button in table row

      @cvp

      Thank you again for saving my project (and sanity)
      I had read that thread before, but didn’t make the connection.

      Here’s what worked for me:
      I ended up using

      vi = ObjCInstance(b)
      

      Since my object ‘b’ is ui.Button

      Also, the popover location was off by the title bar height. Used GetTitleBarHeight() from here. Adjusted popover padding with help from here.

      I appreciate how helpful this community is. I’m learning a lot.

      posted in Pythonista
      crazyfox
      crazyfox
    • Popover location coordinates for button in table row

      Hi all-

      I’m trying to present a popover triggered by a button in a TableViewCell.
      My underlying table is a TreeNode (from File Picker) and so I can’t use row_height * row index calculation.
      Converting button.center to screen_coordinates is where I’m getting stuck (I think this is how to accomplish the task)

      Any thoughts?

      posted in Pythonista
      crazyfox
      crazyfox
    • RE: Populate ui.Textview from user selections

      @JonB thanks for the suggestions.

      posted in Pythonista
      crazyfox
      crazyfox
    • Populate ui.Textview from user selections

      Hi all,

      I have multiple tableviews presented in navigationview. There is a textview in the root view. I want to collect all user selections (from all nav views) and display in textview.

      1. I'm getting stuck on how to update the textview when a selection is made in deeper sub-levels.

      2. What if the individual tables are generated from separate classes?

      Can you point me towards a strategy to accomplish this task?

      thanks

      import ui
      import console
      
      
      class MyTableView(object):
          def __init__(self, items, name):
              self.items = items
              self.tv = ui.TableView()
              self.tv.name = self.name = name
              self.tv.delegate = self.tv.data_source = self
              
          def tableview_did_select(self, tableview, section, row):
              if self.name == 'House' and self.items[row] == 'Kitchen':
                  print(self.name, row)
                  pushed_view = eval('kitchen_tv.tv')
                  tableview.navigation_view.push_view(pushed_view)
                  # does not work. 
                  # print('pushed view: {}\nnav view: {}'.format(pushed_view.name,pushed_view.navigation_view))
                  # pushed_view.navigation_view.superview.superview['txv'].text += self.items[row] +'\n'
      
              elif self.name == 'Kitchen' and self.items[row] == 'Fruits':
                  pushed_view = eval('fruit_tv.tv')
                  tableview.navigation_view.push_view(pushed_view)
                  # does not work
                  pushed_view.navigation_view.superview.superview['txv'].text += self.items[row]+'\n'
              else:
                  tableview.navigation_view.superview.superview['txv'].text += self.items[row]+'\n' #this works
      
      
      
          def tableview_number_of_sections(self, tableview):
              return 1
      
          def tableview_number_of_rows(self, tableview, section):
              return len(self.items)
      
          def tableview_cell_for_row(self, tableview, section, row):
              cell = ui.TableViewCell()
              cell.text_label.text = self.items[row]
              return cell
      
      
      house_list = 'Bed Bath Kitchen'.split()
      kitchen_list = 'Fruits Vegetables Drinks'.split()
      fruit_list = 'Orange Grape Apple Banana'.split()
      
      house_tv = MyTableView(house_list, 'House')
      kitchen_tv = MyTableView(kitchen_list, 'Kitchen')
      fruit_tv = MyTableView(fruit_list, 'Fruits')
      
      root = ui.View(frame=(0,0,630,330),background_color= '#e3f4ff')
      txv = ui.TextView(name='txv', frame=(320,10,300,300), background_color='white')
      root.add_subview(txv)
      nav_base = ui.View(frame = (10,10,300,300), background_color= '#fafafa') #container for nav
      root.add_subview(nav_base)
      
      nav = ui.NavigationView(house_tv.tv)
      nav_base.add_subview(nav)
      
      root.present('sheet')
      
      posted in Pythonista
      crazyfox
      crazyfox
    • RE: Search text in your scripts via help of popup menu

      @cvp. Helpful! Thank you.

      posted in Pythonista
      crazyfox
      crazyfox
    • RE: Need help with UI, tableviewcell_for_row

      @cvp Thank you for taking the time.
      I think I was making it harder than it should be.

      @crazyfox first, replace load_str by load_view_str 😀

      ...I see it now. Editing/posting error trying include pyui string.

      @crazyfox sincerely, I don't understand your

              cell = ui.TableViewCell()
              cell = MyDropDown(tableview, section, row, frame=(100,0,200,100), items=itemslist).as_cell() 
      

      ...This evolved out of series of TypeErrors and issues with arguments I could not fix elegantly.

      Much more to learn. Thanks again for your help.
      Until next mental block.
      -KP

      posted in Pythonista
      crazyfox
      crazyfox
    • RE: Need help with UI, tableviewcell_for_row

      Thanks @cvp
      This is what I’ve cobbled together (with inspiration from @cvp and @jonb.
      Very crude.

      1. I’m trying to understand how to position UI elements in table view row.
      2. looks like row_height in main table has to tall enough for dropdown views and touch capture.

      I’m an absolute beginner, so any feedback is appreciated.
      Thanks, KP

      [picture link] don’t know why I can’t do inline images. https://imgur.com/n4U3RCf

      
      import ui, console,dialogs
      
      pyui_str = r'''
      [
        {
          "nodes" : [
            {
              "nodes" : [
      
              ],
              "frame" : "{{21, 24}, {480, 287}}",
              "class" : "TableView",
              "attributes" : {
                "flex" : "WH",
                "data_source_items" : "Row 1\nRow 2\nRow 3",
                "name" : "tableview1",
                "frame" : "{{120, 110}, {200, 200}}",
                "data_source_number_of_lines" : 1,
                "class" : "TableView",
                "background_color" : "RGBA(1.0, 1.0, 1.0, 1.0)",
                "data_source_delete_enabled" : true,
                "data_source_font_size" : 18,
                "row_height" : 66,
                "uuid" : "BE2CD45E-DD3C-496F-98C3-93E1222A94AA"
              },
              "selected" : false
            }
          ],
          "frame" : "{{0, 0}, {523, 405}}",
          "class" : "View",
          "attributes" : {
            "enabled" : true,
            "background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)",
            "tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)",
            "border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)",
            "flex" : ""
          },
          "selected" : false
        }
      ]
      '''
      
      
      
      class MyDropDown(ui.View):
          def __init__(self, tableview, section, row, items=[], frame=(0,0,200,200), *args, **kwargs):
              super().__init__(*args, **kwargs)
              self.frame = frame
              self.border_width = 1
              self.border_color = 'red'
              self.background_color='#f6feff'
              
              tf = ui.TextField(name='tf')
              tf.enabled = False
              tf.frame = (self.x,self.y,self.width-32,32)
              tf.border_width= 1
              tf.corner_radius = 5
              self.add_subview(tf)
              self.tf = tf
              
              b = ui.Button()
              b.frame = (tf.x+tf.width,self.y,32,32)
              b.image = ui.Image.named('iob:arrow_down_b_32')
              b.border_width = 1
              b.corner_radius = 5
              b.action = self.b_action
              self.add_subview(b)
              
              tv = ui.TableView()
              tv.frame = (self.x,tf.height,tf.width,self.height-32)
              tv.border_width = 1
              tv.corner_radius = 5
              tv.data_source = ui.ListDataSource(items=items)
              tv.height = min(24*3,24*len(items))
              tv.row_height= 24
              tv.delegate = self
              tv.hidden = True
              self.add_subview(tv)
              self.tv = tv
              
          def b_action(self,sender):
              self.h = self.height
              def showtable():
                  self.border_color = 'green'
                  self.tv.hidden = False
                  self.height = self.tv.height+32
              ui.animate(showtable,.4)
      
          def tableview_did_select(self,tableview, section, row):
              # Called when a row was selected
              data = tableview.data_source.items[row]
              self.tf.text = data
              def hidetable():
                  self.border_color = 'red'
                  self.height = self.h
              ui.animate(hidetable,.4)
              tableview.hidden = True    
      
          def as_cell(self):
              c=ui.TableViewCell()
              self.frame=c.content_view.bounds
              c.content_view.add_subview(self)
              c.set_needs_display()
              return c
              
      class MainView(ui.View):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
              v = ui.load_str(pyui_str)
              t = v['tableview1']
              t.delegate = t.data_source = self
              
              t.row_height = 222
              v.present()
              
              self.content_view = None
              self.tbl = t
              
          def tableview_number_of_rows(self, tableview, section):
              # Return the number of rows in the section
              #return len(self.items)
              return 2
              
          def tableview_cell_for_row(self, tableview, section, row):
              # Create and return a cell for the given section/row
              if row==0:
                  itemslist = ['as','sd','df']
              elif row==1:
                  itemslist = ['wer','qwe','ghj']
                  
              cell = ui.TableViewCell()
              cell = MyDropDown(tableview, section, row, frame=(100,0,200,100), items=itemslist).as_cell()
      
              seg = ui.SegmentedControl(name='segRL')
              seg.segments = ['R','L']
              seg.selected_index = -1
              seg.frame = (0,0,96,32)
              seg.action = self.seg_action
              cell.content_view.add_subview(seg)
      
              tf_stent = ui.TextField(name='tf_stent',placeholder='boo')
              tf_stent.enabled = True
              tf_stent.clear_button_mode = 'while_editing'
              tf_stent.frame = (500,0,60,32)
              tf_stent.border_width= 1
              tf_stent.border_color='blue'
              tf_stent.corner_radius = 5
              cell.content_view.add_subview(tf_stent)
      
              tfl = ui.TextField(name='tfl')
              tfl.enabled = True
              tfl.clear_button_mode = 'while_editing'
              tfl.frame = (seg.width+4,0,120,32)
              tfl.border_width= 1
              tfl.corner_radius = 5
              self.add_subview(tfl)
              self.tfl = tfl
      
              return cell
              
          def change_row_ht(ht=44):
              self.tbl.row_height = ht
              #redraw display
              self.tbl.set_needs_display()
              
          def seg_action(self, sender):
              sideRL = sender.segments[sender.selected_index]
                      
      MainView()
      
      
      posted in Pythonista
      crazyfox
      crazyfox
    • Need help with UI, tableviewcell_for_row

      Hi all,
      Any ideas on recreating the UI seen in Apple Mail rules (attached) or similar(smart mailboxes, etc)? i.e. Expandable table with multiple dropdowns in each row.

      I am populating tableviewcell_for_row with custom UIView class and other standard elements. The layout has been difficult to define and dropdown selections are restricted to row height. I think I can make it work but is not pretty.

      Is there a more elegant way to approach this?

      KP

      https://imgur.com/qzsDEOO

      posted in Pythonista
      crazyfox
      crazyfox
    • RE: IOS 13.3 IPad Pro Keyboard missing snippets menu

      I’m having the same issue.
      iPad Pro 13.3 cannot see snippets button.

      Disappointing as this was a big selling point for me.

      Am I missing a setting somewhere?

      posted in Editorial
      crazyfox
      crazyfox
    • RE: Closing a view from a TextField Delegate

      @BGKirkham
      Thank you. Sorry didn’t mean to hijack your thread.

      @cvp
      It works. Thanks again for pointing me in the right direction.

      posted in Pythonista
      crazyfox
      crazyfox