def loadParameters(RDK=None): if RDK is None: RDK = Robolink() global RADIUS global PARENT radius = RDK.getParam(PARAM_RADIUS, True) if radius is not None and radius != '': RADIUS = float(radius) parent_name = RDK.getParam(PARAM_PARENT_NAME, True) if parent_name is not None and parent_name != '': item = RDK.Item(parent_name) if item.Valid() and item.Name() == parent_name: PARENT = item if PARENT is None: PARENT = RDK.ActiveStation()
def loadParameters(RDK=None): if RDK is None: RDK = Robolink() global BOX_SIZE_XYZ global USE_METRIC global PARENT global CONV_PARENT size_x = RDK.getParam(PARAM_BOX_X, True) if size_x is not None and size_x != '': BOX_SIZE_XYZ[0] = float(size_x) size_y = RDK.getParam(PARAM_BOX_Y, True) if size_y is not None and size_y != '': BOX_SIZE_XYZ[1] = float(size_y) size_z = RDK.getParam(PARAM_BOX_Z, True) if size_z is not None and size_z != '': BOX_SIZE_XYZ[2] = float(size_z) metric = RDK.getParam(PARAM_UNITS, True) if metric is not None and metric != '': USE_METRIC = bool(metric == 'True') parent_name = RDK.getParam(PARAM_PARENT_NAME, True) if parent_name is not None and parent_name != '': item = RDK.Item(parent_name) if item.Valid() and item.Name() == parent_name: PARENT = item if PARENT is None: PARENT = RDK.ActiveStation() conv_parent_name = RDK.getParam(PARAM_CONV_PARENT_NAME, True) if conv_parent_name is not None and conv_parent_name != '': item = RDK.Item(conv_parent_name) if item.Valid() and item.Name() == conv_parent_name: CONV_PARENT = item
class SpawnBoxEditor: SIZE_SPINBOX_FROM = 0.1 SIZE_SPINBOX_TO = 10000 SIZE_SPINBOX_INCREMENT = 0.5 SIZE_SPINBOX_FORMAT = "%0.2f" WIDTH_ENTRY = 32 STICKY = tk.NSEW def __init__(self, RDK=None) -> None: self.RDK = RDK if self.RDK is None: self.RDK = Robolink() self.root = tk.Tk() self.unit_options = tk.IntVar() self.units_format = '' self.box_length = tk.DoubleVar(value=0) self.box_width = tk.DoubleVar(value=0) self.box_height = tk.DoubleVar(value=0) self.box_length_text = tk.StringVar(value='') self.box_width_text = tk.StringVar(value='') self.box_height_text = tk.StringVar(value='') self.parent_name_text = tk.StringVar(value='') self.conv_parent_name_text = tk.StringVar(value='') sbt.loadParameters(self.RDK) self.init() def init(self): self.unit_options.set(int(sbt.USE_METRIC)) self.units_format = '(mm)' if sbt.USE_METRIC else '(in)' self.box_length.set(sbt.BOX_SIZE_XYZ[0]) self.box_width.set(sbt.BOX_SIZE_XYZ[1]) self.box_height.set(sbt.BOX_SIZE_XYZ[2]) self.box_length_text.set('Box Length ' + self.units_format) self.box_width_text.set('Box Width ' + self.units_format) self.box_height_text.set('Box Height ' + self.units_format) self.parent_name_text.set(sbt.PARENT.Name() if sbt.PARENT is not None else 'Unset') self.conv_parent_name_text.set(sbt.CONV_PARENT.Name() if sbt.CONV_PARENT is not None else 'Unset') def switchUnitsFormat(self): use_metric = self.unit_options.get() == 1 if use_metric != sbt.USE_METRIC: # Convert units factor = 25.4 # in to mm if sbt.USE_METRIC and not use_metric: factor = 1 / 25.4 # mm to in self.box_length.set(self.box_length.get() * factor) self.box_width.set(self.box_width.get() * factor) self.box_height.set(self.box_height.get() * factor) sbt.USE_METRIC = use_metric def setBoxDimensions(self): sbt.BOX_SIZE_XYZ[0] = self.box_length.get() sbt.BOX_SIZE_XYZ[1] = self.box_width.get() sbt.BOX_SIZE_XYZ[2] = self.box_height.get() def selectParent(self): self.RDK.setSelection([]) choices = self.RDK.ItemList(ITEM_TYPE_FRAME) choices.append(self.RDK.ActiveStation()) parent = self.RDK.ItemUserPick('Select spawning location', choices) if parent is not None and parent.Valid(): sbt.PARENT = parent self.parent_name_text.set(sbt.PARENT.Name()) def selectConvParent(self): self.RDK.setSelection([]) conv_parent = self.RDK.ItemUserPick('Select conveyor relocation', ITEM_TYPE_FRAME) if conv_parent is not None and conv_parent.Valid(): sbt.CONV_PARENT = conv_parent self.conv_parent_name_text.set(sbt.CONV_PARENT.Name()) def clearConvParent(self): sbt.CONV_PARENT = None self.conv_parent_name_text.set('Unset') def saveAndClose(self): self.setBoxDimensions() # This is not called if user entered manually sbt.setParameters(self.RDK) self.root.destroy() def loadDefaults(self): sbt.loadDefaults() self.init() def show(self): # Generate the main window frame = tk.Frame(self.root) frame.pack(side=tk.TOP, fill=tk.X, padx=1, pady=1) row = -1 # Unit selection row += 1 l_units = tk.Label(frame, text='Units', anchor='w') rb_box_units_mm = tk.Radiobutton(frame, text='mm', variable=self.unit_options, value=1, command=self.switchUnitsFormat) rb_box_units_in = tk.Radiobutton(frame, text='in', variable=self.unit_options, value=0, command=self.switchUnitsFormat) l_units.grid(column=0, row=row, sticky=self.STICKY) rb_box_units_mm.grid(column=1, columnspan=1, row=row, sticky=tk.NW) rb_box_units_in.grid(column=2, columnspan=3, row=row, sticky=tk.NW) # Box length (x) row += 1 l_box_length = tk.Label(frame, textvariable=self.box_length_text, anchor='w') sb_box_length = tk.Spinbox( frame, textvariable=self.box_length, from_=self.SIZE_SPINBOX_FROM, to=self.SIZE_SPINBOX_TO, increment=self.SIZE_SPINBOX_INCREMENT, format=self.SIZE_SPINBOX_FORMAT, command=self.setBoxDimensions, ) l_box_length.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) sb_box_length.grid(column=1, columnspan=3, row=row, sticky=self.STICKY) # Box width (y) row += 1 l_box_width = tk.Label(frame, textvariable=self.box_width_text, anchor='w') sb_box_width = tk.Spinbox( frame, textvariable=self.box_width, from_=self.SIZE_SPINBOX_FROM, to=self.SIZE_SPINBOX_TO, increment=self.SIZE_SPINBOX_INCREMENT, format=self.SIZE_SPINBOX_FORMAT, command=self.setBoxDimensions, ) l_box_width.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) sb_box_width.grid(column=1, columnspan=3, row=row, sticky=self.STICKY) # Box height (z) row += 1 l_box_height = tk.Label(frame, textvariable=self.box_height_text, anchor='w') sb_box_height = tk.Spinbox( frame, textvariable=self.box_height, from_=self.SIZE_SPINBOX_FROM, to=self.SIZE_SPINBOX_TO, increment=self.SIZE_SPINBOX_INCREMENT, format=self.SIZE_SPINBOX_FORMAT, command=self.setBoxDimensions, ) l_box_height.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) sb_box_height.grid(column=1, columnspan=3, row=row, sticky=self.STICKY) # Spawn location row += 1 l_parent = tk.Label(frame, text='Spawn location (Item)', anchor='w') e_parent = tk.Entry(frame, textvariable=self.parent_name_text, state='readonly', width=self.WIDTH_ENTRY) b_parent = tk.Button(frame, text='Select', command=self.selectParent) l_parent.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) e_parent.grid(column=1, columnspan=1, row=row, sticky=self.STICKY) b_parent.grid(column=2, columnspan=2, row=row, sticky=self.STICKY, padx=1, pady=1) # Conveyor remap row += 1 l_conv_parent = tk.Label(frame, text='Conveyor relocation (Item)', anchor='w') e_conv_parent = tk.Entry(frame, textvariable=self.conv_parent_name_text, state='readonly', width=self.WIDTH_ENTRY) b_conv_parent = tk.Button(frame, text='Select', command=self.selectConvParent) b_conv_parent_clr = tk.Button(frame, text='Clear', command=self.clearConvParent) l_conv_parent.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) e_conv_parent.grid(column=1, columnspan=1, row=row, sticky=self.STICKY) b_conv_parent.grid(column=2, columnspan=1, row=row, sticky=self.STICKY, padx=1, pady=1) b_conv_parent_clr.grid(column=3, columnspan=1, row=row, sticky=self.STICKY, padx=1, pady=1) # User controls control_row = tk.Frame(self.root) control_row.pack(side=tk.BOTTOM, padx=1, pady=1) # Creating the OK button b_ok = tk.Button(control_row, text='OK', command=self.saveAndClose, width=12) b_ok.grid(column=0, row=0, sticky=self.STICKY, padx=1, pady=1) # Creating the Cancel button b_cancel = tk.Button(control_row, text='Cancel', command=self.root.destroy, width=12) b_cancel.grid(column=1, row=0, sticky=self.STICKY, padx=1, pady=1) # Creating the Default button b_defaults = tk.Button(control_row, text='Defaults', command=self.loadDefaults, width=12) b_defaults.grid(column=2, row=0, sticky=self.STICKY, padx=1, pady=1) # Set window name window_title = "Box Spawner Editor" self.root.title(window_title) # Logo icon_path = getPathIcon() if os.path.exists(icon_path): self.root.iconbitmap(icon_path) self.root.resizable(0, 0) self.root.mainloop()
class ObjectDeleterEditor: SIZE_SPINBOX_FROM = 0.1 SIZE_SPINBOX_TO = 10000 SIZE_SPINBOX_INCREMENT = 1 SIZE_SPINBOX_FORMAT = "%0.2f" WIDTH_ENTRY = 32 STICKY = tk.NSEW def __init__(self, RDK=None) -> None: self.RDK = RDK if self.RDK is None: self.RDK = Robolink() self.root = tk.Tk() self.radius = tk.DoubleVar(value=0) self.parent_name_text = tk.StringVar( value=odt.PARENT.Name() if odt.PARENT is not None else 'Unset') odt.loadParameters(self.RDK) self.init() def init(self): self.radius.set(odt.RADIUS) self.parent_name_text.set( odt.PARENT.Name() if odt.PARENT is not None else 'Unset') def setRadius(self): odt.RADIUS = self.radius.get() def selectParent(self): self.RDK.setSelection([]) choices = self.RDK.ItemList(ITEM_TYPE_FRAME) choices.append(self.RDK.ActiveStation()) parent = self.RDK.ItemUserPick('Select Deleter location', choices) if parent is not None and parent.Valid(): odt.PARENT = parent self.parent_name_text.set(odt.PARENT.Name()) def saveAndClose(self): self.setRadius() odt.setParameters(self.RDK) self.root.destroy() def loadDefaults(self): odt.loadDefaults() self.init() def show(self): # Generate the main window frame = tk.Frame(self.root) frame.pack(side=tk.TOP, fill=tk.X, padx=1, pady=1) row = -1 # Radius row += 1 l_radius = tk.Label(frame, text='Radius (mm)', anchor='w') sb_radius = tk.Spinbox( frame, textvariable=self.radius, from_=self.SIZE_SPINBOX_FROM, to=self.SIZE_SPINBOX_TO, increment=self.SIZE_SPINBOX_INCREMENT, format=self.SIZE_SPINBOX_FORMAT, command=self.setRadius, ) l_radius.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) sb_radius.grid(column=1, columnspan=3, row=row, sticky=self.STICKY) # Delete location row += 1 l_parent = tk.Label(frame, text='Location (Item)', anchor='w') e_parent = tk.Entry(frame, textvariable=self.parent_name_text, state='readonly', width=self.WIDTH_ENTRY) b_parent = tk.Button(frame, text='Select', command=self.selectParent, padx=1, pady=1) l_parent.grid(column=0, columnspan=1, row=row, sticky=self.STICKY) e_parent.grid(column=1, columnspan=1, row=row, sticky=self.STICKY) b_parent.grid(column=2, columnspan=2, row=row, sticky=self.STICKY, padx=1, pady=1) # User controls control_row = tk.Frame(self.root) control_row.pack(side=tk.BOTTOM, padx=1, pady=1) # Creating the OK button b_ok = tk.Button(control_row, text='OK', command=self.saveAndClose, width=12) b_ok.grid(column=0, row=0, sticky=self.STICKY, padx=1, pady=1) # Creating the Cancel button b_cancel = tk.Button(control_row, text='Cancel', command=self.root.destroy, width=12) b_cancel.grid(column=1, row=0, sticky=self.STICKY, padx=1, pady=1) # Creating the Default button b_defaults = tk.Button(control_row, text='Defaults', command=self.loadDefaults, width=12) b_defaults.grid(column=2, row=0, sticky=self.STICKY, padx=1, pady=1) # Set window name window_title = "Object Deleter Editor" self.root.title(window_title) # Logo icon_path = getPathIcon() if os.path.exists(icon_path): self.root.iconbitmap(icon_path) self.root.resizable(0, 0) self.root.mainloop()