def updateGroupList(self): self.updating_group = True all, k = None, None try: headerItem = QTableWidgetItem() headerItem.setText(self.__tr("Group")) self.GroupTableWidget.clear() self.GroupTableWidget.setColumnCount(1) self.GroupTableWidget.setHorizontalHeaderItem(0, headerItem) self.GroupTableWidget.setColumnWidth(0, self.GroupTableWidget.width()) groups = self.db.get_all_groups() groups.sort() self.GroupTableWidget.setRowCount(len(groups)) # Force All group to top of table all = QTableWidgetItem(self.__tr("All")) all.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.GroupTableWidget.setItem(0, 0, all) j = 1 for g in groups: if g == to_unicode('All'): continue # i = QTableWidgetItem(str(g)) if isinstance(g, int): i = QTableWidgetItem(str(g)) else: i = QTableWidgetItem(from_unicode_to_str(g)) if g == self.group: k = i i.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsDropEnabled) self.GroupTableWidget.setItem(j, 0, i) j += 1 finally: self.updating_group = False if k is not None: k.setSelected(True) elif all is not None: all.setSelected(True)
def updateNameList(self): self.updating_name = True m, k = None, None try: headerItem = QTableWidgetItem() headerItem.setText(self.__tr("Name")) self.NameTableWidget.clear() self.NameTableWidget.setColumnCount(1) self.NameTableWidget.setHorizontalHeaderItem(0, headerItem) self.NameTableWidget.setColumnWidth(0, self.NameTableWidget.width()) names = self.db.group_members(self.group) filtered_names = [n for n in names if not n.startswith('__')] filtered_names.sort() self.NameTableWidget.setRowCount(len(filtered_names)) for j, n in enumerate(filtered_names): if isinstance(n, int): i = QTableWidgetItem(str(n)) else: i = QTableWidgetItem(from_unicode_to_str(n)) i.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled) self.NameTableWidget.setItem(j, 0, i) if n == self.name: m = i if j == 0: k = i finally: self.updating_name = False if m is not None: m.setSelected(True) elif k is not None: k.setSelected(True) else: # no names, disable name frame and name actions self.name = None self.RemoveNameAction.setEnabled(False) self.NewGroupFromSelectionAction.setEnabled(False) self.RemoveFromGroupAction.setEnabled(False) self.AddToGroupAction.setEnabled(False) self.updateDetailsFrame()
ok = True for x in phone_num: if x not in '0123456789-(+) ': log.error("Invalid characters in phone number. Please only use 0-9, -, (, +, and )") ok = False break if not ok: continue break while True: if current_station_name: station_name = input(log.bold("\nEnter the name and/or company for this device (c=use current:'%s'*, q=quit) ?"%from_unicode_to_str(current_station_name))) else: station_name = input(log.bold("\nEnter the name and/or company for this device (q=quit) ?")) if station_name.strip().lower() == 'q': log.info("OK, done.") clean_exit(0) if current_station_name and (not station_name or station_name.strip().lower() == 'c'): station_name = current_station_name ### Here station_name can be unicode or utf-8 sequence. ### making sure to convert data to unicode for all the cases. try: station_name.encode('utf-8') except (UnicodeEncodeError,UnicodeDecodeError): station_name = station_name.decode('utf-8')
"Invalid characters in phone number. Please only use 0-9, -, (, +, and )" ) ok = False break if not ok: continue break while True: if current_station_name: station_name = input( log.bold( "\nEnter the name and/or company for this device (c=use current:'%s'*, q=quit) ?" % from_unicode_to_str( current_station_name))) else: station_name = input( log.bold( "\nEnter the name and/or company for this device (q=quit) ?" )) if station_name.strip().lower() == 'q': log.info("OK, done.") clean_exit(0) if current_station_name and ( not station_name or station_name.strip().lower() == 'c'): station_name = current_station_name ### Here station_name can be unicode or utf-8 sequence.