def _other_view(self): # For other screens aside Login Screen And Main View Screen self.stacked = QStackedWidget() self.main_grid_widget = QWidget() self.main_grid = QGridLayout() back_btn = QCommandLinkButton() back_btn.setIcon(QIcon("./assets/icons/back.png")) back_btn.setIconSize(QSize(30, 30)) self.main_grid_widget.setLayout(self.main_grid) self.main_grid.addWidget(back_btn, 0, 0) self.main_grid.addWidget(self.stacked, 1, 0, 1, 0) back_btn.clicked.connect(self._handle_go_back) back_btn.setMaximumWidth(45)
class COMPONENTS(QWidget): def __init__(self): super().__init__() self.APP_URL = "http://127.0.0.1:8000" # self.APP_URL = "https://face-recog-server.herokuapp.com" self.msg = QMessageBox() self.grid = QGridLayout() self.group_box = QGroupBox() # PROFILE PICTURE self.profile_pic = QLabel() self.profile_pic.setAlignment(Qt.AlignCenter) self.profile_pic.setMaximumSize(130, 130) self.profile_pic.setScaledContents(True) # PROFILE PICTURE LAYOUT self.pro_pic_view = QVBoxLayout() self.change_pro = QPushButton() self.change_pro.setIcon(QIcon("./assets/icons/capture.png")) self.pro_pic_view.addWidget(self.profile_pic) self.pro_pic_view.addWidget(self.change_pro) self.cam_btn = QPushButton("Capture") # FIRST NAME self.f_name = QLabel("First Name") self.f_name.setObjectName("Label") self.f_name_input = QLineEdit() # MIDDLE NAME self.m_name = QLabel("Middle Name") self.m_name.setObjectName("Label") self.m_name_input = QLineEdit() # LAST NAME self.l_name = QLabel("Last Name") self.l_name.setObjectName("Label") self.l_name_input = QLineEdit() # DATE OF BIRTH self.dob_label = QLabel("Date of Birth") self.dob_label.setObjectName("Label") self.dob_date_label = QLabel("Choose Date..") self.dob_date_label.setStyleSheet("font-weight: normal;") self.dob_date_choose = QPushButton() self.dob_date_choose.setIcon(QIcon("./assets/icons/calendar.png")) self.dob_date_choose.setIconSize(QSize(25, 25)) self.dob_layout = QHBoxLayout() self.dob_date_choose.clicked.connect(self.calender_show) self.dob_layout.addWidget(self.dob_date_label) self.dob_layout.addWidget(self.dob_date_choose) # AGE self.age = QLabel("Age") self.age.setObjectName("Label") self.age_input = QLineEdit() self.age_input.setValidator(QIntValidator()) self.age_input.setMaxLength(3) # GENDER self.gender = QLabel("Gender") self.gender.setObjectName("Label") self.gender_1 = QRadioButton("MALE") self.gender_2 = QRadioButton("FEMALE") self.gender_1.setChecked(True) self.gender_layout = QHBoxLayout() self.gender_layout.addWidget(self.gender_1) self.gender_layout.addWidget(self.gender_2) # NATIONAILTY self.nationality = QLabel("Nationality") self.nationality.setObjectName("Label") self.nationality_input = QLineEdit() # STATE OF ORIGIN self.state_origin = QLabel("State of Origin") self.state_origin.setObjectName("Label") self.state_origin_input = QLineEdit() # LGA OF ORIGIN self.lga_origin = QLabel("LGA") self.lga_origin.setObjectName("Label") self.lga_origin_input = QLineEdit() # MARITAL STATUS self.marital = QLabel("Marital Status") self.marital.setObjectName("Label") self.marital_select = QComboBox() self.marital_select.addItems( ["SINGLE", "SEPERATED", "DIVORCED", "MARRIED", "WIDOWED"]) self.profession = QLabel("Profession") self.profession.setObjectName("Label") self.profession_input = QLineEdit() # JAMB NUMBER self.j_num = QLabel("JAMB No.") self.j_num.setObjectName("Label") self.j_num_input = QLineEdit() self.j_num_input.setMaxLength(10) # COLLEGE self.college = QLabel("College") self.college.setObjectName("Label") self.college_select = QComboBox() self.college_select.addItems([ "CAERSE", "CASAP", "CAFST", "CCSS", "COED", "CEET", "CGSC", "COLMAS", "CNREM", "COLNAS", "COLPAS", "CVM", ]) # DEPARTMENT self.dept = QLabel("Department") self.dept.setObjectName("Label") self.dept_select = QComboBox() self.dept_select.addItems([ "AGRIBUSINESS MANAGEMENT", "AGRICULTURAL ECONOMICS", "AGRICULTURAL EXTENSION AND RURAL SOCIOLOGY", ]) # LEVEL self.level = QLabel("Level") self.level.setObjectName("Label") self.level_select = QComboBox() self.level_select.addItems(["100L", "200L", "300L", "400L"]) # MATRIC NUMBER self.m_num = QLabel("Matriculation No.") self.m_num.setObjectName("Label") self.m_num_input = QLineEdit() # HOME ADDRESS self.address = QLabel("Home Address") self.address.setObjectName("Label") self.address_input = QLineEdit() # CELL PHONE self.phone = QLabel("Cell Phone") self.phone.setObjectName("Label") self.phone_input = QLineEdit() # self.phone_input.setValidator(QIntValidator self.phone_input.setMaxLength(11) # EMAIL self.email = QLabel("Email") self.email.setObjectName("Label") self.email.setObjectName("Label") self.email_input = QLineEdit() # PARENT NAME self.p_name = QLabel("Parent's/Sponsor's Name") self.p_name.setObjectName("Label") self.p_name_input = QLineEdit() # PARENT EMAIL self.p_email = QLabel("Parent's/Sponsor's Email") self.p_email.setObjectName("Label") self.p_email_input = QLineEdit() # PARENT PHONE self.p_phone = QLabel("Parent's/Sponsor's Phone") self.p_phone.setObjectName("Label") self.p_phone_input = QLineEdit() self.p_phone_input.setMaxLength(11) # DATE OF REGISTRATION self.dor = QLabel("Date of Registration") self.dor.setObjectName("Label") self.dor_text = QLineEdit() date = QDate.currentDate().toString(Qt.ISODate) self.dor_text.setText(date) # Next self._next = QPushButton("Next") # Prev self._prev = QPushButton("Previous") def calender_show(self): self.initial_layout = QVBoxLayout() self.calender_view = QWidget() self.calender_view.setWindowTitle("Choose Date") self.calender = QCalendarWidget() self.calender.setGridVisible(True) self.flags = Qt.WindowFlags(Qt.WindowStaysOnTopHint) self.calender_view.setWindowFlags(self.flags) self.initial_layout.addWidget(self.calender) self.calender_view.setLayout(self.initial_layout) self.calender_view.show() self.calender_view.resize(350, 250) self.calender.clicked[QDate].connect(self.select_date) def select_date(self): self.dob_date_label.setText(self.calender.selectedDate().toString( Qt.ISODate)) self.calender_view.hide() def _start_video(self, super_layout): self.video_widget = QWidget() self.video_init_layout = QVBoxLayout() self.back_btn = QCommandLinkButton() self.back_btn.setIcon(QIcon("./assets/icons/back.png")) self.back_btn.setIconSize(QSize(30, 30)) self.back_btn.setMaximumWidth(45) # Create Camera View self.cam_view = QLabel() self.video_init_layout.addWidget(self.back_btn) self.video_init_layout.addWidget(self.cam_view) self.video_init_layout.addWidget(self.cam_btn) self.video_widget.setLayout(self.video_init_layout) super_layout.addWidget(self.video_widget) super_layout.setCurrentWidget(self.video_widget) # create a timer self.timer = QTimer() # set timer timeout callback function self.timer.timeout.connect(self._video) if not self.timer.isActive(): self.cam = cv2.VideoCapture(0) self.timer.start(1) def _video(self): face_cascade = cv2.CascadeClassifier( "./assets/classifier/haarcascade_frontalface_alt2.xml") ret, self.image = self.cam.read() image_copy = self.image.copy() # Capture Image-by-Image gray = cv2.cvtColor(image_copy, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(40, 40), flags=cv2.CASCADE_SCALE_IMAGE, ) for (x, y, w, h) in faces: cv2.rectangle(image_copy, (x, y), (x + w, y + h), (255, 255, 255), 1) self.image_shown = cv2.cvtColor(image_copy, cv2.COLOR_BGR2RGB) # get image infos self.height, self.width, self.channel = self.image_shown.shape self.step = self.channel * self.width # create QImage from image self.qImg = QImage( self.image_shown.data, self.width, self.height, self.step, QImage.Format_RGB888, ) # Set the data from qImg to cam_view self.cam_view.setPixmap(QPixmap.fromImage(self.qImg)) def isConnected(self): try: r = requests.get(url=f"{self.APP_URL}") print(r.text) return True except requests.exceptions.ConnectionError as e: self.msg.setIconPixmap(QPixmap("./assets/icons/no_connection.png")) self.msg.setWindowTitle("Error!") self.msg.setWindowIcon(QIcon("./assets/icons/error.png")) self.msg.setText("Connect to the Internet to use app!") self.msg.show() self.msg.exec_() return False except requests.exceptions.Timeout as e: self.msg.setIconPixmap( QPixmap("./assets/icons/network_timeout.png")) self.msg.setWindowIcon(QIcon("./assets/icons/error.png")) self.msg.setWindowTitle("Information") self.msg.setWindowIcon(QIcon("./assets/icons/error.png")) self.msg.setText("Poor Network Connection!") self.msg.show() self.msg.exec_() return False
def __init__(self, files, tab, delete, parent, test=False): """ Keyword arguments: files -- list with dicts containing file names tab -- instanseof AudioVideoTab, ImageTab or DocumentTab indicating currently active tab delete -- boolean that shows if files must removed after conversion parent -- parent widget files: Each dict have only one key and one corresponding value. Key is a file to be converted and it's value is the name of the new file that will be converted. Example list: [{"/foo/bar.png" : "/foo/bar.bmp"}, {"/f/bar2.png" : "/f/bar2.bmp"}] """ super(Progress, self).__init__(parent) self.parent = parent self.files = files self.num_total_files = len(self.files) self.tab = tab self.delete = delete if not test: self._type = tab.name self.ok = 0 self.error = 0 self.running = True self.nowQL = QLabel(self.tr('In progress: ')) self.nowQPBar = QProgressBar() self.nowQPBar.setValue(0) self.shutdownQCB = QCheckBox(self.tr('Shutdown after conversion')) self.cancelQPB = QPushButton(self.tr('Cancel')) detailsQPB = QCommandLinkButton(self.tr('Details')) detailsQPB.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) detailsQPB.setCheckable(True) detailsQPB.setMaximumWidth(113) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) self.outputQTE = QTextEdit() self.outputQTE.setReadOnly(True) self.frame = QFrame() frame_layout = utils.add_to_layout('h', self.outputQTE) self.frame.setLayout(frame_layout) self.frame.hide() hlayout1 = utils.add_to_layout('h', None, self.nowQL, None) hlayout2 = utils.add_to_layout('h', detailsQPB, line) hlayout3 = utils.add_to_layout('h', self.frame) hlayout4 = utils.add_to_layout('h', None, self.cancelQPB) vlayout = utils.add_to_layout( 'v', hlayout1, self.nowQPBar, hlayout2, hlayout3, self.shutdownQCB, hlayout4 ) self.setLayout(vlayout) detailsQPB.toggled.connect(self.resize_dialog) detailsQPB.toggled.connect(self.frame.setVisible) self.cancelQPB.clicked.connect(self.reject) self.file_converted_signal.connect(self.next_file) self.update_text_edit_signal.connect(self.update_text_edit) self.resize(484, 190) self.setWindowTitle('FF Multi Converter - ' + self.tr('Conversion')) if not test: self.get_data() # should be first and not in QTimer.singleShot() QTimer.singleShot(0, self.manage_conversions)
class SettingsWindow(QMainWindow): """Provides UI to edit the register (member and certificate list) This window also serves as first screen for when there is no register loaded yet, in which case it displays a prompt to create/load a register""" def __init__(self, parent): super(SettingsWindow, self).__init__(parent) self.thread_running_flag = False self.setWindowModality(Qt.WindowModal) # freeze parent window self.registre = self.parentWidget().registre self.school_name = self.parentWidget().school_name self.lay_out() def lay_out(self): self.setWindowTitle(ls.strings.PARAMETERS_BUTTON) self.layout = QVBoxLayout() # ----------- Callback functions ---------- def valider_callback(): p = prenom.text() n = nom.text() if not p or not n: return err = self.registre.ajouter_membre(p, n) if type(err) == str: dialog(err, ls.strings.ERROR) return for _ in range(liste_membres.count()): liste_membres.takeItem(0) for m in self.registre.membres: liste_membres.addItem(m.id) self.update_registre() def retirer_membre_callback(): if liste_membres.currentItem() is None: return identification = liste_membres.currentItem().text() m = self.registre.find_membre_by_id(identification) self.registre.supprimer_membre(m) for _ in range(liste_membres.count()): liste_membres.takeItem(0) for m in self.registre.membres: liste_membres.addItem(m.id) self.update_registre() def cat_list_connect(x, y): if x is not None: for cat in cert_lists: cert_lists[cat].hide() cert_lists[x.text()].show() cert_label.setText(ls.strings.X_CAT_CERTIFICATES(x.text())) else: cat_input.setCurrentIndex(-1) def cat_input_connect(x): l = cat_list.findItems(x, Qt.MatchExactly) if l: cat_list.setCurrentItem(l[0]) for cat in cert_lists: cert_lists[cat].hide() cert_lists[x].show() def valider_cert_callback(): cat = cat_input.currentText() nom = nom_input.text() if not cat or not nom: dialog(ls.strings.PLEASE_ENTER_CERTIFICATE_NAME_AND_CATEGORY) return err = self.registre.ajouter_certificat(nom, cat) if err is not None: dialog(err, ls.strings.ERROR) return if cat not in cert_lists: cert_lists[cat] = ResizableListWidget() b_left_layout.addWidget(cert_lists[cat]) cert_lists[cat].hide() else: for _ in range(cert_lists[cat].count()): cert_lists[cat].takeItem(0) for _ in range(cat_list.count()): cat_list.takeItem(0) cat_input.removeItem(0) for categ in self.registre.categories: cat_list.addItem(categ) cat_input.addItem(categ) if cat in self.registre.categories: for c in self.registre.get_certificats(cat): cert_lists[cat].addItem(c.nom) cat_list.setCurrentItem( cat_list.findItems(cat, Qt.MatchExactly)[0]) cat_input.setCurrentText(cat) cert_lists[cat].show() self.update_registre() def supprimer_certificat(nom, cat): c_row = cert_lists[cat].row(cert_lists[cat].currentItem()) cert_lists[cat].takeItem(c_row) self.registre.supprimer_certificat( self.registre.find_certificat_by_name(nom)) def suppr_cert_callback(): cat = cat_list.currentItem() nom = cert_lists[cat.text()].currentItem() if nom is None or cat is None: return nom = nom.text() cat = cat.text() supprimer_certificat(nom, cat) self.update_registre() def suppr_cat_callback(): if confirm(ls.strings.DELETE_CATEGORY_Q): if cat_list.currentItem() is None: return cat = cat_list.currentItem().text() for nom in [c.nom for c in self.registre.get_certificats(cat)]: supprimer_certificat(nom, cat) cat_row = cat_list.row(cat_list.currentItem()) cat_list.takeItem(cat_row) self.registre.supprimer_categorie(cat) cert_lists[cat].hide() self.update_registre() def avance_callback(): if self.avance.text() == ls.strings.ADVANCED: self.avance.setText(ls.strings.HIDE) self.avance_w.show() else: self.avance.setText(ls.strings.ADVANCED) self.avance_w.hide() def change_school_callback(): self.hide() NewSchoolWindow(self).show() def supprimer_registre_callback(): if cloud_support.supprimer_registre(self.school_name): self.parentWidget().school_name = "" self.school_name = "" self.registre.clear() self.hide_widgets() def change_language_callback(): ls.select_language(ls.strings.code) self.lay_out() self.parentWidget().lay_out() # -------------------------------------------------- # header : create/load/delete online register buttons f = 20 # font size header = QWidget() header_layout = QHBoxLayout() header_layout.setContentsMargins(16, 0, 16, 0) self.school_name_w = QLabel(self.school_name) self.school_name_w.setFont(QFont("unknown", f)) self.school_name_w.setMaximumHeight(60) self.avance = QCommandLinkButton(ls.strings.ADVANCED) self.avance.setMaximumWidth(100) self.avance_w = QWidget() if self.school_name != "": self.avance_w.hide() avance_layout = QHBoxLayout() avance_layout.setContentsMargins(0, 0, 0, 0) self.avance_w.setLayout(avance_layout) self.change_school = QPushButton(ls.strings.CREATE_LOAD_REGISTER) self.supprimer_registre = QPushButton(ls.strings.DELETE_REGISTER) self.supprimer_registre.setMaximumWidth(300) avance_layout.addWidget(self.change_school) avance_layout.addWidget(self.supprimer_registre) header_layout.addWidget(self.school_name_w) header_layout.addWidget(self.avance) header_layout.addWidget(self.avance_w) header.setLayout(header_layout) self.layout.addWidget(header) self.avance.clicked.connect(avance_callback) self.change_school.clicked.connect(change_school_callback) self.supprimer_registre.clicked.connect(supprimer_registre_callback) # top widget : member list management self.gestion_membres = QWidget() self.gestion_membres.setMaximumHeight(300) membres_layout = QHBoxLayout() t_left_w = QWidget() t_right_w = QWidget() t_left_layout = QVBoxLayout() t_right_layout = QVBoxLayout() t_left_w.setLayout(t_left_layout) t_right_w.setLayout(t_right_layout) liste_membres_label = QLabel(ls.strings.MEMBER_LIST) ajouter_membre = QLabel(ls.strings.ADD_MEMBER) prenom = MyLineEdit(placeholder=ls.strings.FIRST_NAME) nom = MyLineEdit(placeholder=ls.strings.LAST_NAME) prenom.setFont(QFont("unknown", 15)) nom.setFont(QFont("unknown", 15)) liste_membres = ResizableListWidget() for m in self.registre.membres: liste_membres.addItem(m.id) valider = ResizableButton(ls.strings.VALIDATE) retirer_membre = ResizableButton(ls.strings.REMOVE_MEMBER) t_left_layout.addWidget(liste_membres_label) t_left_layout.addWidget(liste_membres) t_left_layout.addWidget(retirer_membre) t_right_layout.addWidget(ajouter_membre) t_right_layout.addWidget(prenom) t_right_layout.addWidget(nom) t_right_layout.addWidget(valider) membres_layout.addWidget(t_left_w) membres_layout.addWidget(t_right_w) self.gestion_membres.setLayout(membres_layout) # bottom widget : gestion des certificats self.gestion_certificats = QWidget() certificats_layout = QHBoxLayout() b_left_w = QWidget() b_right_w = QWidget() b_left_layout = QVBoxLayout() b_right_layout = QVBoxLayout() b_left_w.setLayout(b_left_layout) b_right_w.setLayout(b_right_layout) cat_label = QLabel(ls.strings.CATEGORIES) cat_list = ResizableListWidget() cat_list.addItems(self.registre.categories) cert_label = QLabel(ls.strings.CERTIFICATES) ajouter_certificat = QLabel(ls.strings.ADD_CERTIFICATE) cat_input = MyComboBox(placeholder=ls.strings.CATEGORY) cat_input.setFont(QFont("unknown", 15)) cat_input.addItems(self.registre.categories) valider_cert = ResizableButton(ls.strings.VALIDATE) nom_input = MyLineEdit(placeholder=ls.strings.CERTIFICATE_NAME) nom_input.setFont(QFont("unknown", 15)) supprs_w = QWidget() supprs_layout = QHBoxLayout() suppr_cert = ResizableButton(ls.strings.DELETE_CERTIFICATE) suppr_cat = ResizableButton(ls.strings.DELETE_CATEGORY) supprs_w.setLayout(supprs_layout) self.gestion_certificats.setLayout(certificats_layout) b_left_layout.addWidget(cat_label) b_left_layout.addWidget(cat_list) b_left_layout.addWidget(cert_label) cert_lists = {} for cat in self.registre.categories: cert_lists[cat] = ResizableListWidget() for cert in self.registre.get_certificats(cat): cert_lists[cat].addItem(cert.nom) b_left_layout.addWidget(cert_lists[cat]) cert_lists[cat].hide() b_right_layout.addWidget(ajouter_certificat) b_right_layout.addWidget(cat_input) b_right_layout.addWidget(nom_input) b_right_layout.addWidget(valider_cert) supprs_layout.addWidget(suppr_cert) supprs_layout.addWidget(suppr_cat) b_right_layout.addWidget(supprs_w) certificats_layout.addWidget(b_left_w) certificats_layout.addWidget(b_right_w) # footer self.footer = QWidget() footer_layout = QHBoxLayout() change_language = QPushButton(ls.strings.LANGUAGE + ls.strings.name) change_language.setMaximumWidth(change_language.sizeHint().width()) self.thread_progress = QLabel(ls.strings.SAVED) self.thread_progress.setAlignment(Qt.AlignRight) self.thread_progress.setStyleSheet("color:grey") footer_layout.addWidget(change_language) footer_layout.addWidget(self.thread_progress) self.footer.setLayout(footer_layout) self.layout.addWidget(self.gestion_membres) self.layout.addWidget(self.gestion_certificats) self.layout.addWidget(self.footer) main_widget = QWidget() main_widget.setLayout(self.layout) self.setCentralWidget(main_widget) self.hide_widgets() # connecting slots valider.clicked.connect(valider_callback) retirer_membre.clicked.connect(retirer_membre_callback) cat_list.currentItemChanged.connect(cat_list_connect) cat_input.currentTextChanged.connect(cat_input_connect) valider_cert.clicked.connect(valider_cert_callback) suppr_cert.clicked.connect(suppr_cert_callback) suppr_cat.clicked.connect(suppr_cat_callback) change_language.clicked.connect(change_language_callback) cat_list.setCurrentRow(0, QItemSelectionModel.Select) def update_registre(self): self.parentWidget().registre_updated_flag = True self.registre.enregistrer() self.upload_in_thread() def hide_widgets(self): if self.school_name: self.school_name_w.setText(self.school_name) self.gestion_membres.show() self.gestion_certificats.show() self.supprimer_registre.show() self.avance.show() self.thread_progress.show() self.resize(710, 600) else: self.school_name_w.setText(ls.strings.CLICK_HERE_TO_BEGIN) self.gestion_membres.hide() self.gestion_certificats.hide() self.change_school.show() self.supprimer_registre.hide() self.avance.hide() self.thread_progress.hide() self.resize(710, 60) def closeEvent(self, event): self.parentWidget().update_comboboxes() self.parentWidget().setWindowOpacity(1.) super(SettingsWindow, self).closeEvent(event) def close_avance(self): self.avance.setText(ls.strings.ADVANCED) self.avance_w.hide() def upload_in_thread(self): if self.thread_running_flag: return else: self.thread_running_flag = True self.thread = QThread() self.uploader = multithreading.Uploader() self.uploader.moveToThread(self.thread) self.thread.started.connect(self.uploader.run) self.uploader.finished.connect(self.thread.quit) self.uploader.finished.connect(self.uploader.deleteLater) self.thread.finished.connect(self.thread.deleteLater) def finished(): self.thread_progress.setText(ls.strings.SAVED) self.thread_running_flag = False def started(): self.thread_progress.setText(ls.strings.SAVING) self.uploader.finished.connect(finished) self.uploader.started.connect(started) self.thread.start()