def create_user(self): firstname = unicode(self.firstname.text().toUtf8(), encoding="UTF-8") lastname = unicode(self.lastname.text().toUtf8(), encoding="UTF-8") rfid = unicode(self.rfid_card.text().toUtf8(), encoding="UTF-8") admin = self.admin_checkbox.isChecked() try: if self.user.get_by_rfid(rfid)[ 'warnings'] and self.key.get_by_rfid(rfid)['warnings']: if self.first_user: admin = True new_user = self.user.create(firstname, lastname, rfid, admin) if new_user['errors'] or new_user['warnings']: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) else: self.info = InfoWindow(label_text=u'Користувача додано!', parent=self) self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) QtCore.QTimer.singleShot(5000, self.close) else: self.info = InfoWindow( label_text=u'Такий RFID ключ вже зареєстрований у системі') self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) except: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close)
class DeleteKeysWindow(QtGui.QMainWindow, delete_keys_design.Ui_DeleteKeys): def __init__(self, keys): super(self.__class__, self).__init__() self.setupUi(self) self.exit_to_main.clicked.connect(self.exit) if keys: buttons = {} row_count = 0 for key in keys: buttons[key.id] = QtGui.QPushButton( self.scrollAreaWidgetContents) buttons[key.id].setFixedSize(150, 100) if key.status is True: buttons[key.id].setStyleSheet( 'QPushButton {background-color: #669900;' 'color: #ffffff;' 'font: 75 40pt DejaVu Sans Mono for Powerline;}') else: buttons[key.id].setStyleSheet( 'QPushButton {background-color: #cc3300;' 'color: #ffffff;' 'font: 75 40pt DejaVu Sans Mono for Powerline;}') buttons[key.id].setText( _translate("GetKeyWindow", str(key.room.encode('utf-8')), None)) buttons[key.id].setObjectName(key.rfid_chip) buttons[key.id].clicked.connect(self.button_clicked) self.gridLayout_2.addWidget(buttons[key.id], int(row_count % 3), int(row_count / 3)) row_count += 1 def button_clicked(self): sender = self.sender() key = Key.get_by_rfid(str(sender.objectName())) if key['data']: self.choice = ChoiceWindow( operation='delete_key', label_text=u'Видалити ключ від кімнати {} ?'.format( key['data'].room), key=key['data'].rfid_chip, parent=self) self.choice.show() QtCore.QTimer.singleShot(10000, self.choice.close) elif key['warnings']: self.info = InfoWindow( label_text=u'У системі незнадено такого ключа') self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) else: self.info = InfoWindow( label_text= u'Вибачте, сталася помилка,зверніться будь ласка до адміністратора' ) self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) def exit(self): self.close()
def __init__(self): super(self.__class__, self).__init__() self.setupUi(self) self.get_key.clicked.connect(self.get_the_keys) self.info_error = InfoWindow( label_text= u'Вибачте, сталася помилка, зверніться будь ласка до адміністратора' )
def delete_keys(self): keys = Key.get_all() if keys['data']: self.delete_keys_window = DeleteKeysWindow(keys['data']) self.delete_keys_window.show() elif keys['warnings']: self.info = InfoWindow( label_text=u"Немає ключів які можна видалити") self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) else: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close)
def delete_users(self): users = User.get_all() if users['data']: self.delete_users_window = DeleteUsersWindow(users['data']) self.delete_users_window.show() elif users['warnings']: self.info = InfoWindow( label_text=u"Немає користувачів яких можна видалити") self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) else: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close)
def __init__(self): super(self.__class__, self).__init__() self.setupUi(self) self.new_user_window = AddNewUser() self.new_room_window = AddNewRoom() self.new_user.clicked.connect(self.add_user) self.new_key.clicked.connect(self.add_key) self.remove_user.clicked.connect(self.delete_users) self.remove_key.clicked.connect(self.delete_keys) self.exit_to_main.clicked.connect(self.exit) self.info_error = InfoWindow( label_text= u'Вибачте, сталася помилка, зверніться будь ласка до адміністратора' )
class AddNewUser(QtGui.QMainWindow, new_user_design.Ui_AddUserWindow): def __init__(self, first_user=None): super(self.__class__, self).__init__() self.setupUi(self) self.first_user = first_user self.add_rfid_card.clicked.connect(self.connect_rfid_card) self.add_new_user.clicked.connect(self.create_user) self.exit_to_main.clicked.connect(self.exit) self.user = User self.key = Key self.info_error = InfoWindow( label_text= u'Вибачте, сталася помилка, зверніться будь ласка до адміністратора' ) def connect_rfid_card(self): pass def create_user(self): firstname = unicode(self.firstname.text().toUtf8(), encoding="UTF-8") lastname = unicode(self.lastname.text().toUtf8(), encoding="UTF-8") rfid = unicode(self.rfid_card.text().toUtf8(), encoding="UTF-8") admin = self.admin_checkbox.isChecked() try: if self.user.get_by_rfid(rfid)[ 'warnings'] and self.key.get_by_rfid(rfid)['warnings']: if self.first_user: admin = True new_user = self.user.create(firstname, lastname, rfid, admin) if new_user['errors'] or new_user['warnings']: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) else: self.info = InfoWindow(label_text=u'Користувача додано!', parent=self) self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) QtCore.QTimer.singleShot(5000, self.close) else: self.info = InfoWindow( label_text=u'Такий RFID ключ вже зареєстрований у системі') self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) except: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) def exit(self): self.firstname.clear() self.lastname.clear() self.rfid_card.clear() self.close()
class AdminForm(QtGui.QMainWindow, admin_form_design.Ui_AdminFormMain): def __init__(self): super(self.__class__, self).__init__() self.setupUi(self) self.new_user_window = AddNewUser() self.new_room_window = AddNewRoom() self.new_user.clicked.connect(self.add_user) self.new_key.clicked.connect(self.add_key) self.remove_user.clicked.connect(self.delete_users) self.remove_key.clicked.connect(self.delete_keys) self.exit_to_main.clicked.connect(self.exit) self.info_error = InfoWindow( label_text= u'Вибачте, сталася помилка, зверніться будь ласка до адміністратора' ) def add_user(self): self.new_user_window.show() def add_key(self): self.new_room_window.show() def delete_users(self): users = User.get_all() if users['data']: self.delete_users_window = DeleteUsersWindow(users['data']) self.delete_users_window.show() elif users['warnings']: self.info = InfoWindow( label_text=u"Немає користувачів яких можна видалити") self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) else: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) def delete_keys(self): keys = Key.get_all() if keys['data']: self.delete_keys_window = DeleteKeysWindow(keys['data']) self.delete_keys_window.show() elif keys['warnings']: self.info = InfoWindow( label_text=u"Немає ключів які можна видалити") self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) else: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) def exit(self): self.close()
def get_the_keys(self): if User.get_all()['warnings']: self.info = InfoWindow( label_text= u"Перший запуск програми, будь ласка створіть користувача!") self.info.show() self.new_user = AddNewUser() QtCore.QTimer.singleShot(3000, self.info.close) QtCore.QTimer.singleShot(3000, self.new_user.show) else: # TODO: Open window with user auth user = User.get_by_rfid("12334")['data'] #self.authenticate_user() username = user.firstname + u' ' + user.lastname self.welcome_window(username) keys = Key.get_all() if keys['errors']: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) elif keys['warnings']: self.get_key_window(keys=None, user=None) else: self.get_key_window(keys['data'], user=user)
def button_clicked(self): sender = self.sender() key = Key.get_by_rfid(str(sender.objectName())) if key['data']: self.choice = ChoiceWindow( operation='delete_key', label_text=u'Видалити ключ від кімнати {} ?'.format( key['data'].room), key=key['data'].rfid_chip, parent=self) self.choice.show() QtCore.QTimer.singleShot(10000, self.choice.close) elif key['warnings']: self.info = InfoWindow( label_text=u'У системі незнадено такого ключа') self.info.show() QtCore.QTimer.singleShot(5000, self.info.close) else: self.info = InfoWindow( label_text= u'Вибачте, сталася помилка,зверніться будь ласка до адміністратора' ) self.info.show() QtCore.QTimer.singleShot(5000, self.info.close)
class MainFirstWindow(QtGui.QMainWindow, main_design.Ui_FirstWindow): def __init__(self): super(self.__class__, self).__init__() self.setupUi(self) self.get_key.clicked.connect(self.get_the_keys) self.info_error = InfoWindow( label_text= u'Вибачте, сталася помилка, зверніться будь ласка до адміністратора' ) def authenticate_user(self): self.read_card_window = ReadCardWindow() self.read_card_window.show() QtCore.QTimer.singleShot(10000, self.read_card_window.close) # TODO: open scanning window for 30 sec # TODO: run scanning script # TODO: close after 30 second \ return bad answer \ get rights def welcome_window(self, label_text): self.welcome = WelcomeWindow(label_text) self.welcome.show() QtCore.QTimer.singleShot(2000, self.welcome.close) def get_key_window(self, keys, user): self.get_keys_window = GetKeyWindow(keys, user) QtCore.QTimer.singleShot( 2000, self.get_keys_window.show ) # time when welcome window close and this window open # Time to close get_key_window #QtCore.QTimer.singleShot(60000, self.get_keys_window.close) def get_the_keys(self): if User.get_all()['warnings']: self.info = InfoWindow( label_text= u"Перший запуск програми, будь ласка створіть користувача!") self.info.show() self.new_user = AddNewUser() QtCore.QTimer.singleShot(3000, self.info.close) QtCore.QTimer.singleShot(3000, self.new_user.show) else: # TODO: Open window with user auth user = User.get_by_rfid("12334")['data'] #self.authenticate_user() username = user.firstname + u' ' + user.lastname self.welcome_window(username) keys = Key.get_all() if keys['errors']: self.info_error.show() QtCore.QTimer.singleShot(5000, self.info_error.close) elif keys['warnings']: self.get_key_window(keys=None, user=None) else: self.get_key_window(keys['data'], user=user) # TODO: Need return error window def put_the_keys(self): # TODO: Add a window for put keys return