예제 #1
0
    def __init__(self, master, db_name):
        Toplevel.__init__(self, master)
        self.master = master
        self.db_name = db_name
        self.db_location = db_location
        self.class_name = self.db_name[:-2].capitalize()
        pretty_class_str = getattr(__import__(self.class_name.lower()), self.class_name).pretty_str
        self.title(pretty_class_str.capitalize() + " Database")
        self.mode = 'view'
        self.overwrite_decision = 'cancel'

        # Place window
        xpos, ypos = get_win_place(self)
        self.geometry('+%d+%d' % (xpos, ypos))

        # Create subframes within database management window
        self.db_frame = DatabaseFrame(self)
        self.button_frame = ttk.Frame(self, padding=5)

        # Create add, edit, close, cancel, and save changes buttons in button frame
        self.add_button = ttk.Button(self.button_frame, text='Add', command=self.launch_add_object_window)
        self.edit_button = ttk.Button(self.button_frame, text='Edit', command=self.edit_objects)
        self.close_button = ttk.Button(self.button_frame, text='Close', command=self.close_window)
        self.cancel_button = ttk.Button(self.button_frame, text='Cancel', command=self.cancel_edit)
        self.save_changes_button = ttk.Button(self.button_frame, text='Save Changes', command=self.save_edits)
        self.delete_button = ttk.Button(self.button_frame, text='Delete Object', command=self.delete_obj)

        # Create edit message label in button frame
        self.edit_message = StringVar()
        self.edit_message_label = ttk.Label(self.button_frame, textvariable=self.edit_message)

        # Pack button frame widgets
        self.close_button.pack(side=RIGHT)
        self.edit_button.pack(side=RIGHT)
        self.add_button.pack(side=RIGHT)
        self.edit_message_label.pack(side=LEFT)

        # Pack subframes
        self.db_frame.pack(fill=BOTH, expand=YES)
        self.button_frame.pack(fill=X)

        # Handle resizing
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
예제 #2
0
    def __init__(self, master):
        Toplevel.__init__(self, master)
        self.db_name = master.db_name
        self.db_location = master.db_location
        self.class_name = master.class_name
        pretty_class_str = getattr(__import__(self.class_name.lower()), self.class_name).pretty_str
        self.title("Add to %s database" % pretty_class_str)

        # Place window
        xpos, ypos = get_win_place(self)
        self.geometry('+%d+%d' % (xpos, ypos))

        # Create subframes
        self.entry_frame, self.object_info = \
            getattr(__import__(self.class_name.lower()), self.class_name).obj_input_frame(self)
        self.button_frame = ttk.Frame(self, padding=5)

        # Create Save and Close buttons and add window information indicator
        self.overwrite_decision = 'cancel'  # Instance variable used as a global between self and OverwriteConfirm()
        self.add_button = ttk.Button(self.button_frame, text='Add', command=self.add_obj_to_database)
        self.close_button = ttk.Button(self.button_frame, text='Close', command=self.close_window)
        self.indicator_var = StringVar()
        self.add_indicator = ttk.Label(self.button_frame, textvariable=self.indicator_var)

        # Pack Save and close buttons and add object indicator
        self.close_button.pack(side=RIGHT)
        self.add_button.pack(side=RIGHT)
        self.add_indicator.pack(side=LEFT)

        # Pack subframes
        self.entry_frame.pack(fill=BOTH, expand=YES)
        self.button_frame.pack(fill=X)

        # Handle resizing
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        self.protocol('WM_DELETE_WINDOW', self.close_window)
예제 #3
0
    def __init__(self, master, message_text):
        Toplevel.__init__(self, master)
        self.master = master
        self.resizable(width=FALSE, height=FALSE)

        # Place window
        xpos, ypos = get_win_place(self)
        self.geometry('+%d+%d' % (xpos, ypos))

        self.mainframe = ttk.Frame(self, padding=5)
        self.mainframe.pack()

        # Create confirmation message, replace confirmation button, and cancel button
        self.message_text = message_text
        self.message = ttk.Label(self.mainframe, text=self.message_text, wraplength=300)
        self.replace_button = ttk.Button(self.mainframe, text='Confirm',
                                         command=lambda: self.overwrite_decision('confirmed'))
        self.cancel_button = ttk.Button(self.mainframe, text='Cancel',
                                        command=lambda: self.overwrite_decision('cancel'))

        # Grid widgets
        self.message.pack(expand=YES, padx=15, pady=5)
        self.replace_button.pack(side=RIGHT)
        self.cancel_button.pack(side=RIGHT)
