• @Phuket2 hehe thanks anyway. Really glad fir all the help

  • @Webmaster4o , lol does not surprise me. But let's face it a lot of little treasures in Pythonista.
    I wish they could all be documented, but I understand why they are not. It would take a big chunk out of the development time. I can't remember how long I have had Pythonista now, but I am astounded how much it has evolved in that short time.

  • Hmmm, I really think this is a nice update to what I posted here. I understand some may not think its good. Not sure.

    But by using the ViewWalker Class I posted the other day here

    And adding self.dict.update(ViewWalker(self).as_dict()) to the PYUIViewer class so you can access all your objects with dot notation rather than self['switch1'] for example.

    There is a limitation and that is your instance attrs and all your pyui objects have to have unique names. It's explained in the ViewWalker link. Hmmm, I am not sure it's really such a limitation. In a real app you would want this anyway.

    But if you load a pyui file in this manner and all your names are unique you have dot notation access to the objects as well as they are all accessible from the root level.

    I guess it would be nice to offer the same functionality (dot notation) in a hierarchical way instead of the flattened out way I am doing here.
    Hmmm, not sure I can figure that out just yet, @jonB, maybe that's something for you 😬😬
    Still nicer to do self.firstView.SecondView.ThirdView.switch1 = True
    Then ...
    self['firstView']...['switch1'].value = True

    I am not entirely sure why @omz didn't add this in somehow.

    Ok, I think it's exciting....maybe I am clapping with one hand 😱🎉🎉🎉🎉

    class PYUIViewer(ui.View): # this acts as a normal Custom ui.View class # the root view of the class is the pyui file read in def __init__(self, pyui_fn, *args, **kwargs): ui.load_view(pyui_fn, bindings={'MyClass': WrapInstance(self), 'self': self}) # call after so our kwargs modify attrs super().__init__(*args, **kwargs) # use the ViewWalker to get a dict of all the view controls/etc self.__dict__.update(ViewWalker(self).as_dict()) # i have a ui.Switch named switch1 in pyui file. # now i can refer to it directly, rather than use string # subscripts ie. self['switch1'] # but if could be self['v1']['sv1']['sv2']['switch1'] self['switch1'].value = False # conventional way self.switch1.value = False # after updating our dict
  • MonthView is the ten lines or less version. It is not nearly as cool as your code but there are limits to what you can achieve in just ten lines.

  • @JonB , revised version of the test code. is a lot of extra just for testing. But so clean now for the timer part. Also a lot more accurate timings . Thanks again

    import ui import datetime, time class Test (ui.View): def __init__(self, duration = 1.0): self.frame = (0,0,300,300) self.background_color = 'white' btn = ui.Button(title = 'start') btn.width = 100 btn.border_width = .5 # hmmmmmmm, center does not work ( as you would expect it too ) # eg. btn.center = self.center btn.center = (self.center[0], self.center[1] - (44/2)) btn.action = self.JonB_way self.fire_obj = btn self.add_subview(btn) self.auto_close_duration = float(duration) self.start = None def JonB_way(self, sender): self.fire_obj.enabled = False self.start = datetime.datetime.now() ui.delay(self.fire_delay, self.auto_close_duration) def fire_delay(self): self.name = str(datetime.datetime.now() - self.start) self.fire_obj.enabled = True
Internal error.

Oops! Looks like something went wrong!