def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(6, 31) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: self.opening_character_update_window(event)) self.filter_manager = FilterRuleManager() self.characters = CharacterPowerModel.select_character_power_list() self._init_upper_frame() self._updating_status()
def __init__(self, master, callback, character_selected, width=422, height=155, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title('Character selection') self.records = None self.update_records() self.filter_manager = FilterRuleManager() self.filter_manager.set_comparison_rule(0) self.filter_manager.set_comparison_rule(1) self._init_widgets() self._init_character_selected(character_selected) self.callback = callback
def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: self.opening_character_update_window(event)) self.set_table_place(6, 31) self.filter_manager = FilterRuleManager() self.table_model = TableModelAdvance() self.table_model.set_columns(CharacterWeapon.TABLE_VIEW_COLUMNS) self.table_view.setModel(self.table_model) self.characters = CharacterWeaponModel.select_character_weapon_list() self._init_upper_frame() self.update_table()
def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(6, 31) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: self.opening_character_update_window(event)) self.filter_manager = FilterRuleManager() self.characters = CharacterPowerModel.select_character_power_list() self._init_upper_frame() self._updating_status()
def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(34, 29) self.table_model = TableModelAdvance() self.table_model.set_columns(RecordOfDrawLots.TABLE_VIEW_COLUMNS) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: self.opening_character_update_window(event)) self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.records = DrawLotsModel.select_record_list() self.events = DrawLotsModel.select_event_list() self._init_adding_frame() self._init_filter_frame() self.table.tkraise() # 放上層,避免被其他元件遮到 self.update_table()
def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: self.opening_character_update_window(event)) self.set_table_place(6, 31) self.filter_manager = FilterRuleManager() self.table_model = TableModelAdvance() self.table_model.set_columns(CharacterWeapon.TABLE_VIEW_COLUMNS) self.table_view.setModel(self.table_model) self.characters = CharacterWeaponModel.select_character_weapon_list() self._init_upper_frame() self.update_table()
def __init__(self, master): MainFrameWithTable.__init__(self, master) self.set_table_place(34, 29) self.table_view.cellwidth = 85 self.table_model = TableModelAdvance() self.table_model.set_columns(FriendRecord.TABLE_VIEW_COLUMNS, main_column='Names') self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.filter_manager.set_comparison_rule( 'used_names', rule=sub_match_request_or_japanese_character) self.filter_manager.set_comparison_rule('current_character') # 滑鼠中鍵事件註冊,設定為更新好友資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: (self.table_view.handle_left_click(event), self.opening_info_update_window(event))) self._init_left_frame() self._init_upper_frame() self._init_context()
def __init__(self, master): MainFrameWithTable.__init__(self, master) self.set_table_place(34, 29) self.table_view.cellwidth = 85 self.table_model = TableModelAdvance() self.table_model.set_columns(FriendRecord.TABLE_VIEW_COLUMNS, main_column='Names') self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.filter_manager.set_comparison_rule('used_names', rule=sub_match_request_or_japanese_character) self.filter_manager.set_comparison_rule('current_character') # 滑鼠中鍵事件註冊,設定為更新好友資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: ( self.table_view.handle_left_click(event), self.opening_info_update_window(event))) self._init_left_frame() self._init_upper_frame() self._init_context()
def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(34, 29) self.table_model = TableModelAdvance() self.table_model.set_columns(RecordOfDrawLots.TABLE_VIEW_COLUMNS) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: self.opening_character_update_window(event)) self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.records = DrawLotsModel.select_record_list() self.events = DrawLotsModel.select_event_list() self._init_adding_frame() self._init_filter_frame() self.table.tkraise() # 放上層,避免被其他元件遮到 self.update_table()
class CharacterWeaponFrame(MainFrameWithTable): def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: self.opening_character_update_window(event)) self.set_table_place(6, 31) self.filter_manager = FilterRuleManager() self.table_model = TableModelAdvance() self.table_model.set_columns(CharacterWeapon.TABLE_VIEW_COLUMNS) self.table_view.setModel(self.table_model) self.characters = CharacterWeaponModel.select_character_weapon_list() self._init_upper_frame() self.update_table() def _init_upper_frame(self): self.insufficiently = ToggleButton(self, text='Insufficiently', width=14, font=(SCP, 8), relief=RIDGE) self.insufficiently.bind( '<Button-1>', lambda event: (self.filter_manager.set_specific_condition( 'unforged', 0 if self.insufficiently.is_selected else CONDITIONLESS, rule=not_match_request), self.update_table()), add='+') self.insufficiently.place(x=380, y=3) Label(self, text='Type:', width=5, font=(MS_JH, 11)).place(x=510, y=3) self.type_selector = FilteredCombobox(self, width=4, font=(MS_JH, 9), justify=CENTER, state='readonly') self.type_selector['values'] = WEAPONS self.type_selector.place(x=558, y=5) self.type_selector.bind( '<<ComboboxSelected>>', lambda event: (self.filter_manager.set_specific_condition( 'weapon_type', self.type_selector.get()), self.update_table())) button = Button(self, text='新增', width=8, font=(MS_JH, 10)) button.place(x=640, y=1) button["command"] = lambda: open_adding_new_character_weapon_window( self, callback=lambda cw: (self.characters.append(cw), self.update_table())) def update_table(self): results = self.filter_manager.filter(self.characters) self.table_model.set_rows( [result.get_table_view_info() for result in results]) self.table_model.setSortOrder(columnName='Left', reverse=1) self.redisplay_table() # 更改角色資訊 def opening_character_update_window(self, event): self.table_view.handle_left_click(event) character = self.get_corresponding_character_weapon_in_row( self.table_view.get_row_clicked(event)).character open_updating_character_window(self, character, lambda: None) # 編輯武器狀態 def do_double_clicking(self, event): character_weapon = self.get_corresponding_character_weapon_in_row( self.table_view.get_row_clicked(event)) open_updating_character_weapon_window(self, character_weapon, self.update_table) def do_dragging_along_right(self, row_number): character = self.get_corresponding_character_weapon_in_row(row_number) delete_character_weapon_with_conforming( self, character, lambda: (self.characters.remove( character), self.update_table())) # 直接從 list 中拿掉,不用重撈 def get_corresponding_character_weapon_in_row(self, row_number): selected_name = self.table_model.getCellRecord(row_number, 0) for character in self.characters: if character.nickname.encode('utf-8') == selected_name: return character
class CharacterPowerFrame(MainFrameWithTable): def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(6, 31) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: self.opening_character_update_window(event)) self.filter_manager = FilterRuleManager() self.characters = CharacterPowerModel.select_character_power_list() self._init_upper_frame() self._updating_status() def _init_upper_frame(self): self.presently = ToggleButton(self, text='Presently', width=9, font=(SCP, 8), relief=RIDGE) self.presently.bind('<Button-1>', lambda event: self.update_table(), add='+') self.presently.place(x=318, y=3) Label(self, text='Order:', width=5, font=(MS_JH, 11)).place(x=401, y=3) self.order_selector = ttk.Combobox(self, width=8, font=(MS_JH, 9), justify=CENTER, state='readonly') self.order_selector['values'] = ['DPS', 'Character'] self.order_selector.set('DPS') self.order_selector.place(x=452, y=5) self.order_selector.bind('<<ComboboxSelected>>', lambda event: self.update_table()) button = Button(self, text='新增', width=8, font=(MS_JH, 10)) button.place(x=550, y=1) button["command"] = lambda: open_adding_new_character_power_window( self, callback=lambda cp: self.callback_after_adding_character_power(cp)) self.state_str = StringVar(value='ToFull') self.state = Button(self, textvariable=self.state_str, width=8, font=(SCP, 10), relief=RIDGE) self.state.is_full = False self.state['command'] = lambda: (self.toggle_state(), self._updating_status()) self.state.place(x=640, y=1) def _updating_status(self): if self.state.is_full: self.table_model = TableModelAdvance() self.table_model.set_columns(CharacterPower.TABLE_VIEW_FULL_COLUMNS, main_column='Character') self.table_view.setModel(self.table_model) self.state_str.set('ToSimple') else: self.table_model = TableModelAdvance() self.table_model.set_columns(CharacterPower.TABLE_VIEW_SIMPLE_COLUMNS, main_column='Character') self.table_view.setModel(self.table_model) self.state_str.set('ToFull') self.update_table() def toggle_state(self): self.state.is_full = not self.state.is_full def callback_after_adding_character_power(self, character_power): self.characters.append(character_power) self.update_table() def update_table(self): self.table_model.set_rows(self.get_infos_by_state()) # 先根據目前的選擇設定排序方法 if self.order_selector.get() == 'DPS': self.table_model.setSortOrder(columnName='DPS', reverse=1) else: self.table_model.setSortOrder(columnName='Lv', reverse=1) self.table_model.setSortOrder(columnName='Character') self.redisplay_table() self.table_view.resizeColumn(1, 30) # Presently self.table_view.hide_column('ID') def get_infos_by_state(self): self.filter_manager.set_specific_condition('presently', True if self.presently.is_selected else CONDITIONLESS) results = self.filter_manager.filter(self.characters) return [character.get_table_view_full_info() for character in results] if self.state.is_full else \ [character.get_table_view_simple_info() for character in results] # 編輯角色傷害 def do_double_clicking(self, event): character_power = self.get_corresponding_character_power_in_row(self.table_view.get_row_clicked(event)) open_updating_character_power_window(self, character_power, self.update_table) def do_dragging_along_right(self, row_number): character = self.get_corresponding_character_power_in_row(row_number) delete_character_power_with_conforming(self, character, lambda: ( self.characters.remove(character), self.update_table())) # 直接從 list 中拿掉,不用重撈 def do_dragging_along_left(self, row_number): character = self.get_corresponding_character_power_in_row(row_number) open_adding_new_character_power_window( self, callback=lambda cp: self.callback_after_adding_character_power(cp), character=character) # 更改角色資訊 def opening_character_update_window(self, event): self.table_view.handle_left_click(event) character = self.get_corresponding_character_power_in_row(self.table_view.get_row_clicked(event)).character open_updating_character_window(self, character, lambda: None) def get_corresponding_character_power_in_row(self, row_number): selected_id = self.table_model.getCellRecord(row_number, 0) selected_level = self.table_model.getCellRecord(row_number, 3) for character in self.characters: if character.c_id == selected_id and character.level == selected_level: return character
class CharacterPowerFrame(MainFrameWithTable): def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(6, 31) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: self.opening_character_update_window(event)) self.filter_manager = FilterRuleManager() self.characters = CharacterPowerModel.select_character_power_list() self._init_upper_frame() self._updating_status() def _init_upper_frame(self): self.presently = ToggleButton(self, text='Presently', width=9, font=(SCP, 8), relief=RIDGE) self.presently.bind('<Button-1>', lambda event: self.update_table(), add='+') self.presently.place(x=318, y=3) Label(self, text='Order:', width=5, font=(MS_JH, 11)).place(x=401, y=3) self.order_selector = ttk.Combobox(self, width=8, font=(MS_JH, 9), justify=CENTER, state='readonly') self.order_selector['values'] = ['DPS', 'Character'] self.order_selector.set('DPS') self.order_selector.place(x=452, y=5) self.order_selector.bind('<<ComboboxSelected>>', lambda event: self.update_table()) button = Button(self, text='新增', width=8, font=(MS_JH, 10)) button.place(x=550, y=1) button["command"] = lambda: open_adding_new_character_power_window( self, callback=lambda cp: self.callback_after_adding_character_power(cp)) self.state_str = StringVar(value='ToFull') self.state = Button(self, textvariable=self.state_str, width=8, font=(SCP, 10), relief=RIDGE) self.state.is_full = False self.state['command'] = lambda: (self.toggle_state(), self._updating_status()) self.state.place(x=640, y=1) def _updating_status(self): if self.state.is_full: self.table_model = TableModelAdvance() self.table_model.set_columns( CharacterPower.TABLE_VIEW_FULL_COLUMNS, main_column='Character') self.table_view.setModel(self.table_model) self.state_str.set('ToSimple') else: self.table_model = TableModelAdvance() self.table_model.set_columns( CharacterPower.TABLE_VIEW_SIMPLE_COLUMNS, main_column='Character') self.table_view.setModel(self.table_model) self.state_str.set('ToFull') self.update_table() def toggle_state(self): self.state.is_full = not self.state.is_full def callback_after_adding_character_power(self, character_power): self.characters.append(character_power) self.update_table() def update_table(self): self.table_model.set_rows(self.get_infos_by_state()) # 先根據目前的選擇設定排序方法 if self.order_selector.get() == 'DPS': self.table_model.setSortOrder(columnName='DPS', reverse=1) else: self.table_model.setSortOrder(columnName='Lv', reverse=1) self.table_model.setSortOrder(columnName='Character') self.redisplay_table() self.table_view.resizeColumn(1, 30) # Presently self.table_view.hide_column('ID') def get_infos_by_state(self): self.filter_manager.set_specific_condition( 'presently', True if self.presently.is_selected else CONDITIONLESS) results = self.filter_manager.filter(self.characters) return [character.get_table_view_full_info() for character in results] if self.state.is_full else \ [character.get_table_view_simple_info() for character in results] # 編輯角色傷害 def do_double_clicking(self, event): character_power = self.get_corresponding_character_power_in_row( self.table_view.get_row_clicked(event)) open_updating_character_power_window(self, character_power, self.update_table) def do_dragging_along_right(self, row_number): character = self.get_corresponding_character_power_in_row(row_number) delete_character_power_with_conforming( self, character, lambda: (self.characters.remove( character), self.update_table())) # 直接從 list 中拿掉,不用重撈 def do_dragging_along_left(self, row_number): character = self.get_corresponding_character_power_in_row(row_number) open_adding_new_character_power_window( self, callback=lambda cp: self.callback_after_adding_character_power(cp), character=character) # 更改角色資訊 def opening_character_update_window(self, event): self.table_view.handle_left_click(event) character = self.get_corresponding_character_power_in_row( self.table_view.get_row_clicked(event)).character open_updating_character_window(self, character, lambda: None) def get_corresponding_character_power_in_row(self, row_number): selected_id = self.table_model.getCellRecord(row_number, 0) selected_level = self.table_model.getCellRecord(row_number, 3) for character in self.characters: if character.c_id == selected_id and character.level == selected_level: return character
class FriendRecordFrame(MainFrameWithTable): def __init__(self, master): MainFrameWithTable.__init__(self, master) self.set_table_place(34, 29) self.table_view.cellwidth = 85 self.table_model = TableModelAdvance() self.table_model.set_columns(FriendRecord.TABLE_VIEW_COLUMNS, main_column='Names') self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.filter_manager.set_comparison_rule( 'used_names', rule=sub_match_request_or_japanese_character) self.filter_manager.set_comparison_rule('current_character') # 滑鼠中鍵事件註冊,設定為更新好友資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: (self.table_view.handle_left_click(event), self.opening_info_update_window(event))) self._init_left_frame() self._init_upper_frame() self._init_context() def _init_left_frame(self): button = Button(self, text="送出並返回", width=2, height=8, wraplength=1, font=(MS_JH, 12), borderwidth=2) button.place(x=4, y=44) button["command"] = self.submitting button = Button(self, text="取消並返回", width=2, height=8, wraplength=1, font=(MS_JH, 12), borderwidth=2) button.place(x=4, y=224) button["command"] = self.switching_to_friend_info def _init_upper_frame(self): basic_y = 3 # 供使用者調整日期 basic_x = 60 Label(self, text='Date:', font=(MS_JH, 11)).place(x=basic_x, y=basic_y) self.date = StringVar(value='') Entry(self, width=11, textvariable=self.date, font=(MS_JH, 11)).place(x=basic_x + 41, y=basic_y + 2) # 選擇是否顯示已登記的好友 basic_x = 256 self.is_show_recorded_friends = BooleanVar() self.is_show_recorded_friends.trace("w", lambda *args: self.update_table()) check_button = Checkbutton(self, variable=self.is_show_recorded_friends) check_button.place(x=basic_x, y=basic_y) label = Label(self, text='顯示已登記', font=(MS_JH, 11)) label.place(x=basic_x + 18, y=basic_y) bind_check_box_and_label(check_button, label) # 角色部分名稱篩選 basic_x = 366 Label(self, text='篩選:', font=(MS_JH, 11)).place(x=basic_x, y=basic_y) self.queried_name = StringVar() entry = Entry(self, width=11, textvariable=self.queried_name, font=(MS_JH, 11)) entry.place(x=basic_x + 40, y=basic_y + 2) entry.bind('<Return>', lambda event: self.update_table()) basic_x = 550 self.friend_count_str = StringVar() Label(self, textvariable=self.friend_count_str, font=(MS_JH, 12)).place(x=basic_x + 17, y=basic_y) def _init_context(self): self.date.set(date.today()) # 此次記錄的日期 # 建立 FriendRecordObjects self.friend_records = FriendModel.select_new_friend_record_list() self.friend_count_str.set('Friends: %02d' % len(self.friend_records)) # 好友總數 self.update_table() def update_table(self): # 根據名稱要求篩選,同時篩選符合設定的已登記/未登記紀錄 self.filter_manager.set_specific_condition( 'status', RECORDED if self.is_show_recorded_friends.get() else UNRECORDED) self.table_model.set_rows([ record.get_table_view_info() for record in self.filter_manager.filter(self.friend_records, self.queried_name.get()) ]) self.table_model.setSortOrder(columnName='LastProfession') self.redisplay_table() self.table_view.hide_column('ID') self.table_view.hide_column('LastProfession') def submitting(self): # 先確認資料的正確性 if self.validate_before_submitting(): # 將已經登記的 record 逐一更新到 DB 內,有衝突時則通知並略過該筆記錄 for record in self.friend_records: try: if record.status == RECORDED: FriendModel.insert_friend_record_into_db( record, self.date.get(), commit_followed=False) except StandardError as e: tkMessageBox.showinfo( 'Fail to record', '{0}\'s {1}.\n Already been skipped.'.format( record.used_names.encode('utf-8'), e), parent=self) continue FriendModel.commit() # 更新 FriendInfo Table 中的資訊(RaisedIn3Weeks, LastCharacter 等) FriendModel.take_statistic_to_update_friend_info() self.switching_to_friend_info() # 檢查數量計算並要求確認,確認後時才真正送出 def validate_before_submitting(self): updated_record_number = sum(1 for record in self.friend_records if record.status == RECORDED) return tkMessageBox.askyesno( 'Recording these records?', '總計 {0} 筆記錄,\n是否確認送出?'.format(updated_record_number), parent=self) def switching_to_friend_info(self): self.master.change_main_frame(FriendInfoFrame(self.master)) # 編輯好友記錄 def do_double_clicking(self, event): the_friend_id = int( self.table_model.getCellRecord( self.table_view.get_row_clicked(event), 0)) for record in self.friend_records: if record.f_id == the_friend_id: FriendRecordWindow(self, record, self.update_table) break self.queried_name.set('') # 此時大部分篩選都是為了找此人來編輯刪除,故編輯後清空條件 # 更改好友資訊 def opening_info_update_window(self, event): friend_info = FriendModel.select_specific_friend_info( int( self.table_model.getCellRecord( self.table_view.get_row_clicked(event), 0))) open_updating_friend_info_window(self, friend_info, lambda: None)
def __init__(self, data_getter): self._data = [] self.data_getter = data_getter self.filter_manager = FilterRuleManager()
class DrawLotsFrame(MainFrameWithTable): def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(34, 29) self.table_model = TableModelAdvance() self.table_model.set_columns(RecordOfDrawLots.TABLE_VIEW_COLUMNS) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: self.opening_character_update_window(event)) self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.records = DrawLotsModel.select_record_list() self.events = DrawLotsModel.select_event_list() self._init_adding_frame() self._init_filter_frame() self.table.tkraise() # 放上層,避免被其他元件遮到 self.update_table() def _init_adding_frame(self): # 新增酒廠的按鈕 button = Button(self, text="新增酒廠", width=2, height=5, wraplength=1, font=(MS_JH, 11)) button.place(x=7, y=41) button["command"] = lambda: open_adding_event_window( self, lambda event: (self.events.insert(0, event), self.event_filter.set_objects(self.events))) # 新增記錄的按鈕 button = Button(self, text="新增記錄", width=2, height=12, wraplength=1, font=(MS_JH, 12)) button.place(x=5, y=155) button['command'] = self.adding_record button.bind('<Button-3>', lambda event: self.adding_record(limitation=False)) def _init_filter_frame(self): basic_x = 20 Label(self, text='E:', font=(MS_JH, 12)).place(x=basic_x, y=3) self.event_filter = FilteredObjectCombobox(self, setter=lambda obj: obj.name, getter=lambda obj: obj.e_id, width=16, justify=CENTER) self.event_filter.set_objects(self.events) self.event_filter.place(x=basic_x + 18, y=3) self.event_filter.bind( '<<ComboboxSelected>>', lambda x: (self.filter_manager.set_specific_condition( 'event_id', self.event_filter.get()), self.update_table()), add='+') self.event_filter.bind( '<Button-2>', lambda event: (open_updating_event_window( self, self.event_filter.selected_object, lambda: self. event_filter.set_objects(self.events)))) basic_x += 158 Label(self, text='C:', font=(MS_JH, 12)).place(x=basic_x, y=3) self.cost_filter = FilteredCombobox(self, width=6, justify=CENTER) self.cost_filter['values'] = DRAW_LOTS_COST self.cost_filter.place(x=basic_x + 20, y=3) self.cost_filter.bind( '<<ComboboxSelected>>', lambda x: (self.filter_manager.set_specific_condition( 'cost', self.cost_filter.get()), self.update_table())) basic_x += 90 Label(self, text='R:', font=(MS_JH, 12)).place(x=basic_x, y=3) self.rank_filter = IntFilteredCombobox(self, width=3, justify=CENTER) self.rank_filter['values'] = [5, 4, 3] self.rank_filter.place(x=basic_x + 20, y=3) self.rank_filter.bind( '<<ComboboxSelected>>', lambda x: (self.filter_manager.set_specific_condition( 'rank', self.rank_filter.get()), self.update_table())) basic_x = 342 Label(self, text='Total:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.total_count = Label(self, font=(MS_JH, 12)) self.total_count.place(x=basic_x + 44, y=2) basic_x += 83 Label(self, text='SSR:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.ssr_count = Label(self, font=(MS_JH, 10)) self.ssr_count.place(x=basic_x + 34, y=-3) self.ssr_ratio = Label(self, font=(MS_JH, 9)) self.ssr_ratio.place(x=basic_x + 44, y=13) basic_x += 80 Label(self, text='SR:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.sr_count = Label(self, font=(MS_JH, 10)) self.sr_count.place(x=basic_x + 25, y=-3) self.sr_ratio = Label(self, font=(MS_JH, 9)) self.sr_ratio.place(x=basic_x + 35, y=13) basic_x += 78 Label(self, text='R:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.r_count = Label(self, font=(MS_JH, 10)) self.r_count.place(x=basic_x + 16, y=-3) self.r_ratio = Label(self, font=(MS_JH, 9)) self.r_ratio.place(x=basic_x + 26, y=13) # 清空進行篩選的條件 button = Button(self, text="清空條件", width=7, font=(MS_JH, 11)) button.place(x=658, y=-1) button["command"] = self.clearing_filter def update_table(self): results = self.filter_manager.filter(self.records) self.table_model.set_rows( [result.get_table_view_info() for result in results]) self.table_model.setSortOrder(columnName='Order', reverse=1) self.redisplay_table() self.table_view.resizeColumn(0, 55) # DrawOrder self.table_view.resizeColumn(1, 178) # Event self.table_view.resizeColumn(4, 120) # Character # 就篩選結果更新統計資料 self._update_statistic_by_specific_results(results) def _update_statistic_by_specific_results(self, results): # doing statistic: total, ssr, sr, r statistic = [0, 0, 0, 0] for record in results: record.take_statistic(statistic) # 特殊情況,顯示為 0 並結束 if statistic[0] == 0: self.total_count["text"] = 0 self.ssr_count["text"] = 0 self.ssr_ratio["text"] = 0 self.sr_count["text"] = 0 self.sr_ratio["text"] = 0 self.r_count["text"] = 0 self.r_ratio["text"] = 0 return self.total_count["text"] = '%3d' % statistic[0] self.ssr_count["text"] = statistic[1] self.ssr_ratio["text"] = self.convert_to_ratio(statistic[0], statistic[1]) self.sr_count["text"] = statistic[2] self.sr_ratio["text"] = self.convert_to_ratio(statistic[0], statistic[2]) self.r_count["text"] = statistic[3] self.r_ratio["text"] = self.convert_to_ratio(statistic[0], statistic[3]) @staticmethod def convert_to_ratio(total, numerator): ratio = round(100.0 * numerator / total, 1) return str(ratio) + '%' def clearing_filter(self): self.event_filter.set(None) self.cost_filter.set('') self.rank_filter.set('') self.filter_manager.clean_specific_condition() self.update_table() def adding_record(self, limitation=True): open_adding_new_record_window( self, DrawLotsModel.get_suitable_events(self.events, limitation), lambda record: (self.records.append(record), self.update_table())) def do_double_clicking(self, event): record = self.get_record_by_order( self.table_model.getCellRecord( self.table_view.get_row_clicked(event), 0)) open_updating_record_window(self, record, self.events, callback=self.update_table) def do_dragging_along_right(self, row_number): record = self.get_record_by_order( self.table_model.getCellRecord(row_number, 0)) delete_record_with_conforming( self, record, lambda: (self.records.remove(record), self.update_table())) # 直接從 list 中拿掉,不用重撈) def get_record_by_order(self, order): for each_record in self.records: if each_record.order == order: return each_record # 更改角色資訊 def opening_character_update_window(self, event): self.table_view.handle_left_click(event) character = self.get_record_by_order( self.table_model.getCellRecord( self.table_view.get_row_clicked(event), 0)).character open_updating_character_window(self, character, lambda: None)
class FriendRecordFrame(MainFrameWithTable): def __init__(self, master): MainFrameWithTable.__init__(self, master) self.set_table_place(34, 29) self.table_view.cellwidth = 85 self.table_model = TableModelAdvance() self.table_model.set_columns(FriendRecord.TABLE_VIEW_COLUMNS, main_column='Names') self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.filter_manager.set_comparison_rule('used_names', rule=sub_match_request_or_japanese_character) self.filter_manager.set_comparison_rule('current_character') # 滑鼠中鍵事件註冊,設定為更新好友資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: ( self.table_view.handle_left_click(event), self.opening_info_update_window(event))) self._init_left_frame() self._init_upper_frame() self._init_context() def _init_left_frame(self): button = Button(self, text="送出並返回", width=2, height=8, wraplength=1, font=(MS_JH, 12), borderwidth=2) button.place(x=4, y=44) button["command"] = self.submitting button = Button(self, text="取消並返回", width=2, height=8, wraplength=1, font=(MS_JH, 12), borderwidth=2) button.place(x=4, y=224) button["command"] = self.switching_to_friend_info def _init_upper_frame(self): basic_y = 3 # 供使用者調整日期 basic_x = 60 Label(self, text='Date:', font=(MS_JH, 11)).place(x=basic_x, y=basic_y) self.date = StringVar(value='') Entry(self, width=11, textvariable=self.date, font=(MS_JH, 11)).place(x=basic_x + 41, y=basic_y + 2) # 選擇是否顯示已登記的好友 basic_x = 256 self.is_show_recorded_friends = BooleanVar() self.is_show_recorded_friends.trace("w", lambda *args: self.update_table()) check_button = Checkbutton(self, variable=self.is_show_recorded_friends) check_button.place(x=basic_x, y=basic_y) label = Label(self, text='顯示已登記', font=(MS_JH, 11)) label.place(x=basic_x + 18, y=basic_y) bind_check_box_and_label(check_button, label) # 角色部分名稱篩選 basic_x = 366 Label(self, text='篩選:', font=(MS_JH, 11)).place(x=basic_x, y=basic_y) self.queried_name = StringVar() entry = Entry(self, width=11, textvariable=self.queried_name, font=(MS_JH, 11)) entry.place(x=basic_x + 40, y=basic_y + 2) entry.bind('<Return>', lambda event: self.update_table()) basic_x = 550 self.friend_count_str = StringVar() Label(self, textvariable=self.friend_count_str, font=(MS_JH, 12)).place(x=basic_x + 17, y=basic_y) def _init_context(self): self.date.set(date.today()) # 此次記錄的日期 # 建立 FriendRecordObjects self.friend_records = FriendModel.select_new_friend_record_list() self.friend_count_str.set('Friends: %02d' % len(self.friend_records)) # 好友總數 self.update_table() def update_table(self): # 根據名稱要求篩選,同時篩選符合設定的已登記/未登記紀錄 self.filter_manager.set_specific_condition( 'status', RECORDED if self.is_show_recorded_friends.get() else UNRECORDED) self.table_model.set_rows([record.get_table_view_info() for record in self.filter_manager.filter(self.friend_records, self.queried_name.get())]) self.table_model.setSortOrder(columnName='LastProfession') self.redisplay_table() self.table_view.hide_column('ID') self.table_view.hide_column('LastProfession') def submitting(self): # 先確認資料的正確性 if self.validate_before_submitting(): # 將已經登記的 record 逐一更新到 DB 內,有衝突時則通知並略過該筆記錄 for record in self.friend_records: try: if record.status == RECORDED: FriendModel.insert_friend_record_into_db(record, self.date.get(), commit_followed=False) except StandardError as e: tkMessageBox.showinfo('Fail to record', '{0}\'s {1}.\n Already been skipped.'.format( record.used_names.encode('utf-8'), e), parent=self) continue FriendModel.commit() # 更新 FriendInfo Table 中的資訊(RaisedIn3Weeks, LastCharacter 等) FriendModel.take_statistic_to_update_friend_info() self.switching_to_friend_info() # 檢查數量計算並要求確認,確認後時才真正送出 def validate_before_submitting(self): updated_record_number = sum(1 for record in self.friend_records if record.status == RECORDED) return tkMessageBox.askyesno('Recording these records?', '總計 {0} 筆記錄,\n是否確認送出?'.format( updated_record_number), parent=self) def switching_to_friend_info(self): self.master.change_main_frame(FriendInfoFrame(self.master)) # 編輯好友記錄 def do_double_clicking(self, event): the_friend_id = int(self.table_model.getCellRecord(self.table_view.get_row_clicked(event), 0)) for record in self.friend_records: if record.f_id == the_friend_id: FriendRecordWindow(self, record, self.update_table) break self.queried_name.set('') # 此時大部分篩選都是為了找此人來編輯刪除,故編輯後清空條件 # 更改好友資訊 def opening_info_update_window(self, event): friend_info = FriendModel.select_specific_friend_info( int(self.table_model.getCellRecord(self.table_view.get_row_clicked(event), 0))) open_updating_friend_info_window(self, friend_info, lambda: None)
class DrawLotsFrame(MainFrameWithTable): def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) self.set_table_place(34, 29) self.table_model = TableModelAdvance() self.table_model.set_columns(RecordOfDrawLots.TABLE_VIEW_COLUMNS) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: self.opening_character_update_window(event)) self.table_view.setModel(self.table_model) self.filter_manager = FilterRuleManager() self.records = DrawLotsModel.select_record_list() self.events = DrawLotsModel.select_event_list() self._init_adding_frame() self._init_filter_frame() self.table.tkraise() # 放上層,避免被其他元件遮到 self.update_table() def _init_adding_frame(self): # 新增酒廠的按鈕 button = Button(self, text="新增酒廠", width=2, height=5, wraplength=1, font=(MS_JH, 11)) button.place(x=7, y=41) button["command"] = lambda: open_adding_event_window(self, lambda event: ( self.events.insert(0, event), self.event_filter.set_objects(self.events))) # 新增記錄的按鈕 button = Button(self, text="新增記錄", width=2, height=12, wraplength=1, font=(MS_JH, 12)) button.place(x=5, y=155) button['command'] = self.adding_record button.bind('<Button-3>', lambda event: self.adding_record(limitation=False)) def _init_filter_frame(self): basic_x = 20 Label(self, text='E:', font=(MS_JH, 12)).place(x=basic_x, y=3) self.event_filter = FilteredObjectCombobox( self, setter=lambda obj: obj.name, getter=lambda obj: obj.e_id, width=16, justify=CENTER) self.event_filter.set_objects(self.events) self.event_filter.place(x=basic_x + 18, y=3) self.event_filter.bind('<<ComboboxSelected>>', lambda x: (self.filter_manager.set_specific_condition( 'event_id', self.event_filter.get()), self.update_table()), add='+') self.event_filter.bind('<Button-2>', lambda event: (open_updating_event_window( self, self.event_filter.selected_object, lambda: self.event_filter.set_objects(self.events)))) basic_x += 158 Label(self, text='C:', font=(MS_JH, 12)).place(x=basic_x, y=3) self.cost_filter = FilteredCombobox(self, width=6, justify=CENTER) self.cost_filter['values'] = DRAW_LOTS_COST self.cost_filter.place(x=basic_x + 20, y=3) self.cost_filter.bind('<<ComboboxSelected>>', lambda x: (self.filter_manager.set_specific_condition('cost', self.cost_filter.get()), self.update_table())) basic_x += 90 Label(self, text='R:', font=(MS_JH, 12)).place(x=basic_x, y=3) self.rank_filter = IntFilteredCombobox(self, width=3, justify=CENTER) self.rank_filter['values'] = [5, 4, 3] self.rank_filter.place(x=basic_x + 20, y=3) self.rank_filter.bind('<<ComboboxSelected>>', lambda x: (self.filter_manager.set_specific_condition('rank', self.rank_filter.get()), self.update_table())) basic_x = 342 Label(self, text='Total:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.total_count = Label(self, font=(MS_JH, 12)) self.total_count.place(x=basic_x + 44, y=2) basic_x += 83 Label(self, text='SSR:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.ssr_count = Label(self, font=(MS_JH, 10)) self.ssr_count.place(x=basic_x + 34, y=-3) self.ssr_ratio = Label(self, font=(MS_JH, 9)) self.ssr_ratio.place(x=basic_x + 44, y=13) basic_x += 80 Label(self, text='SR:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.sr_count = Label(self, font=(MS_JH, 10)) self.sr_count.place(x=basic_x + 25, y=-3) self.sr_ratio = Label(self, font=(MS_JH, 9)) self.sr_ratio.place(x=basic_x + 35, y=13) basic_x += 78 Label(self, text='R:', font=(MS_JH, 12)).place(x=basic_x, y=2) self.r_count = Label(self, font=(MS_JH, 10)) self.r_count.place(x=basic_x + 16, y=-3) self.r_ratio = Label(self, font=(MS_JH, 9)) self.r_ratio.place(x=basic_x + 26, y=13) # 清空進行篩選的條件 button = Button(self, text="清空條件", width=7, font=(MS_JH, 11)) button.place(x=658, y=-1) button["command"] = self.clearing_filter def update_table(self): results = self.filter_manager.filter(self.records) self.table_model.set_rows([result.get_table_view_info() for result in results]) self.table_model.setSortOrder(columnName='Order', reverse=1) self.redisplay_table() self.table_view.resizeColumn(0, 55) # DrawOrder self.table_view.resizeColumn(1, 178) # Event self.table_view.resizeColumn(4, 120) # Character # 就篩選結果更新統計資料 self._update_statistic_by_specific_results(results) def _update_statistic_by_specific_results(self, results): # doing statistic: total, ssr, sr, r statistic = [0, 0, 0, 0] for record in results: record.take_statistic(statistic) # 特殊情況,顯示為 0 並結束 if statistic[0] == 0: self.total_count["text"] = 0 self.ssr_count["text"] = 0 self.ssr_ratio["text"] = 0 self.sr_count["text"] = 0 self.sr_ratio["text"] = 0 self.r_count["text"] = 0 self.r_ratio["text"] = 0 return self.total_count["text"] = '%3d' % statistic[0] self.ssr_count["text"] = statistic[1] self.ssr_ratio["text"] = self.convert_to_ratio(statistic[0], statistic[1]) self.sr_count["text"] = statistic[2] self.sr_ratio["text"] = self.convert_to_ratio(statistic[0], statistic[2]) self.r_count["text"] = statistic[3] self.r_ratio["text"] = self.convert_to_ratio(statistic[0], statistic[3]) @staticmethod def convert_to_ratio(total, numerator): ratio = round(100.0 * numerator / total, 1) return str(ratio) + '%' def clearing_filter(self): self.event_filter.set(None) self.cost_filter.set('') self.rank_filter.set('') self.filter_manager.clean_specific_condition() self.update_table() def adding_record(self, limitation=True): open_adding_new_record_window(self, DrawLotsModel.get_suitable_events(self.events, limitation), lambda record: ( self.records.append(record), self.update_table())) def do_double_clicking(self, event): record = self.get_record_by_order(self.table_model.getCellRecord(self.table_view.get_row_clicked(event), 0)) open_updating_record_window(self, record, self.events, callback=self.update_table) def do_dragging_along_right(self, row_number): record = self.get_record_by_order(self.table_model.getCellRecord(row_number, 0)) delete_record_with_conforming( self, record, lambda: (self.records.remove(record), self.update_table())) # 直接從 list 中拿掉,不用重撈) def get_record_by_order(self, order): for each_record in self.records: if each_record.order == order: return each_record # 更改角色資訊 def opening_character_update_window(self, event): self.table_view.handle_left_click(event) character = self.get_record_by_order( self.table_model.getCellRecord(self.table_view.get_row_clicked(event), 0)).character open_updating_character_window(self, character, lambda: None)
class CharacterSelectionWindow(BasicWindow): def __init__(self, master, callback, character_selected, width=422, height=155, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title('Character selection') self.records = None self.update_records() self.filter_manager = FilterRuleManager() self.filter_manager.set_comparison_rule(0) self.filter_manager.set_comparison_rule(1) self._init_widgets() self._init_character_selected(character_selected) self.callback = callback def _init_widgets(self): self.profession_selector = ProfessionSelector(self, self.updating_request_profession) self.profession_selector.place(x=5, y=5) self.rank_selector = RankSelector(self, self.updating_request_rank) self.rank_selector.place(x=5, y=53) Label(self, text='所屬', width=5, font=("", 10)).place(x=221, y=5) self.belonged_selector = FilteredCombobox(self, width=7, font=("", 11), justify=CENTER) self.belonged_selector['values'] = BELONGEDS self.belonged_selector.place(x=213, y=22) self.belonged_selector.bind('<<ComboboxSelected>>', lambda x: self.updating_request_belonged(self.belonged_selector.get())) self.belonged_selector.bind('<Return>', lambda x: self.character_selector.focus_set()) Label(self, text='篩選', width=5, font=("", 11)).place(x=222, y=54) self.name_request = StringVar(value='') entry = Entry(self, width=8, textvariable=self.name_request, font=("", 12)) entry.place(x=214, y=73) entry.bind('<Return>', lambda x: self.updating_request_name()) entry.bind('<Escape>', lambda x: (self.name_request.set(''), self.updating_request_name())) Label(self, text='Character', width=10, font=("", 12)).place(x=304, y=26) self.character_selector = ttk.Combobox(self, state='readonly', width=10, font=("", 12), justify=CENTER) self.character_selector.place(x=305, y=48) self.character_selector.bind('<Return>', lambda x: self.submitting()) # 熱鍵,直接指過來 self.bind('<f>', lambda x: self.character_selector.focus_set()) y_position = 115 # 送交的按鈕 button = Button(self, text="選擇此角色", width=25, borderwidth=3) button.place(x=17, y=y_position) button["command"] = self.submitting # 新增角色的按鈕 button = Button(self, text="新增角色", width=9, borderwidth=3) button.place(x=225, y=y_position) button["command"] = lambda: open_adding_new_jp_character_window( self, lambda new_character: (self.update_records(), self.updating_character_selector())) # 取消並結束的按鈕 button = Button(self, text="放棄選擇", width=9, borderwidth=3) button.place(x=317, y=y_position) button["command"] = self.destroy def _init_character_selected(self, character_selected): if character_selected is None: pass elif isinstance(character_selected, Character): self.profession_selector.select(character_selected.profession) self.rank_selector.select(character_selected.rank) self.updating_character_selector() self.character_selector.set(character_selected.nickname) else: raise TypeError('In CharacterSelectionWindow, arg: \"character_selected\"') def updating_request_profession(self, profession): self.filter_manager.set_specific_condition(2, profession) self.updating_character_selector() self.character_selector.focus_set() def updating_request_rank(self, rank): self.filter_manager.set_specific_condition(3, rank, match_requested_rank) self.updating_character_selector() self.character_selector.focus_set() def updating_request_belonged(self, belonged): self.filter_manager.set_specific_condition(4, belonged) self.updating_character_selector() def updating_request_name(self): self.updating_character_selector() self.character_selector.focus_set() # 清除原本的選擇,並更新可選擇的角色 def updating_character_selector(self): self.character_selector.set('') character_matched = [] for character_infos in self.filter_manager.filter(self.records, self.name_request.get()): character_matched.append(character_infos[0]) self.character_selector['values'] = character_matched # 有選擇的情況下才回傳,否則彈出錯誤視窗 def submitting(self): if self.character_selector.get() != '': self.callback(CharacterModel.select_character_by_specific_column('Nickname', self.character_selector.get())) self.destroy() else: tkMessageBox.showwarning("Character haven't selected", '\"Character\" 未選\n', parent=self) def update_records(self): self.records = CharacterModel.select_character_info_for_character_selector()
class DataHolder(object): def __init__(self, data_getter): self._data = [] self.data_getter = data_getter self.filter_manager = FilterRuleManager() def update_data(self): self._data = self.data_getter() def append(self, datum): self._data.append(datum) def remove(self, datum): self._data.remove(datum) def get_specific_datum(self, key, request): for datum in self._data: if datum[key] == request: return datum # Templete method def get_displaying_data(self, request): pass def get_matched_data(self, request): return self.filter_manager.filter(self._data, request) def set_comparison_rule(self, key, rule=sub_match_request): self.filter_manager.set_comparison_rule(key, rule) def clean_comparison_rules(self): self.filter_manager.clean_comparison_rules() def set_specific_condition(self, key, request, rule=match_request): self.filter_manager.set_specific_condition(key, request, rule) def clean_specific_condition(self): self.filter_manager.clean_specific_condition() def set_sub_object_filter(self, key, filter): self.filter_manager.set_sub_object_filter(key, filter) def clean_sub_object_filter(self): self.filter_manager.clean_sub_object_filter()
class CharacterWeaponFrame(MainFrameWithTable): def __init__(self, master, **kwargs): MainFrameWithTable.__init__(self, master, **kwargs) # 滑鼠中鍵事件註冊,設定為更改角色詳細資訊,並選取該列 self.table_view.bind("<Button-2>", lambda event: self.opening_character_update_window(event)) self.set_table_place(6, 31) self.filter_manager = FilterRuleManager() self.table_model = TableModelAdvance() self.table_model.set_columns(CharacterWeapon.TABLE_VIEW_COLUMNS) self.table_view.setModel(self.table_model) self.characters = CharacterWeaponModel.select_character_weapon_list() self._init_upper_frame() self.update_table() def _init_upper_frame(self): self.insufficiently = ToggleButton(self, text='Insufficiently', width=14, font=(SCP, 8), relief=RIDGE) self.insufficiently.bind('<Button-1>', lambda event: ( self.filter_manager.set_specific_condition( 'unforged', 0 if self.insufficiently.is_selected else CONDITIONLESS, rule=not_match_request), self.update_table()), add='+') self.insufficiently.place(x=380, y=3) Label(self, text='Type:', width=5, font=(MS_JH, 11)).place(x=510, y=3) self.type_selector = FilteredCombobox(self, width=4, font=(MS_JH, 9), justify=CENTER, state='readonly') self.type_selector['values'] = WEAPONS self.type_selector.place(x=558, y=5) self.type_selector.bind('<<ComboboxSelected>>', lambda event: ( self.filter_manager.set_specific_condition('weapon_type', self.type_selector.get()), self.update_table())) button = Button(self, text='新增', width=8, font=(MS_JH, 10)) button.place(x=640, y=1) button["command"] = lambda: open_adding_new_character_weapon_window( self, callback=lambda cw: (self.characters.append(cw), self.update_table())) def update_table(self): results = self.filter_manager.filter(self.characters) self.table_model.set_rows([result.get_table_view_info() for result in results]) self.table_model.setSortOrder(columnName='Left', reverse=1) self.redisplay_table() # 更改角色資訊 def opening_character_update_window(self, event): self.table_view.handle_left_click(event) character = self.get_corresponding_character_weapon_in_row(self.table_view.get_row_clicked(event)).character open_updating_character_window(self, character, lambda: None) # 編輯武器狀態 def do_double_clicking(self, event): character_weapon = self.get_corresponding_character_weapon_in_row(self.table_view.get_row_clicked(event)) open_updating_character_weapon_window(self, character_weapon, self.update_table) def do_dragging_along_right(self, row_number): character = self.get_corresponding_character_weapon_in_row(row_number) delete_character_weapon_with_conforming(self, character, lambda: ( self.characters.remove(character), self.update_table())) # 直接從 list 中拿掉,不用重撈 def get_corresponding_character_weapon_in_row(self, row_number): selected_name = self.table_model.getCellRecord(row_number, 0) for character in self.characters: if character.nickname.encode('utf-8') == selected_name: return character