Author | Message |
---|---|
rabbott
Posts: 1649
|
Posted 21:44 Feb 18, 2020 |
Ricardo Medina had a good suggestion today. He said that since we have a Inevitably, what seemed like a relatively simple change became a bit more complex. For one thing,
@staticmethod
def gui_get(key):
value = SimEngine.values.get(key, None)
return int(value) if isinstance(value, float) and value == int(value) else value
@staticmethod
def gui_set(key, **kwargs):
widget = gui.WINDOW[key]
widget.update(**kwargs)
The method The method gui_set is a bit more complex. It is used instead of
gui.WINDOW['rows'].update(value=len(self.ca_lines))
on the last line of __init__ in ca_outline, one now writes,
SimEngine.gui_set('rows', value=len(self.ca_lines))
So, in practice, there is little difference between using If you look at the implementation of I believe I've updated all the code on GitHub to reflect this change. (In making the changes I commented out the lines that use
There is a second relatively minor change. Instead of So instead of def handle_event_and_values(self): """ This is called when a GUI widget is changed and isn't handled by the system. The key of the widget that changed is the event. If the changed widget has to do with the rule number or switches, make them all consistent. This is the function that will trigger all the code you write this week """ # Handle color change requests. super().handle_event_and_values() event = SimEngine.get_gui_event() if event in ['Rule_nbr'] + CA_World.bin_0_to_7: self.make_switches_and_rule_nbr_consistent()
def handle_event(self, event): """ This is called when a GUI widget is changed and isn't handled by the system. The key of the widget that changed is the event. If the changed widget has to do with the rule number or switches, make them all consistent. This is the function that will trigger all the code you write this week """ # Handle color change requests. super().handle_event(event) if event in ['Rule_nbr'] + CA_World.bin_0_to_7: self.make_switches_and_rule_nbr_consistent()
The preceding discussion is probably longer than most of you care about. (In practice, the actual changes are relatively minor.) But I wanted to show you the kind of thought one should put into one's code--whether or not you agree with the actual decisions I made about these specific issues. (If you disagree, what alternative would you suggest? After all, this started with a suggestion by Ricardo Medina.)
Last edited by rabbott at
08:31 Feb 19, 2020.
|