예제 #4
0
    def __init__(self, master, mode):
        """
        This class is a Toplevel window which replaces the standard AddObjectWindow for the case of propeller/motor
        combinations. The structure of the class's attributes are significantly different from those of other
        components, therefore a new window is necessary.

        The mode input can either be mode = 'add' or mode = 'edit', depending on what button was pressed in the database
        management window.
        """
        Toplevel.__init__(self, master)
        self.mode = mode
        if self.mode == 'add':
            self.title("Add to Prop/Motor Combo Database")
        else:
            self.title("Edit Prop/Motor Object")
        self.db_name = 'propmotorcombodb'
        self.db_location = master.db_location
        self.class_name = 'Propmotorcombo'
        self.overwrite_decision = 'cancel'

        # Place window
        xpos, ypos = get_win_place(self)
        self.geometry('+%d+%d' % (xpos, ypos))

        # Important step. If the mode is edit, retrieve the selected prop/motor combo from the database window
        if self.mode == 'edit':
            self.current_obj_name = self.master.db_frame.current_object_selection.get()
            db = shelve.open(self.db_location+self.db_name)
            self.obj_for_edit = db[self.current_obj_name]
            db.close()

        # Create internal frames
        self.add_vector_frame = AddPMComboVectorFrame(self)
        self.misc_entry_frame = ttk.Frame(self, padding=5)
        self.button_frame = ttk.Frame(self, padding=5)

        # Create add and cancel buttons (for add mode) and save changes button (for edit mode) + indicator message label
        self.indicator_var = StringVar()
        self.indicator_label = ttk.Label(self.button_frame, textvariable=self.indicator_var)
        self.update()
        self.indicator_var.set("Enter motor/propeller combo data in the spreadsheet.")
        self.add_button = ttk.Button(self.button_frame, text='Add', command=self.add_obj_to_database)
        self.save_changes_button = ttk.Button(self.button_frame, text='Save Changes', command=self.add_obj_to_database)
        self.cancel_button = ttk.Button(self.button_frame, text='Cancel', command=self.close_window)
        self.delete_obj_button = ttk.Button(self.button_frame, text='Delete Object',
                                            command=self.delete_obj_from_database)

        # Create motor database and propeller databases
        self.motor_db = shelve.open(self.db_location+'motordb')
        self.prop_db = shelve.open(self.db_location+'propellerdb')

        # Create widgets in misc entry frame
        self.motor_label = ttk.Label(self.misc_entry_frame, text='Select Motor')
        self.motor_selected = StringVar()
        self.motor_cb = ttk.Combobox(self.misc_entry_frame, textvariable=self.motor_selected,
                                     values=self.motor_db.keys(), state='readonly', width=len(max(self.motor_db.keys(),
                                                                                              key=len))+1)
        if self.mode == 'edit':
            self.motor_cb.current(self.motor_db.keys().index(self.obj_for_edit.motor.name))
        else:
            self.motor_cb.current(0)
        self.motor_db.close()

        self.prop_label = ttk.Label(self.misc_entry_frame, text='Select Propeller')
        self.prop_selected = StringVar()
        self.prop_cb = ttk.Combobox(self.misc_entry_frame, textvariable=self.prop_selected, values=self.prop_db.keys(),
                                    state='readonly', width=len(max(self.prop_db.keys(), key=len))+1)
        if self.mode == 'edit':
            self.prop_cb.current(self.prop_db.keys().index(self.obj_for_edit.prop.name))
        else:
            self.prop_cb.current(0)
        self.prop_db.close()

        self.battery_voltage_label = ttk.Label(self.misc_entry_frame, text='Test Battery Voltage (V)')
        self.battery_voltage = StringVar()
        self.battery_voltage_entry = ttk.Entry(self.misc_entry_frame, textvariable=self.battery_voltage, width=8)
        if self.mode == 'edit':
            self.battery_voltage.set(self.obj_for_edit.test_bat_volt_rating['value'])

        # Grid widgets in button frame
        self.indicator_label.pack(side=LEFT)
        self.cancel_button.pack(side=RIGHT)
        if self.mode == 'add':
            self.add_button.pack(side=RIGHT)
        else:
            self.delete_obj_button.pack(side=RIGHT)
            self.save_changes_button.pack(side=RIGHT)

        # Grid widgets in misc entry frame
        self.motor_label.grid(column=0, row=0, pady='15 5', sticky=S)
        self.motor_cb.grid(column=0, row=1, padx=10, pady='0 10', sticky=N)
        self.prop_label.grid(column=0, row=2, pady='5 5', sticky=S)
        self.prop_cb.grid(column=0, row=3, padx=10, pady='0 10', sticky=N)
        self.battery_voltage_label.grid(column=0, row=4, pady='5 5', padx=10, sticky=S)
        self.battery_voltage_entry.grid(column=0, row=5, pady='0 10', padx=10, sticky=N)

        # Grid frames.
        self.button_frame.grid(column=0, row=1, columnspan=2, sticky='nsew')
        self.misc_entry_frame.grid(column=0, row=0, sticky='nsew')
        self.add_vector_frame.grid(column=1, row=0, sticky='nsew')

        # Handle resizing
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        self.protocol('WM_DELETE_WINDOW', self.close_window)