Exemplo n.º 1
0
class CharacterFrame(MainFrameWithTable):
    def __init__(self, master, **kwargs):
        MainFrameWithTable.__init__(self, master, **kwargs)
        self.model = CharacterModel.CharacterFrameModel()
        self.set_table_place(34, 38)
        self.table_model = TableModelAdvance()
        self.table_model.set_columns(Character.TABLE_VIEW_COLUMNS,
                                     main_column='Nickname')
        self.table_view.setModel(self.table_model)

        self._init_upper_frame()
        self._init_left_frame()

        self.model.update_data()
        self.update_table()

    def _init_left_frame(self):
        self.character_count = IntVar()
        Label(self,
              textvariable=self.character_count,
              width=3,
              font=(SCP, 9, 'bold')).place(x=5, y=10)

        # 新增記錄的按鈕,分別是日、台服
        button = Button(self,
                        text="新增日服角色",
                        width=2,
                        height=10,
                        wraplength=1,
                        font=(MS_JH, 12))
        button.place(x=4, y=50)
        button["command"] = lambda: open_adding_new_jp_character_window(
            self, lambda character: self.callback_after_adding_character(
                character))
        button = Button(self,
                        text="台服角色",
                        width=2,
                        height=6,
                        wraplength=1,
                        font=(MS_JH, 11))
        button.place(x=5, y=280)
        button["command"] = lambda: open_adding_new_cn_character_window(
            self, lambda character: self.callback_after_adding_character(
                character))

    def _init_upper_frame(self):
        filter_frame = Frame(self, width=self['width'], height=40)
        filter_frame.place(x=0, y=0)

        current_x = 45
        self.profession_selector = ProfessionSelector(filter_frame,
                                                      self.updating_profession)
        self.profession_selector.place(x=current_x, y=-4)

        current_x += 199
        self.rank_selector = RankSelector(filter_frame, self.updating_rank)
        self.rank_selector.place(x=current_x, y=-4)

        # 所屬篩選
        current_x = 448
        Label(filter_frame, text='所屬:',
              font=(MS_JH, 10)).place(x=current_x + 10, y=-3)
        self.belonged = FilteredCombobox(filter_frame, width=6, justify=CENTER)
        self.belonged['values'] = BELONGEDS
        self.belonged.place(x=current_x, y=16)
        self.belonged.bind('<<ComboboxSelected>>',
                           lambda event: self.updating_belonged())

        # 角色部分名稱篩選
        current_x += 75
        Label(filter_frame, text='篩選:', font=(MS_JH, 12)).place(x=current_x,
                                                                y=7)
        self.request = StringVar()
        entry = Entry(filter_frame,
                      width=9,
                      textvariable=self.request,
                      font=(MS_JH, 11))
        entry.place(x=current_x + 42, y=9)
        entry.bind('<Return>', lambda event: self.update_table())

        # 清空進行篩選的條件
        button = Button(filter_frame, text="清空條件", width=7, font=(MS_JH, 11))
        button.place(x=667, y=3)
        button["command"] = self.clearing_filters

    def update_table(self):
        # 將符合篩選條件的角色加入欲呈現表格中
        results = self.model.get_displaying_data(self.request.get())
        self.character_count.set(len(results))
        self.table_model.set_rows(results)

        self.table_model.setSortOrder(columnName='Rank', reverse=1)
        self.table_model.setSortOrder(columnName='Profession')

        self.redisplay_table()
        self.table_view.hide_column('ID')

    def callback_after_adding_character(self, character):
        self.model.append(character)
        self.update_table()

    def updating_profession(self, request):
        self.model.set_specific_condition('profession', request)
        self.update_table()

    def updating_rank(self, request):
        self.model.set_specific_condition('rank', request,
                                          match_requested_rank)
        self.update_table()

    def updating_belonged(self):
        self.model.set_specific_condition('belonged', self.belonged.get())
        self.update_table()

    def clearing_filters(self):
        self.profession_selector.clean_current_selection()
        self.rank_selector.clean_current_selection()
        self.belonged.set('')
        self.model.clean_specific_condition()
        self.request.set('')
        self.update_table()

    def do_double_clicking(self, event):
        character = self.get_corresponding_character_in_row(
            self.table_view.get_row_clicked(event))
        open_updating_character_window(self, character,
                                       lambda: self.update_table())

    # 主要供方便刪除測試或誤加的角色用,未檢查其他 table 中使用到的該角色
    def do_dragging_along_right(self, row_number):
        character = self.get_corresponding_character_in_row(row_number)
        delete_character_with_conforming(
            self, character, lambda: (self.model.remove(
                character), self.update_table()))  # 直接從 list 中拿掉,不用重撈

    def get_corresponding_character_in_row(self, row_number):
        selected_id = self.table_model.getCellRecord(row_number, 0)
        return self.model.get_specific_datum('c_id', selected_id)
