def enter_entry(self, event): flag = self.flag_by_cb[event.widget] old_level = SlTrace.getLevel(flag) _, flag, text_var = self.data_by_flag[flag] entry_text = text_var.get() new_level = str2val(entry_text, old_level) self.set_trace_level(flag, new_level, change_cb=False) # No select for Entry
def set_val_from_ctl(self, field_name): """ Set ctls value from field Also updates player value properties :field_name: field name """ if not field_name in self.ctls_vars: raise SelectError("No field named %s" % field_name) ctl_var = self.ctls_vars[field_name] if ctl_var is None: raise SelectError("No variable for %s" % field_name) while True: try: value = ctl_var.get() break except: ctl = self.ctls[field_name] ctl_str = ctl.get() ctl_var_type = content_var_type(ctl_var) default_val_str = self.get_prop_val(field_name, None) default_val = str2val(default_val_str, ctl_var_type) sr = SelectInput( master=self, title="GameControl", message=f"Bad format:'{ctl_str}' for {field_name}: ", default=default_val) value = sr.result if value is not None: break self.set_ctl_val(field_name, value) self.set_prop_val(field_name, value)
def validate(self): val_str = self.e1.get() try: self.result = str2val(val_str, self.default) return 1 except SelectErrorInput: messagebox.showwarning( "Bad input", f"Illegal values {val_str}, please try again") return 0
def setLevel(cls, trace_name, level=True): trace_name = trace_name.lower() cls.recordTraceFlag(trace_name, level=level) flag_key = cls.getTraceFlagKey(trace_name) cls.setProperty(flag_key, level) if isinstance(level, str): try: level = str2bool(level) except: try: level = str2val(level, 0) except: pass # Leave unchanged if trace_name == "all": cls.traceAll = level else: cls.traceFlags[trace_name] = level
def add_player_prop(self, prop_fields, snapshot=None, in_section=False): """ Add player property to given section :prop_fields: list of property keys - whole key :snapshot: properties into which we add player default: current properties :in_section: in a section (e.g. "undo") default: False """ if snapshot is None: snapshot = SlTrace.getDefaultProps() if in_section: player_idx = PlayerProp.SECT_PLAYER_NUM_IDX sect_num = prop_fields[PlayerProp.SECT_NUM_IDX] else: player_idx = PlayerProp.PLAYER_NUM_IDX sect_num = None player_info = self.get_sect_part(sect_num) player_id_str = prop_fields[player_idx] if re.match(r'\d+$', player_id_str) is None: return # Not a player num player_id = int(player_id_str) player = player_info.get_player(player_id) # Create player, if not there prop_key = ".".join(prop_fields) player_attr = prop_fields[player_idx+1] # Just after id prop_val = snapshot.getProperty(prop_key, None) if player_attr == "move": player_attr = "position" if not hasattr(player, player_attr): raise SelectError(f"Unrecognized player attribute {player_attr} in {prop_val}") player_val = getattr(player, player_attr) try: property_value = str2val(prop_val, player_val) except: SlTrace.lg(f"Can't convert {prop_val} in prop field {player_attr} to type: {type(player_val)}") raise SelectError(f"Bad Input: {'.'.join(prop_fields)}") setattr(player, player_attr, property_value) if player_attr == "color": player.icolor = player.color elif player_attr == "color_bg": player.icolor2 = player.color_bg