def __init__(self, parent=None): super(PwdGenerator, self).__init__(parent) self.dialog = Ui_MainDialog() self.dialog.setupUi(self) self.connectSlots()
class PwdGenerator(QDialog): ''' Main class ''' def __init__(self, parent=None): super(PwdGenerator, self).__init__(parent) self.dialog = Ui_MainDialog() self.dialog.setupUi(self) self.connectSlots() def connectSlots(self): self.connect(self.dialog.btn_GenNewPwd, SIGNAL("clicked()"), self.btn_GenNewPwd_cb) self.connect(self.dialog.btn_About, SIGNAL("clicked()"), self.btn_About_cb) def generate_abc(self): '''Returns a list of available characters selected by user''' abc = [] if self.dialog.chbox_use_digits.checkState() == Qt.Checked: abc.extend(map(str, range(0,10))) if self.dialog.chbox_use_letters.checkState() == Qt.Checked: abc.extend(map(chr, range(97, 123))) abc.extend(map(chr, range(65, 91))) qcheckbox_class_name = type(QCheckBox()).__name__ if (self.dialog.chbox_use_symbols.checkState() == Qt.Checked): for check_box in self.dialog.groupBox_Symbols.children(): if type(check_box).__name__ == qcheckbox_class_name: if check_box.checkState() == Qt.Checked: if check_box.text() == 'space': abc.append(' ') elif check_box.text() == "\\": abc.append('\\') elif check_box.text() == "&&": abc.append("&") else: abc.append(str(check_box.text())) return abc def btn_About_cb(self): dialog = AboutDialog() dialog.exec_() def btn_GenNewPwd_cb(self): '''Generate random password''' abc = self.generate_abc() abc_len = len(abc) pwd = "" pwd_len = int(self.dialog.spinbox_char_num.text()) if abc_len < 1: return for i in xrange(pwd_len): pwd += str(abc[randint(0, abc_len-1)]) self.dialog.inp_Pwd.setText(pwd)