def delete_friend_with_conforming(master, friend_info, callback): if tkMessageBox.askyesno( 'Deleting', 'Are you sure you want to delete friend 「{0}」?'.format( friend_info.used_names.encode('utf-8')), parent=master): FriendModel.delete_friend_from_db(friend_info) callback()
def _init_upper_frame(self): basic_y = 3 basic_x = 52 button = Button(self, text="新增好友", width=8, font=(MS_JH, 11)) button.place(x=basic_x, y=-1) button["command"] = self.adding_new_friend basic_x = 153 Label(self, text='Order:', font=(MS_JH, 12)).place(x=basic_x, y=basic_y) self.order_selector = ttk.Combobox(self, state='readonly', width=10, justify=CENTER) self.order_selector.set(FriendInfo.TABLE_VIEW_SORTABLE_COLUMNS[0]) self.order_selector['values'] = FriendInfo.TABLE_VIEW_SORTABLE_COLUMNS self.order_selector.place(x=basic_x + 55, y=basic_y + 1) self.order_selector.bind('<<ComboboxSelected>>', lambda x: self.redisplay_table_by_order_rule()) # 角色部分名稱篩選 basic_x = 322 Label(self, text='篩選:', font=(MS_JH, 12)).place(x=basic_x, y=basic_y) self.queried_name = StringVar() entry = Entry(self, width=8, textvariable=self.queried_name, font=(MS_JH, 11)) entry.place(x=basic_x + 42, y=basic_y + 2) entry.bind('<Return>', lambda x: self.update_table()) basic_x = 460 self.friend_count_var = StringVar() Label(self, textvariable=self.friend_count_var, font=(MS_JH, 12)).place(x=basic_x + 17, y=basic_y) basic_x = 565 since_last_record = 'Since: {0} days ago'.format(FriendModel.get_since_all_record_date()) Label(self, text=since_last_record, 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 _init_upper_frame(self): basic_y = 3 basic_x = 52 button = Button(self, text="新增好友", width=8, font=(MS_JH, 11)) button.place(x=basic_x, y=-1) button["command"] = self.adding_new_friend basic_x = 153 Label(self, text='Order:', font=(MS_JH, 12)).place(x=basic_x, y=basic_y) self.order_selector = ttk.Combobox(self, state='readonly', width=10, justify=CENTER) self.order_selector.set(FriendInfo.TABLE_VIEW_SORTABLE_COLUMNS[0]) self.order_selector['values'] = FriendInfo.TABLE_VIEW_SORTABLE_COLUMNS self.order_selector.place(x=basic_x + 55, y=basic_y + 1) self.order_selector.bind( '<<ComboboxSelected>>', lambda x: self.redisplay_table_by_order_rule()) # 角色部分名稱篩選 basic_x = 322 Label(self, text='篩選:', font=(MS_JH, 12)).place(x=basic_x, y=basic_y) self.queried_name = StringVar() entry = Entry(self, width=8, textvariable=self.queried_name, font=(MS_JH, 11)) entry.place(x=basic_x + 42, y=basic_y + 2) entry.bind('<Return>', lambda x: self.update_table()) basic_x = 460 self.friend_count_var = StringVar() Label(self, textvariable=self.friend_count_var, font=(MS_JH, 12)).place(x=basic_x + 17, y=basic_y) basic_x = 565 since_last_record = 'Since: {0} days ago'.format( FriendModel.get_since_all_record_date()) Label(self, text=since_last_record, font=(MS_JH, 12)).place(x=basic_x + 17, y=basic_y)
def __init__(self, master): MainFrameWithTable.__init__(self, master) self.model = FriendModel.FriendInfoModel() self.set_table_place(34, 29) self.table_model = TableModelAdvance() self.table_model.set_columns(FriendInfo.TABLE_VIEW_COLUMNS, main_column='UsedNames') self.table_view.setModel(self.table_model) # 滑鼠中鍵事件註冊,若為設定為更新好友資訊,並選取該列 self.table_view.bind( "<Button-2>", lambda event: (self.table_view.handle_left_click(event), open_updating_friend_info_window( self, self.get_corresponding_friend_info_in_row( self.table_view.get_row_clicked(event)), self.update_table ))) self._init_left_frame() self._init_upper_frame() self.model.update_data() self.update_all()
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 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 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 delete_friend_with_conforming(master, friend_info, callback): if tkMessageBox.askyesno('Deleting', 'Are you sure you want to delete friend 「{0}」?'.format( friend_info.used_names.encode('utf-8')), parent=master): FriendModel.delete_friend_from_db(friend_info) callback()
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 open_updating_friend_info_window(master, friend_info, callback): popup = FriendInfoWindow( master, friend_info, lambda: (FriendModel.update_friend_info_into_db(friend_info), callback()) ) master.wait_window(popup)
def open_updating_friend_info_window(master, friend_info, callback): popup = FriendInfoWindow( master, friend_info, lambda: (FriendModel.update_friend_info_into_db(friend_info), callback())) master.wait_window(popup)