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 gear_widget_mouse_click(self, gw: GearWidget): if len(self.invalidated_gear) > 0: self.cmdEquipCost_clicked() if len(self.invalidated_gear) > 0: return gw = GearWindow(self.enh_model, gw.gear) gw.sig_closed.connect(self.gear_window_closed) self.gear_windows.add(gw) gw.show()
def create_gt_cmb(self, gear_widget: GearWidget, top_lvl=None): this_gear = gear_widget.gear if top_lvl is None: top_lvl = self.find_top_lvl_item_from_gear(this_gear) gear_widget.create_gt_cmb(self) cmb_gt = gear_widget.cmbType idx_GEAR_TYPE = self.get_header_index(HEADER_GEAR_TYPE) cmb_gt.currentTextChanged.connect( lambda x: top_lvl.setText(idx_GEAR_TYPE, get_gt_color_compare(x))) self.setItemWidget(top_lvl, idx_GEAR_TYPE, cmb_gt)
def create_lvl_cmb(self, gear_widget: GearWidget, top_lvl=None): this_gear = gear_widget.gear if top_lvl is None: top_lvl = self.find_top_lvl_item_from_gear(this_gear) gear_widget.create_lvl_cmb(self) cmb_enh = gear_widget.cmbLevel idx_TARGET = self.get_header_index(HEADER_TARGET) cmb_enh.currentTextChanged.connect( lambda x: top_lvl.setText(idx_TARGET, get_gt_color_compare(x))) self.setItemWidget(top_lvl, idx_TARGET, cmb_enh)
def reload_list(self): model = self.enh_model 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) #exchange_dict = dict_box_list([x for x in model.fs_exchange if x.active], lambda x: x.effective_fs_level() - 1) exchange_dict: Dict[int, FailStackItemExchange] = {x.effective_fs_level()-1: x for x in model.fs_exchange if x.active} 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 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) 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 i in exchange_dict: item = exchange_dict[i] widget = make_material_list_widget([(x.item_id, x.amount) for x in item.exchange_items.values()], show_names=True, item_store=model.item_store()) self.removeCellWidget(rc, index_GEAR) self.setCellWidget(rc, index_GEAR, widget) self.resizeColumnsToContents()
def add_children(self, top_lvl: QTreeWidgetItem): model = self.enh_model idx_NAME = self.get_header_index(HEADER_NAME) idx_GEAR_TYPE = self.get_header_index(HEADER_GEAR_TYPE) idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST) idx_TARGET = self.get_header_index(HEADER_TARGET) master_gw = self.itemWidget(top_lvl, idx_NAME) this_gear: Gear = master_gw.gear gear_type = this_gear.gear_type top_lvl.takeChildren() for i in range(gear_type.bt_start - 1, len(gear_type.map)): twi = QTreeWidgetItem(top_lvl, [''] * self.columnCount()) lvl = this_gear.gear_type.idx_lvl_map[i] _gear = this_gear.duplicate() _gear.set_enhance_lvl(lvl) this_gw = GearWidget(_gear, model, edit_able=False, display_full_name=False) self.setItemWidget(twi, idx_NAME, this_gw) top_lvl.addChild(twi) twi.setText(idx_GEAR_TYPE, gear_type.name) twi.setText(idx_BASE_ITEM_COST, top_lvl.text(2)) twi.setText(idx_TARGET, _gear.enhance_lvl) twi.setForeground(idx_GEAR_TYPE, Qt.black) twi.setBackground(idx_GEAR_TYPE, gt_str_to_q_color(gear_type.name).lighter())
def fs_gear_sig_gear_changed(self, gw: GearWidget): model = self.enh_model settings = model.settings item_store: ItemStore = settings[settings.P_ITEM_STORE] this_gear: Gear = gw.gear model.update_costs([this_gear]) with QBlockSig(self): self.fs_gear_set_costs(this_gear, item_store, gw.row()) self.main_invalidate_func()
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 add_children(self, top_lvl: QTreeWidgetItem, start, stop, manager): model = self.enh_model idx_NAME = self.get_header_index(HEADER_NAME) idx_GEAR_TYPE = self.get_header_index(HEADER_GEAR_TYPE) master_gw = self.itemWidget(top_lvl, idx_NAME) this_gear: Gear = master_gw.gear gear_type = this_gear.gear_type idx_NAME = self.get_header_index(HEADER_NAME) idx_TARGET = self.get_header_index(HEADER_TARGET) idx_CRONSTONE = self.get_header_index(HEADER_CRONSTONE) idx_FS = self.get_header_index(HEADER_FS) idx_COST = self.get_header_index(HEADER_COST) idx_SELL_OUT = self.get_header_index(HEADER_SELL_OUT) idx_MARGIN = self.get_header_index(HEADER_MARGIN) if start > -1: actual_start_idx = this_gear.gear_type.idx_lvl_map[start] else: actual_start_idx = master_gw.cmbLevel.itemText(1) act_start = start + 1 top_lvl.takeChildren() for i in range(act_start, len(gear_type.map)): if i == stop: # This is the top level widget continue margin = manager.get_margin(start, i) twi = QTreeWidgetItem(top_lvl, [''] * self.columnCount()) lvl = this_gear.gear_type.idx_lvl_map[i] _gear = this_gear.duplicate() _gear.set_enhance_lvl(lvl) this_gw = GearWidget(_gear, model, edit_able=False, display_full_name=True) self.setItemWidget(twi, idx_NAME, this_gw) top_lvl.addChild(twi) twi.setText(idx_GEAR_TYPE, gear_type.name) twi.setForeground(idx_GEAR_TYPE, Qt.black) twi.setBackground(idx_GEAR_TYPE, gt_str_to_q_color(gear_type.name).lighter()) twi.setText(idx_TARGET, str(actual_start_idx)) twi.setText(idx_SELL_OUT, str(lvl)) fs = numpy.argmin(this_gear.cost_vec[i]) twi.setText(idx_FS, str(fs)) twi.setText(idx_MARGIN, MONNIES_FORMAT.format(margin)) uses_crons = i in this_gear.cron_use if uses_crons: if this_gw.trinket is None: this_gw.set_trinket(pix[STR_PIC_CRON]) else: if this_gw.trinket is not None: this_gw.set_trinket(None)
def set_lvl_cmb_box(self, gw: GearWidget = None, top_lvl: QTreeWidgetItem = None): if gw is None and top_lvl is None: raise Exception('need gear widget or top level to set cmb') if gw is None: idx_NAME = self.get_header_index(HEADER_NAME) gw = self.itemWidget(top_lvl, idx_NAME) if top_lvl is None: top_lvl = gw.parent_widget idx_HEADER_TARGET = self.get_header_index(HEADER_TARGET) this_gear = gw.gear cmdLevel = EnhForProfitLevelCmb(this_gear, self) gw.cmbLevel = cmdLevel self.setItemWidget(top_lvl, idx_HEADER_TARGET, cmdLevel) def changed(x): self.invalidated_gear.add(this_gear) cmdLevel.currentTextChanged.connect(changed)
def update_gw(self): gear = self.fsl.secondary_gear tree = self.treeWidget() idx_NAME = tree.get_header_index(HEADER_NAME) if gear is not None: this_gw = GearWidget( gear, self.model, edit_able=False, display_full_name=False, enhance_overlay=False, check_state=Qt.Checked if self.checked else Qt.Unchecked) this_gw.chkInclude.stateChanged.connect( self.gear_widget_chkInclude_stateChanged) with QBlockSig(tree): self.setText(idx_NAME, '') tree.setItemWidget(self, idx_NAME, this_gw) tree.updateGeometry() if self.checked: self.check_error() else: tree.removeItemWidget(self, idx_NAME)
def cmdFSRefresh_clicked(self, fsl: FailStackList): model: Enhance_model = self.enh_model settings = model.settings with SpeedUpTable(self): with QBlockSig(self): clear_table(self) if not fsl.validate(): return clear_table(self) try: if model.fs_needs_update: model.calcFS() else: model.calc_fs_secondary() except Invalid_FS_Parameters as e: self.frmMain.show_warning_msg(str(e)) return if not fsl.has_ran(): fsl.set_primary_data(model.primary_fs_gear, model.primary_fs_cost, model.primary_cum_fs_cost) fsl.evaluate_map() 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): fs_items = fsl.gear_list fs_cost = fsl.fs_cost cum_fs_cost = fsl.fs_cum_cost this_gear = fsl.secondary_gear bti_m_o = this_gear.gear_type.bt_start - 1 prv_num = fsl.starting_pos for i, num in enumerate(fsl.secondary_map): fsg = this_gear.gear_type.get_fs_gain(bti_m_o + i) for j in range(0, num): rc = self.rowCount() self.insertRow(rc) self.setItem(rc, index_FS, QTableWidgetItem(str(prv_num))) two = GearWidget(fs_items[prv_num], model, edit_able=False, display_full_name=True) two.add_to_table(self, rc, col=index_GEAR) this_cost = numpy.sum(fs_cost[prv_num:prv_num + fsg]) twi = monnies_twi_factory(this_cost) self.setItem(rc, index_COST, twi) this_cum_cost = cum_fs_cost[min( len(cum_fs_cost) - 1, prv_num + fsg)] twi = monnies_twi_factory(this_cum_cost) self.setItem(rc, index_CUMULATIVE_COST, twi) prv_num += fsg if prv_num > settings[settings.P_NUM_FS]: return
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 fs_gear_sig_gear_changed(self, gw: GearWidget, old_gear: Gear): model = self.enh_model this_gear: Gear = gw.gear model.swap_gear(old_gear, this_gear) self.set_item_data(gw.row())
def add_children(self, top_lvl_wid: QTreeWidgetItem): frmMain = self.frmMain model = self.enh_model idx_NAME = self.get_header_index(HEADER_NAME) idx_GEAR_TYPE = self.get_header_index(HEADER_GEAR_TYPE) idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST) idx_TARGET = self.get_header_index(HEADER_TARGET) master_gw = self.itemWidget(top_lvl_wid, idx_NAME) this_gear = master_gw.gear these_lvls = this_gear.guess_target_lvls(intersect=None, excludes=None) prunes = [] for i in range(0, top_lvl_wid.childCount()): child = top_lvl_wid.child(0) child_gw: GearWidget = self.itemWidget(child, idx_NAME) top_lvl_wid.takeChild(0) if not child_gw.chkInclude.isChecked(): prunes.append(child_gw.gear.enhance_lvl) try: child_gw.chkInclude.disconnect() except TypeError: pass def chk_click(state): spinner = self.sender() lvl = spinner.__dict__['lvl'] if state == Qt.Unchecked: try: this_gear.target_lvls.remove(lvl) except ValueError: pass else: if lvl not in this_gear.target_lvls: this_gear.target_lvls.append(lvl) #self.model.invalidate_enahce_list() for lvl in these_lvls: twi = QTreeWidgetItem(top_lvl_wid, [''] * self.columnCount()) _gear = this_gear.duplicate() _gear.set_enhance_lvl(lvl) this_check_state = Qt.Unchecked if lvl in prunes or lvl not in this_gear.target_lvls else Qt.Checked this_gw = GearWidget(_gear, model, edit_able=False, display_full_name=False, check_state=this_check_state) this_gw.sig_error.connect(self.frmMain.sig_show_message) this_gw.sig_layout_changed.connect( lambda: self.resizeColumnToContents(0)) this_gw.chkInclude.__dict__['lvl'] = lvl this_gw.chkInclude.stateChanged.connect(chk_click) self.setItemWidget(twi, idx_NAME, this_gw) top_lvl_wid.addChild(twi) gt_txt = master_gw.cmbType.currentText() twi.setText(idx_GEAR_TYPE, gt_txt) twi.setText(idx_BASE_ITEM_COST, top_lvl_wid.text(2)) twi.setText(idx_TARGET, _gear.enhance_lvl) twi.setForeground(idx_GEAR_TYPE, Qt.black) twi.setBackground(idx_GEAR_TYPE, gt_str_to_q_color(gt_txt).lighter())
def gear_widget_mouse_click(self, gw: GearWidget): gw = GearWindow(self.enh_model, gw.gear) gw.sig_closed.connect(self.gear_window_closed) self.gear_windows.add(gw) gw.show()
def set_gear_not_editable(self, gw: GearWidget): if gw.edit_able: gw.set_editable(False) gw.labelIcon.sigMouseLeftClick.connect( lambda: self.gear_widget_mouse_click(gw))