Exemplo n.º 2
0
class CharacterFrame(MainFrameWithTable):
    def __init__(self, master, **kwargs):
        MainFrameWithTable.__init__(self, master, **kwargs)
        self.model = CharacterModel.CharacterFrameModel()
        self.set_table_place(34, 38)
        self.table_model = TableModelAdvance()
        self.table_model.set_columns(Character.TABLE_VIEW_COLUMNS, main_column="Nickname")
        self.table_view.setModel(self.table_model)

        self._init_upper_frame()
        self._init_left_frame()

        self.model.update_data()
        self.update_table()

    def _init_left_frame(self):
        self.character_count = IntVar()
        Label(self, textvariable=self.character_count, width=3, font=(SCP, 9, "bold")).place(x=5, y=10)

        # 新增記錄的按鈕,分別是日、台服
        button = Button(self, text="新增日服角色", width=2, height=10, wraplength=1, font=(MS_JH, 12))
        button.place(x=4, y=50)
        button["command"] = lambda: open_adding_new_jp_character_window(
            self, lambda character: self.callback_after_adding_character(character)
        )
        button = Button(self, text="台服角色", width=2, height=6, wraplength=1, font=(MS_JH, 11))
        button.place(x=5, y=280)
        button["command"] = lambda: open_adding_new_cn_character_window(
            self, lambda character: self.callback_after_adding_character(character)
        )

    def _init_upper_frame(self):
        filter_frame = Frame(self, width=self["width"], height=40)
        filter_frame.place(x=0, y=0)

        current_x = 45
        self.profession_selector = ProfessionSelector(filter_frame, self.updating_profession)
        self.profession_selector.place(x=current_x, y=-4)

        current_x += 199
        self.rank_selector = RankSelector(filter_frame, self.updating_rank)
        self.rank_selector.place(x=current_x, y=-4)

        # 所屬篩選
        current_x = 448
        Label(filter_frame, text="所屬:", font=(MS_JH, 10)).place(x=current_x + 10, y=-3)
        self.belonged = FilteredCombobox(filter_frame, width=6, justify=CENTER)
        self.belonged["values"] = BELONGEDS
        self.belonged.place(x=current_x, y=16)
        self.belonged.bind("<<ComboboxSelected>>", lambda event: self.updating_belonged())

        # 角色部分名稱篩選
        current_x += 75
        Label(filter_frame, text="篩選:", font=(MS_JH, 12)).place(x=current_x, y=7)
        self.request = StringVar()
        entry = Entry(filter_frame, width=9, textvariable=self.request, font=(MS_JH, 11))
        entry.place(x=current_x + 42, y=9)
        entry.bind("<Return>", lambda event: self.update_table())

        # 清空進行篩選的條件
        button = Button(filter_frame, text="清空條件", width=7, font=(MS_JH, 11))
        button.place(x=667, y=3)
        button["command"] = self.clearing_filters

    def update_table(self):
        # 將符合篩選條件的角色加入欲呈現表格中
        results = self.model.get_displaying_data(self.request.get())
        self.character_count.set(len(results))
        self.table_model.set_rows(results)

        self.table_model.setSortOrder(columnName="Rank", reverse=1)
        self.table_model.setSortOrder(columnName="Profession")

        self.redisplay_table()
        self.table_view.hide_column("ID")

    def callback_after_adding_character(self, character):
        self.model.append(character)
        self.update_table()

    def updating_profession(self, request):
        self.model.set_specific_condition("profession", request)
        self.update_table()

    def updating_rank(self, request):
        self.model.set_specific_condition("rank", request, match_requested_rank)
        self.update_table()

    def updating_belonged(self):
        self.model.set_specific_condition("belonged", self.belonged.get())
        self.update_table()

    def clearing_filters(self):
        self.profession_selector.clean_current_selection()
        self.rank_selector.clean_current_selection()
        self.belonged.set("")
        self.model.clean_specific_condition()
        self.request.set("")
        self.update_table()

    def do_double_clicking(self, event):
        character = self.get_corresponding_character_in_row(self.table_view.get_row_clicked(event))
        open_updating_character_window(self, character, lambda: self.update_table())

    # 主要供方便刪除測試或誤加的角色用,未檢查其他 table 中使用到的該角色
    def do_dragging_along_right(self, row_number):
        character = self.get_corresponding_character_in_row(row_number)
        delete_character_with_conforming(
            self, character, lambda: (self.model.remove(character), self.update_table())
        )  # 直接從 list 中拿掉,不用重撈

    def get_corresponding_character_in_row(self, row_number):
        selected_id = self.table_model.getCellRecord(row_number, 0)
        return self.model.get_specific_datum("c_id", selected_id)
Exemplo n.º 3
0
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()