def __init__(self, parent): # Main window initialization. Frame.__init__(self, parent) self.parent = parent self.character_library = CharacterLibrary() self.fitting_library = FittingLibrary() self.weapon_library = WeaponLibrary() self.module_library = ModuleLibrary() self.current_char = Character('No Skills') self.current_fit = self.fitting_library.get_fitting(self.fitting_library.get_fitting_list()[0]) # Call pertinent methods to display main window. self.menubar_main() self.combobox_character() self.combobox_fitting() self.tree_modules() self.fitting_display() self.stats_display()
class DftUi(Frame): """ This is the Main Window for the Dust Fitting Tool. """ def __init__(self, parent): # Main window initialization. Frame.__init__(self, parent) self.parent = parent self.character_library = CharacterLibrary() self.fitting_library = FittingLibrary() self.weapon_library = WeaponLibrary() self.module_library = ModuleLibrary() self.current_char = Character('No Skills') self.current_fit = self.fitting_library.get_fitting(self.fitting_library.get_fitting_list()[0]) # Call pertinent methods to display main window. self.menubar_main() self.combobox_character() self.combobox_fitting() self.tree_modules() self.fitting_display() self.stats_display() def menubar_main(self): """ Displays and manages the upper menubar. """ # Initial configurations. menubar = Menu(self.parent) self.parent.config(menu=menubar) self.parent.option_add('*tearOff', False) # First menu contents fileMenu = Menu(menubar) fileMenu.add_command(label='New Dropsuit', command=self.new_dropsuit_window) fileMenu.add_command(label='New Vehicle') fileMenu.add_command(label='New Character', command=self.add_character_window) editMenu = Menu(menubar) editMenu.add_command(label='Edit Character', command=self.edit_character_window) editMenu.add_command(label='Delete Character', command=self.delete_character_window) editMenu.add_command(label='Delete Fitting', command=self.delete_fitting_window) # Add the menus menubar.add_cascade(label='File', menu=fileMenu) menubar.add_cascade(label='Edit', menu=editMenu) def combobox_character(self): """ Displays and manages the character selection for the main window. """ # Get known characters. API calls or data retrieval here. character_names = self.character_library.get_character_list() # Creates the Combobox which has all known characters and automatically # selects the first character. Also other widgets. frm_character = Frame(self) lbl_character = Label(frm_character, text='Character:') self.cbx_character = ttk.Combobox(frm_character, values=character_names, width=14) self.cbx_character.set('No Skills') # Grid management. frm_character.grid(column=0, row=0) lbl_character.grid(column=0, row=0, sticky=NW, padx=3, pady=3) self.cbx_character.grid(column=1, row=0, sticky=NW, padx=3, pady=3) # Binding. self.cbx_character.bind('<<ComboboxSelected>>', self.change_character) def combobox_fitting(self): """ Displays and manages the current fitting to be displayed on the main window. """ # Get known fits. API calls or data retrieval here. fitting_names = self.fitting_library.get_fitting_list() # Creates nessessary widgets. frm_fitting = Frame(self) lbl_fitting = Label(frm_fitting, text='Fitting:') self.cbx_fitting = ttk.Combobox(frm_fitting, values=fitting_names) self.cbx_fitting.set(self.current_fit.name) # Grid management. frm_fitting.grid(column=1, row=0) lbl_fitting.grid(column=2, row=0, sticky=NE, padx=3, pady=3) self.cbx_fitting.grid(column=3, row=0, sticky=NW, padx=3, pady=3) # Binding. self.cbx_fitting.bind('<<ComboboxSelected>>', self.change_fitting) def tree_modules(self): """ """ frm_modules = Frame(self) self.tre_modules = ttk.Treeview(frm_modules, height=14, columns=('cpu', 'pg')) scb_modules = Scrollbar(frm_modules, orient=VERTICAL, command=self.tre_modules.yview) self.tre_modules.column('#0', width=150, minwidth=150) self.tre_modules.column('cpu', width=30, minwidth=30) self.tre_modules.column('pg', width=30, minwidth=30) self.tre_modules.heading('cpu', text='CPU') self.tre_modules.heading('pg', text='PG') for parent in self.weapon_library.get_parents(): self.tre_modules.insert('', 'end', parent, text=parent, tag='ttk') for child in self.weapon_library.get_children(parent): self.tre_modules.insert(parent, 'end', child[0], text=child[0], tag='ttk') self.tre_modules.set(child[0], 'cpu', child[1]) self.tre_modules.set(child[0], 'pg', child[2]) for parent in self.module_library.get_parents(): self.tre_modules.insert('', 'end', parent, text=parent, tag='ttk') for child in self.module_library.get_children(parent): self.tre_modules.insert(parent, 'end', child[0], text=child[0], tag='ttk') self.tre_modules.set(child[0], 'cpu', child[1]) self.tre_modules.set(child[0], 'pg', child[2]) # Grid management. frm_modules.grid(column=0, row=1) self.tre_modules.grid(column=0, row=0, sticky=NW, padx=3, pady=3) scb_modules.grid(column=1, row=0, sticky=NE+S, pady=4) self.tre_modules.configure(yscrollcommand=scb_modules.set) # Bindings self.tre_modules.bind('<Double-1>', self.add_module) def fitting_display(self): """ Displays all the current fitting information. """ # Set variables. fitting_list = StringVar(value=self.current_fit.get_all_modules()) # Creates the widgets needed for this display. frm_fitting_display = Frame(self, height=300) self.lbx_fitting = Listbox(frm_fitting_display, listvariable=fitting_list, width=48, height=20, font='TkFixedFont', bg='white') # Grid management. frm_fitting_display.grid(column=1, row=1, sticky=W+E+N+S) self.lbx_fitting.grid(column=0, row=0, sticky=W+E+N+S) # Bindings self.lbx_fitting.bind('<Double-1>', self.remove_module) def stats_display(self): """ Displays fitting stats. """ # Initialize variables. cpu_text = '%s/%s' % (self.current_fit.current_cpu, self.current_fit.max_cpu) pg_text = '%s/%s' % (self.current_fit.current_pg, self.current_fit.max_pg) cpu_over = self.current_fit.get_cpu_over() pg_over = self.current_fit.get_pg_over() # Creates the holding widgets. nbk_stats = ttk.Notebook(self) #nbk_stats.grid_propagate(False) frm_overview = Frame(self) nbk_stats.add(frm_overview, text='Overview') # Creates widgets for Dropsuit Type. lfr_dropsuit_type = ttk.Labelframe(frm_overview, text='Dropsuit Type:') lbl_dropsuit_type = Label(lfr_dropsuit_type, text=self.current_fit.ds_name).grid(column=0, row=0) # Creates widgets for Resources. lfr_resources = ttk.Labelframe(frm_overview, text='Resources') lbl_cpu1 = Label(lfr_resources, text='CPU:').grid(column=0, row=0, sticky=W) lbl_cpu2 = Label(lfr_resources, text=cpu_text).grid(column=1, row=0) lbl_pg1 = Label(lfr_resources, text='PG:').grid(column=2, row=0, sticky=W, padx=10) lbl_pg2 = Label(lfr_resources, text=pg_text).grid(column=3, row=0) lbl_cpu3 = Label(lfr_resources, text=cpu_over).grid(column=1, row=1, sticky=E) lbl_pg3 = Label(lfr_resources, text=pg_over).grid(column=3, row=1, sticky=E) lfr_resources.columnconfigure(0, minsize=30) lfr_resources.columnconfigure(1, minsize=90) lfr_resources.columnconfigure(2, minsize=20) lfr_resources.columnconfigure(3, minsize=75) # Creates widgets for main offenses. lfr_offenses = ttk.Labelframe(frm_overview, text='Main Offense') lbl_weapon = Label(lfr_offenses, text=self.current_fit.get_primary_weapon_name()).grid(column=0, row=0, columnspan=4) lbl_dmg1 = Label(lfr_offenses, text='Damage: ').grid(column=0, row=1, sticky=W) lbl_dmg2 = Label(lfr_offenses, text=self.current_fit.get_primary_stats('damage')).grid(column=1, row=1, sticky=E) lbl_rof1 = Label(lfr_offenses, text='RoF:').grid(column=2, row=1, sticky=W, padx=10) lbl_rof2 = Label(lfr_offenses, text=self.current_fit.get_primary_stats('rate_of_fire')).grid(column=3, row=1, sticky=E) lbl_dps1 = Label(lfr_offenses, text='DPS: ').grid(column=0, row=2, sticky=W) lbl_dps2 = Label(lfr_offenses, text=self.current_fit.get_primary_dps()).grid(column=1, row=2, sticky=E) lbl_dpm1 = Label(lfr_offenses, text='DPMag: ').grid(column=2, row=2, sticky=W, padx=10) lbl_dpm2 = Label(lfr_offenses, text=self.current_fit.get_primary_dpm()).grid(column=3, row=2, sticky=E) lfr_offenses.columnconfigure(0, minsize=60) lfr_offenses.columnconfigure(1, minsize=45) lfr_offenses.columnconfigure(2, minsize=60) lfr_offenses.columnconfigure(3, minsize=60) # Creates widgets for Defenses. lfr_defenses = ttk.Labelframe(frm_overview, text='Defenses') lbl_shield1 = Label(lfr_defenses, text='Shield HP:').grid(column=0, row=0, sticky=W) lbl_shield2 = Label(lfr_defenses, text=self.current_fit.get_shield_hp()).grid(column=1, row=0, sticky=E) lbl_recharge1 = Label(lfr_defenses, text='Recharge:').grid(column=2, row=0, sticky=W, padx=10) lbl_recharge2 = Label(lfr_defenses, text=self.current_fit.get_shield_recharge()).grid(column=3, row=0, sticky=E) lbl_armor1 = Label(lfr_defenses, text='Armor HP:').grid(column=0, row=1, sticky=W) lbl_armor2 = Label(lfr_defenses, text=self.current_fit.get_armor_hp()).grid(column=1, row=1, sticky=E) lbl_repair1 = Label(lfr_defenses, text='Repair:').grid(column=2, row=1, sticky=W, padx=10) lbl_repair2 = Label(lfr_defenses, text=self.current_fit.get_armor_repair_rate()).grid(column=3, row=1, sticky=E) lfr_defenses.columnconfigure(0, minsize=70) lfr_defenses.columnconfigure(1, minsize=50) lfr_defenses.columnconfigure(2, minsize=70) lfr_defenses.columnconfigure(3, minsize=35) # Creates widgets for Sensors. lfr_sensors = ttk.Labelframe(frm_overview, text='Sensors') lbl_prof1 = Label(lfr_sensors, text='Scan Profile: ').grid(column=0, row=0, sticky=W) lbl_prof2 = Label(lfr_sensors, text=self.current_fit.get_scan_profile()).grid(column=1, row=0, sticky=E) lbl_prec1 = Label(lfr_sensors, text='Scan Precision: ').grid(column=0, row=1, sticky=W) lbl_prec2 = Label(lfr_sensors, text=self.current_fit.get_scan_precision()).grid(column=1, row=1, sticky=E) lbl_radi1 = Label(lfr_sensors, text='Scan Radius: ').grid(column=0, row=2, sticky=W) lbl_radi2 = Label(lfr_sensors, text=self.current_fit.get_scan_radius()).grid(column=1, row=2, sticky=E) # Grid management. nbk_stats.grid(column=2, row=0, rowspan=3, sticky=W+E+N+S, padx=3, pady=3) lfr_dropsuit_type.grid(column=0, row=0, sticky=EW) lfr_resources.grid(column=0, row=1, sticky=EW) lfr_offenses.grid(column=0, row=2, sticky=EW) lfr_defenses.grid(column=0, row=3, sticky=EW) lfr_sensors.grid(column=0, row=4, sticky=EW) frm_overview.columnconfigure(0, minsize=250) def new_dropsuit_window(self): """ Handles creating a whole new dropsuit. """ dropsuit_window = DropsuitWindow(self) def add_character_window(self): """ """ add_character_window = AddCharacterWindow(self) def edit_character_window(self): """ Runs the class which deals with editing or adding a character. """ character_edit_window = CharacterEditWindow(self, self.current_char.name) def delete_character_window(self): """ """ delete_character = DeleteCharacterWindow(self) def delete_fitting_window(self): """ """ delete_fitting = DeleteFittingWindow(self) def load_new_dropsuit(self, fitting_name, dropsuit): """ Called from the DropsuitWindow class. This will load the dropsuit given by DropsuitWindow into the current fit. """ # Change the fit to hold the selected dropsuit. self.current_fit = Fitting(fitting_name, self.current_char, dropsuit) self.fitting_library.save_fitting(self.current_fit) # Call the fitting_display and stats_display functions. self.combobox_fitting() self.fitting_display() self.stats_display() def add_module(self, *args): """ Adds a module to the fitting. """ # Find what is selected. module_name = self.tre_modules.selection()[0] # Check to see if its a module or weapon, get the item requested. if module_name in self.module_library.get_names(): self.current_fit.add_module(module_name) else: self.current_fit.add_weapon(module_name) # Save the changes. self.fitting_library.save_fitting(self.current_fit) # Display the change. self.fitting_display() self.stats_display() def remove_module(self, *args): """ Removes a module from the fitting. """ # Find what is selected. listbox_index = self.lbx_fitting.curselection() module_name = self.lbx_fitting.get(listbox_index) self.current_fit.remove_module(module_name) # Save the changes. self.fitting_library.save_fitting(self.current_fit) # Display the change. self.fitting_display() self.stats_display() def change_character(self, *args): """ Changes the current characters for this fitting. """ name = self.cbx_character.get() # Change the character self.current_char = self.character_library.get_character(name) self.current_fit.change_character(self.current_char) # Display the change. self.fitting_display() self.stats_display() def change_fitting(self, *args): """ Changes the current fitting. """ fitting_name = self.cbx_fitting.get() # Change the current fitting. self.current_fit = self.fitting_library.get_fitting(fitting_name) # Display the change. self.fitting_display() self.stats_display() def update_character(self, character): """ Called by CharacterEditWindow. This will update a character with the changed skills. """ # Reload character data. THIS IS A HACK. Add better methods for changing and updating characters. self.character_library = CharacterLibrary() self.current_char = self.character_library.get_character(self.current_char.name) self.current_fit.change_character(self.current_char) # Display the changes. self.fitting_display() self.stats_display() # Reloads the character dropdown menu. Needed if a new character is added. self.combobox_character() def update_fitting(self, fitting): """ Called by DeleteFittingWindow. """ self.fitting_library = FittingLibrary() # Selects a fitting and makes it active. misc_fitting = self.fitting_library.get_fitting_list()[0] self.current_fit = self.fitting_library.get_fitting(misc_fitting) # Display the changes. self.combobox_fitting() self.fitting_display() self.stats_display()