def __init__(self, parent): """Create and populate the grid dimensions UI""" tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) gen_label = tk.Label(self, text="Grid size") gen_label.pack(side=tk.TOP) is_valid_int = (self.register(is_valid_integer), '%P') self.cols_entry = tk.Entry(self, validate='key', validatecommand=is_valid_int, width=4) self.rows_entry = tk.Entry(self, validate='key', validatecommand=is_valid_int, width=4) cols_label = tk.Label(self, text="cols by") rows_label = tk.Label(self, text="rows") self.cols_entry.pack(side=tk.LEFT) cols_label.pack(side=tk.LEFT) self.rows_entry.pack(side=tk.LEFT) rows_label.pack(side=tk.LEFT) self.set_default()
def __init__(self, parent, dimensions): tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) # upper frame to hold title and dropdown box labelframe = tk.Frame(self) gen_label = tk.Label(labelframe, text='Neighbourhood:') gen_label.pack(side=tk.LEFT) if dimensions == 1: self.options = 'Default', 'Custom' else: self.options = 'Moore', 'Von Neumann', 'Custom' self.optvar = tk.StringVar(self) self.optvar.set(self.options[0]) self.optvar.trace("w", self.callback) self.optbox = tk.OptionMenu(labelframe, self.optvar, *self.options) self.optbox.config(width=9) self.optbox.pack(side=tk.LEFT) labelframe.pack() # lower frame to hold the interactive selector selframe = tk.Frame(self) self.nhood_selector = _NeighbourhoodSelector( selframe, (self.optvar, self.options), dimensions) self.nhood_selector.pack() selframe.pack()
def __init__(self, parent): tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) label = tk.Label(self, text="Rule number:") label.pack(side=tk.LEFT) is_valid_int = (self.register(is_valid_integer), '%P') self.num_entry = tk.Entry(self, validate='key', validatecommand=is_valid_int, width=4) self.num_entry.pack(side=tk.LEFT) self.set_default()
def __init__(self, parent): """Create and populate the generations ui""" tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) gen_label = tk.Label(self, text="Generations:") gen_label.pack(side=tk.LEFT) is_valid_int = (self.register(is_valid_integer), '%P') self.gen_entry = tk.Entry(self, validate='key', validatecommand=is_valid_int, width=4) self.set_default() self.gen_entry.pack(side=tk.LEFT)
def __init__(self, parent): """Create and populate the wind direction ui""" tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) gen_label = tk.Label( self, text= "Wind direction (1 = N, 2 = E, 3 = S, 4 = W, anything else = no wind):" ) gen_label.pack(side=tk.LEFT) is_valid_int = (self.register(is_valid_integer), '%P') self.gen_entry = tk.Entry(self, validate='key', validatecommand=is_valid_int, width=4) self.set_default() self.gen_entry.pack(side=tk.LEFT)
def __init__(self, parent, ca_config, ca_graph): tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) self.CANVASSIZE = 30 self.ca_config = ca_config self.ca_graph = ca_graph self.states = ca_config.states self.canvas = np.empty((len(self.states)), dtype=object) if self.ca_config.state_colors is None: self.selected_colors = np.empty((len(self.states)), dtype=tuple) # if two states set one to black one to white if len(self.states) == 2: self.selected_colors[0] = self.BLACK[0] self.selected_colors[1] = self.WHITE[0] else: # Otherwise set all to black self.selected_colors.fill(self.DEFAULTCOL[0]) self.ca_config.state_colors = self.selected_colors else: self.selected_colors = np.array(self.ca_config.state_colors, dtype=float) outerframe = tk.Frame(self) for i, state in enumerate(self.states): frame = tk.Frame(outerframe) label = tk.Label(frame, text=state) self.canvas[i] = tk.Canvas( frame, height=self.CANVASSIZE, width=self.CANVASSIZE, background=rgb_to_hex(*self.selected_colors[i]), bd=2, relief=tk.RAISED) # bind the on mouse click function to the colored canvas self.canvas[i].bind( "<Button-1>", lambda e, i=i: self.onclick(e, i)) label.pack(side=tk.LEFT) self.canvas[i].pack(side=tk.RIGHT) frame.pack(side=tk.LEFT) if i % 3 == 2 and not (i == len(self.states) - 1): outerframe.pack() outerframe = tk.Frame(self) outerframe.pack()
def __init__(self, parent, ca_config): """UI element to customise the initial grid""" # superclasses tk.Frame.__init__(self, parent) _ConfigUIComponent.__init__(self) self.parent = parent self.ca_config = ca_config labelframe = tk.Frame(self) label = tk.Label(labelframe, text="Initial grid:") label.pack(side=tk.LEFT) labelframe.pack(fill=tk.BOTH) self.selected = tk.IntVar() optionsframe = tk.Frame(self) # Initial grid options # if 1d then add the center cell option rdo_centercell = None if self.ca_config.dimensions == 1: centerframe = tk.Frame(optionsframe) rdo_centercell = tk.Radiobutton(centerframe, text="Center cell", variable=self.selected, value=2, command=self.set_centercell) rdo_centercell.pack(side=tk.LEFT) centerframe.pack(fill=tk.BOTH) # proportions of states propframe = tk.Frame(optionsframe) rdo_proportions = tk.Radiobutton(propframe, text="% Initialised", variable=self.selected, value=0) btn_proportions = tk.Button(propframe, text="Edit", command=lambda: self.editinitgrid(proportions=True)) rdo_proportions.pack(side=tk.LEFT) btn_proportions.pack(side=tk.LEFT) propframe.pack(fill=tk.BOTH) #map of land initial state #mapframe = tk.Frame(optionsframe) #rdo_proportions = tk.Radiobutton(mapframe, text="Map", # variable=self.selected, value=1) #rdo_proportions.pack(side=tk.LEFT) #mapframe.pack(fill=tk.BOTH) #MAEKE SET DEFAULT WHICH IS A MAP # custom specific cells customframe = tk.Frame(optionsframe) rdo_custom = tk.Radiobutton(customframe, text="Custom", variable=self.selected, value=1) btn_custom = tk.Button(customframe, text="Edit", command=lambda: self.editinitgrid(custom=True)) rdo_custom.pack(side=tk.LEFT) btn_custom.pack(side=tk.LEFT) customframe.pack(fill=tk.BOTH) optionsframe.pack() # keep handle on radio buttons self.radiobuttons = [rdo_proportions, rdo_custom, rdo_centercell] self.set_default()