• JonB

    Looks like there is a property on the view controller

    https://www.hackingwithswift.com/example-code/uikit/how-to-disable-interactive-swipe-to-dismiss-for-view-controllers

    @cvp, do you recall if we have access to the view controller before it is presented?

    posted in Pythonista read more
  • JonB

    it sounds like you don't even need multiple columns, you just need a title and a subtitle. more complex cells you can design yourself, using the content_view.

    This example shows the four cell styles -- value1, value2, subtitle, and default. For bonus points, you would have the tableview_cell_for_row , etc, actually look up durectly from your sql database .

    import ui,sys
    
    PY3 = sys.version_info[0] >= 3
    if PY3:
        basestring = str
        
    class DetailTextDataSource(ui.ListDataSource):
        def __init__(self, items, style):
            self.style=style
            ui.ListDataSource.__init__(self,items)
        def tableview_cell_for_row(self,tv,section,row):
            item = self.items[row]
            cell = ui.TableViewCell(self.style)
            cell.text_label.number_of_lines = self.number_of_lines
            if isinstance(item, dict):
                cell.text_label.text = item.get('title', '')
                try:
                    cell.detail_text_label.text = item.get('subtitle', '')
                except AttributeError:
                    pass
                img = item.get('image', None)
                if img:
                    try:
                        if isinstance(img, basestring):
                            cell.image_view.image = ui.Image.named(img)
                        elif isinstance(img, ui.Image):
                            cell.image_view.image = img
                    except AttributeError:
                        pass
                accessory = item.get('accessory_type', 'none')
                cell.accessory_type = accessory
            elif isinstance(item,tuple):
                cell.text_label.text = str(item[0])
                cell.detail_text_label.text = str(item[1])
            else:
                cell.text_label.text = str(item)
            if self.text_color:
                cell.text_label.text_color = self.text_color
            if self.highlight_color:
                bg_view = ui.View(background_color=self.highlight_color)
                cell.selected_background_view = bg_view
            if self.font:
                cell.text_label.font = self.font
            return cell
            
    items=[{'title':'Strawberries','subtitle':'3.99','image':'plf:Enemy_Ladybug'},
            {'title':'Blueberries','subtitle':'2.99','image':'plf:Enemy_Snail_shell'},
            {'title':'Honey','subtitle':'4.50','image':'plf:Enemy_Bee'},
            {'title':'Fresh fish','subtitle':'6/lb','image':'plf:Enemy_FishGreen'},
    ]
    
    mainview=ui.View(frame=(0,0,1024,768))
    S1=DetailTextDataSource(items,'value1')
    t=ui.TableView(frame=(0,0,300,600))
    t.data_source=S1
    t.delegate=S1
    mainview.add_subview(t)
    
    S2=DetailTextDataSource(items,'value2')
    t2=ui.TableView(frame=(310,0,200,600))
    t2.data_source=S2
    t2.delegate=S2
    mainview.add_subview(t2)
    
    S3=DetailTextDataSource(items,'subtitle')
    t3=ui.TableView(frame=(520,0,200,600))
    t3.data_source=S3
    t3.delegate=S3
    mainview.add_subview(t3)
    
    S4=DetailTextDataSource(items,'default')
    t4=ui.TableView(frame=(740,0,200,600))
    t4.data_source=S4
    t4.delegate=S4
    mainview.add_subview(t4)
    
    mainview.present()
    

    posted in Pythonista read more
  • JonB

    @DavinE have you used TableViews before? It really seems like you are trying to make a tableview by yourself by using. Scrollview and labels.

    Tableview takes care of most of the hard positioning bits, and you just need to handle each cell.

    posted in Pythonista read more
  • JonB

    something like this, for simple reading.
    notice that you call read, but the actual access to c.value is in update_value -- so your code just needs to be asynchronous, responding to value updates there.

    if you need synchronous access, it becomes harder, since your main code needs to wait until the value has been updated. which can be tricky because i dont think there is a guarantee that when you request a read, that a read actually happens by the device, etc.

    CHPROPS={cb.CH_PROP_BROADCAST:'Broadcast',
             cb.CH_PROP_READ:'Read',
             cb.CH_PROP_WRITE_WITHOUT_RESPONSE:'WriteWithoutResponse',
             cb.CH_PROP_WRITE:'Write',
             cb.CH_PROP_NOTIFY:'Notify',
             cb.CH_PROP_INDICATE:'Indicate',
             cb.CH_PROP_AUTHENTICATED_SIGNED_WRITES:'AuthSignedWrites',
             cb.CH_PROP_EXTENDED_PROPERTIES:'ExtendedProps', 
             cb.CH_PROP_NOTIFY_ENCRYPTION_REQUIRED:'NotifyEncrypReq',
             cb.CH_PROP_INDICATE_ENCRYPTION_REQUIRED:'IndicateEncrReq'}
    
    
    #...inside your manager...
    
       def did_discover_characteristics(self, s, error):
          # You can now read or write the characteristic's value
          props=[]
          for propbit,name in CHPROPS.items():
             if c.properties & propbit:
                props.append(name)
          print(f'-UUID:{c.uuid} PROPS:{",".join(props)}')
          if cb.CH_PROP_READ & c.properties:
             self.peripheral.read_characteristic_value(c)
    
       def did_update_value(self, c):
          '''called when characteristic is read'''
          print(f'-UUID:{c.uuid} + VALUE:{c.value}')
    

    posted in Pythonista read more
  • JonB

    is there a service.read_characteristic_value? or is it under peripheral? also, the read command does not return a value, you must implement did_update_value.

    Peripheral.read_characteristic_value(characteristic)
    Retrieve the value of the given Characteristic. When the value has been read, your central delegate will receive a did_update_value callback, at which point you can access the value with the characteristics’s value attribute. Not all characteristics are guaranteed to have a readable value.

    If you need synchronous access like this, perhaps, implement a semaphore system -- update_value sets a semaphore that the did_discover_characteristics blocks on ( you do maybe need to make sure did_discover_characteristics uses @in_background)

    posted in Pythonista read more
  • JonB

    Looks like maybe you are missing an indent - you wAnt to call discover_characteristics for each service. Your code would only be the last.

    Should be:

    for s in p.services:
       print("-" + str(s.uuid))
       p.discover_characteristics(s)
    

    posted in Pythonista read more
  • JonB

    @robStacks what seems to be the problem?

    posted in Pythonista read more
  • JonB

    It seems to me that your options are to either change the font smaller, or text wrap it so it takes up more lines, fewer columns. The textwrap module has a wrap function that is good for limiting text to some number of columns. I'm sure there is probably a iOS objc way to do the same, within the text view inside the button...

    Buttons with really long text are not really the way iOS designs are supposed to be made... Usually there is a better way.

    posted in Pythonista read more
  • JonB

    Maybe a few more words description, or context might be helpful!

    posted in Pythonista read more
  • JonB

    Yes......

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!