def set_common(self, model: Enhance_model, frmMain: lbl_color_MainWindow): super(TableGenome, self).set_common(model, frmMain) self.graph = frmMain.ui.graph_genome self.sig_thread_created.connect(frmMain.evolve_thread_created) self.sig_thread_destroyed.connect(frmMain.evolve_thread_destroyed) settings = model.settings self.clear() fsl_l = settings[settings.P_FSL_L] checked = set() for name, color, children in fsl_l: itm = UserGroupTreeWidgetItem(model, self.graph, self, [''] * self.columnCount(), color=RGBA_to_Qcolor(color), grp_name=name) self.addTopLevelItem(itm) for child_obj in children: itmc = GenomeTreeWidgetItem(model, itm, [''] * self.columnCount(), checked=False) itm.addChild(itmc) if isinstance(child_obj, dict): fsl = FailStackList(settings, None, None, None, None) fsl.set_state_json(child_obj) else: fsl = settings[settings.P_GENOME_FS][child_obj] self.chosen_twis.add(itmc) itmc.setIcon(0, pix.get_icon(STR_CHECK_PIC)) checked.add(fsl) itmc.set_fsl(fsl) itmc.update_data() itm.setExpanded(True) unaccount = [ x for x in settings[settings.P_GENOME_FS] if x not in checked ] if len(unaccount) > 0: itm = UserGroupTreeWidgetItem(model, self.graph, self, [''] * self.columnCount(), color=QColor(Qt.red), grp_name='Current Setting') self.addTopLevelItem(itm) for fsl in unaccount: itmc = GenomeTreeWidgetItem(model, itm, [''] * self.columnCount(), checked=False) itm.addChild(itmc) self.chosen_twis.add(itmc) itmc.setIcon(0, pix.get_icon(STR_CHECK_PIC)) itmc.set_fsl(fsl) itmc.update_data() itm.setExpanded(True)
def make_menu(self, menu: QMenu): menu.addSeparator() action_make_default = QAction('Use this solution', menu) action_make_default.setIcon(pix.get_icon(STR_CHECK_PIC)) action_make_default.triggered.connect( self.action_make_default_triggered) menu.addAction(action_make_default) action_rem_default = QAction('Don\'t Use this solution', menu) action_rem_default.setIcon(pix.get_icon(STR_MINUS_PIC)) action_rem_default.triggered.connect(self.remove_default_triggered) menu.addAction(action_rem_default)
def dropEvent(self, event) -> None: dragonto = self.itemAt(event.pos()) if dragonto is None: event.ignore() else: event.accept() model = self.enh_model if isinstance(dragonto, UserGroupTreeWidgetItem): for i in self.selectedItems(): if i is dragonto: continue # don't drag a section onto itself settings = self.enh_model.settings fsls = settings[settings.P_GENOME_FS] if isinstance(i, EvolveSolutionWidget): parent = i.parent() i.invalidate_plot() i = parent.takeChild(parent.indexOfChild(i)) fsl = i.fsl itm = GenomeTreeWidgetItem(model, dragonto, [''] * self.columnCount(), fsl=fsl) if fsl in fsls: itm.setIcon(0, pix.get_icon(STR_CHECK_PIC)) self.chosen_twis.remove(i) self.chosen_twis.add(itm) dragonto.addChild(itm) itm.update_data() itm.check_error() elif isinstance(i, GenomeGroupTreeWidget): for j in reversed(range(0, i.childCount())): this_twi = i.child(j) this_twi.invalidate_plot() this_twi: EvolveSolutionWidget = i.takeChild(j) fsl = this_twi.fsl itm = GenomeTreeWidgetItem(model, dragonto, [''] * self.columnCount(), fsl=fsl) if fsl in fsls: itm.setIcon(0, pix.get_icon(STR_CHECK_PIC)) self.chosen_twis.remove(i) self.chosen_twis.add(itm) dragonto.addChild(itm) itm.update_data() itm.check_error() self.takeTopLevelItem(self.indexOfTopLevelItem(i)) self.update()
def make_menu(self, menu: QMenu): super(TableFSCost, self).make_menu(menu) menu.addSeparator() action_refresh = QAction('Refresh List', menu) action_refresh.setIcon(pix.get_icon(STR_REFRESH_PIC)) menu.addAction(action_refresh) action_refresh.triggered.connect(self.cmdFSRefresh_clicked)
def make_menu(self, menu: QMenu): super(TableEquipment, self).make_menu(menu) menu.addSeparator() action_update_costs = QAction('Calculate All Costs', menu) action_update_costs.setIcon(pix.get_icon(STR_CALC_PIC)) action_update_costs.triggered.connect(self.cmdEquipCost_clicked) menu.addAction(action_update_costs) menu.addSeparator()
def make_menu(self, menu: QMenu): super(TableGenome, self).make_menu(menu) menu.addSeparator() action_add_group = QAction('Add Group', menu) action_add_group.triggered.connect(self.action_add_group_triggered) action_add_group.setIcon(pix.get_icon(STR_PLUS_PIC)) menu.addAction(action_add_group) action_add_optimizer = QAction('Add Optimizer', menu) action_add_optimizer.triggered.connect( self.action_add_optimizer_triggered) action_add_optimizer.setIcon(pix.get_icon(STR_PLUS_PIC)) menu.addAction(action_add_optimizer) action_remove_selected = QAction('Remove Selected', menu) action_remove_selected.triggered.connect( self.action_remove_selected_triggered) action_remove_selected.setIcon(pix.get_icon(STR_MINUS_PIC)) menu.addAction(action_remove_selected)
def reload_list(self): model = self.enh_model fs_exceptions = model.settings[model.settings.P_FS_EXCEPTIONS] index_FS = self.get_header_index(HEADER_FS) index_GEAR = self.get_header_index(HEADER_GEAR) index_COST = self.get_header_index(HEADER_COST) index_CUMULATIVE_COST = self.get_header_index(HEADER_CUMULATIVE_COST) index_PROBABILITY = self.get_header_index(HEADER_PROBABILITY) index_CUMULATIVE_PROBABILITY = self.get_header_index( HEADER_CUMULATIVE_PROBABILITY) with SpeedUpTable(self): with QBlockSig(self): clear_table(self) fs_items = model.primary_fs_gear fs_cost = model.primary_fs_cost cum_fs_cost = model.primary_cum_fs_cost cum_fs_probs = model.cum_fs_probs fs_probs = model.fs_probs fs_exception_boxes = self.fs_exception_boxes for i, this_gear in enumerate(fs_items): rc = self.rowCount() self.insertRow(rc) self.setRowHeight(rc, 32) twi = QTableWidgetItem(str(i + 1)) self.setItem(rc, index_FS, twi) if this_gear is None: twi = QTableWidgetItem('Free!') self.setItem(rc, index_GEAR, twi) elif i in fs_exceptions: self.add_custom_fs_combobox(model, fs_exception_boxes, i) else: two = GearWidget(this_gear, model, edit_able=False, display_full_name=True) two.add_to_table(self, rc, col=index_GEAR) twi = monnies_twi_factory(fs_cost[i]) self.setItem(rc, index_COST, twi) twi = monnies_twi_factory(cum_fs_cost[i]) self.setItem(rc, index_CUMULATIVE_COST, twi) twi = QTableWidgetItem(STR_PERCENT_FORMAT.format(fs_probs[i])) self.setItem(rc, index_PROBABILITY, twi) twi = QTableWidgetItem( STR_PERCENT_FORMAT.format(cum_fs_probs[i])) self.setItem(rc, index_CUMULATIVE_PROBABILITY, twi) if model.dragon_scale_30: if not 19 in fs_exceptions: self.removeCellWidget(19, index_GEAR) itm = self.item(19, index_GEAR) itm.setText('Dragon Scale x30') itm.setIcon(pix.get_icon(STR_PIC_DRAGON_SCALE)) if model.dragon_scale_350: if not 39 in fs_exceptions: self.removeCellWidget(39, index_GEAR) self.item(39, index_GEAR).setText('Dragon Scale x350')
def make_menu(self, menu: QMenu): super(EvolveTreeWidget, self).make_menu(menu) menu.addSeparator() action_set_parameters = QAction('Set Parameters', menu) action_set_parameters.setIcon(pix.get_icon(STR_DIAL_PIC)) action_set_parameters.triggered.connect( self.action_set_parameters_callback) menu.addAction(action_set_parameters) action_start_calculation = QAction('Start Calculation', menu) action_start_calculation.triggered.connect( self.action_start_calculation_callback) action_start_calculation.setIcon(pix.get_icon(STR_CALC_PIC)) menu.addAction(action_start_calculation) action_stop_calculation = QAction('Stop Calculating', menu) action_stop_calculation.setIcon(pix.get_icon(STR_STOP_PIC)) action_stop_calculation.triggered.connect( self.action_stop_calculation_callback) menu.addAction(action_stop_calculation)
def __init__(self, gear: Gear, *args, **kwargs): super(GearAction, self).__init__(*args, **kwargs) self.gear = gear if gear.item_id is not None: fn = STR_FMT_ITM_ID.format(gear.item_id) icon_path = os.path.join(IMG_TMP, fn + '.png') if os.path.isfile(icon_path): self.setIcon(pix.get_icon(icon_path)) self.triggered.connect(self.emitit)
def make_menu(self, menu: QMenu): super(AbstractTableFS, self).make_menu(menu) menu.addSeparator() action_table_FS_add = QAction('Add Item', menu) action_table_FS_add.setIcon(pix.get_icon(STR_PLUS_PIC)) menu.addAction(action_table_FS_add) action_table_FS_add.triggered.connect(self.cmdFSAdd_clicked) action_table_FS_remove = QAction('Remove Item', menu) action_table_FS_remove.setIcon(pix.get_icon(STR_MINUS_PIC)) menu.addAction(action_table_FS_remove) action_table_FS_remove.triggered.connect(self.cmdFSRemove_clicked) action_table_FS_mp_update = QAction('Central Market: Update All', menu) action_table_FS_mp_update.setIcon(pix.get_icon(STR_GOLD_PIC)) settings = self.enh_model.settings itm_store: ItemStore = settings[settings.P_ITEM_STORE] action_table_FS_mp_update.setEnabled( isinstance(itm_store.price_updator, CentralMarketPriceUpdator)) action_table_FS_mp_update.triggered.connect( self.action_mp_update_triggered) menu.addAction(action_table_FS_mp_update)
def make_menu(self, menu: QMenu): super(AbstractGearTree, self).make_menu(menu) menu.addSeparator() action_add_gear = QAction('Add Gear', menu) action_add_gear.setIcon(pix.get_icon(STR_PLUS_PIC)) action_add_gear.triggered.connect(self.add_item_basic) menu.addAction(action_add_gear) action_remove_gear = QAction('Remove Gear(s)', menu) action_remove_gear.setIcon(pix.get_icon(STR_MINUS_PIC)) action_remove_gear.triggered.connect(self.remove_selected_equipment) menu.addAction(action_remove_gear) menu.addSeparator() action_mp_update = QAction('MP: Update All', menu) action_mp_update.setIcon(pix.get_icon(STR_GOLD_PIC)) settings = self.enh_model.settings itm_store: ItemStore = settings[settings.P_ITEM_STORE] action_mp_update.setEnabled( isinstance(itm_store.price_updator, CentralMarketPriceUpdator)) action_mp_update.triggered.connect(self.action_mp_update_triggered) menu.addAction(action_mp_update)
def make_menu(self, menu: QMenu): super(TableForProfit, self).make_menu(menu) menu.addSeparator() action_update_costs = QAction('Calculate All Costs', menu) action_update_costs.setIcon(pix.get_icon(STR_CALC_PIC)) action_update_costs.triggered.connect(self.cmdCalc_clicked) menu.addAction(action_update_costs) action_fs_with = QAction('Fail stack with this list', menu) action_fs_with.setCheckable(True) action_fs_with.setChecked(False) action_fs_with.triggered.connect(self.action_fs_with_triggered) menu.addAction(action_fs_with) menu.addSeparator()
def create_TreeWidgetItem(self, parent_wid, this_gear, check_state, icon_overlay=True) -> QTreeWidgetItem: model = self.enh_model top_lvl = TreeWidgetGW(parent_wid, [''] * self.columnCount()) top_lvl.setFlags(top_lvl.flags() | Qt.ItemIsEditable) f_two = GearWidget(this_gear, model, default_icon=pix.get_icon(STR_LENS_PATH), check_state=check_state, edit_able=True, enhance_overlay=icon_overlay) f_two.sig_error.connect(self.frmMain.sig_show_message) idx_NAME = self.get_header_index(HEADER_NAME) f_two.sig_layout_changed.connect( lambda: self.resizeColumnToContents(0)) f_two.add_to_tree(self, top_lvl, col=idx_NAME) self.set_item_data(top_lvl) return top_lvl
def table_FS_add_gear(self, this_gear: Gear, check_state=Qt.Checked): frmMain = self.frmMain model = self.enh_model settings = model.settings rc = self.rowCount() with SpeedUpTable(self): self.insertRow(rc) with QBlockSig(self): # If the rows are not initialized then the context menus will bug out for i in range(0, self.columnCount()): twi = QTableWidgetItem('') self.setItem(rc, i, twi) twi_gt = QTableWidgetItem( ) # Hidden behind the combo box displays number (for sorting?) twi_lvl = QTableWidgetItem( ) # Hidden behind the combo box displays number (for sorting?) f_two = GearWidget(this_gear, model, default_icon=pix.get_icon(STR_LENS_PATH), check_state=check_state, edit_able=True) f_two.sig_error.connect(self.frmMain.sig_show_message) f_two.context_menu = QMenu( f_two ) # Don't want upgrade / downgrade options on this type of gear self.make_menu(f_two.context_menu) f_two.create_Cmbs(self) cmb_gt = f_two.cmbType cmb_enh = f_two.cmbLevel cmb_gt.currentTextChanged.connect( lambda x: set_cell_color_compare(twi_gt, x)) cmb_enh.currentTextChanged.connect(lambda x: set_cell_lvl_compare( twi_lvl, x, this_gear.gear_type)) with QBlockSig(self): f_two.add_to_table(self, rc, col=0) self.setCellWidget(rc, 1, cmb_gt) twi = monnies_twi_factory(this_gear.base_item_cost) self.setItem(rc, 2, twi) self.setCellWidget(rc, 3, cmb_enh) self.setItem(rc, 1, twi_gt) self.setItem(rc, 3, twi_lvl) set_cell_lvl_compare(twi_lvl, cmb_enh.currentText(), this_gear.gear_type) set_cell_color_compare(twi_gt, cmb_gt.currentText()) f_two.chkInclude.stateChanged.connect( lambda x: self.gw_check_state_changed(f_two, x)) self.clearSelection() self.selectRow(rc) with QBlockSig(self): self.cellWidget(rc, 1).currentTextChanged.connect( frmMain.invalidate_fs_list) self.cellWidget(rc, 3).currentTextChanged.connect( frmMain.invalidate_fs_list) self.resizeColumnToContents(0) f_two.sig_gear_changed.connect(self.fs_gear_sig_gear_changed)
def make_default(self, twi: EvolveSolutionWidget): model = self.enh_model model.set_fsl(twi.fsl) self.chosen_twis.add(twi) twi.setIcon(0, pix.get_icon(STR_CHECK_PIC)) self.sig_selected_genome_changed.emit()