19 from roslib.packages
import get_pkg_dir
23 from python_qt_binding
import loadUi
25 from accounts
import User, \
28 GUserAccountCommunicate, \
32 from airbus_cobot_gui
import airbus_cobot_gui_dir
46 def __init__(self, parent = None, closable = True):
47 """! The constructor."""
49 QDialog.__init__(self, parent, Qt.FramelessWindowHint)
56 self.setStyleSheet(
"QDialog{ \
57 background-color:qlineargradient(x1: 0, \
69 self.password_edit.setEchoMode(QLineEdit.Password);
71 self.connect(self.login_button, SIGNAL(
"clicked()"),
75 self.connect(self.exit_button, SIGNAL(
"clicked()"), self.close)
76 self.exit_button.setVisible(
True)
78 self.exit_button.setVisible(
False)
83 """! Check user account validity and connect user."""
85 accounts = UserAccounts()
87 user_info = accounts.find(self.user_id_edit.text())
90 msg_box = MessageBox()
91 msg_box.setText(
trUtf8(
"Invalid user id",
'!'))
92 msg_box.setIcon(QMessageBox.Critical)
93 msg_box.setStandardButtons(QMessageBox.Ok)
94 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
96 elif user_info.password == base64.b64encode(self.password_edit.text()):
97 GUserAccountCommunicate.update(user_info)
100 msg_box = MessageBox()
101 msg_box.setText(
trUtf8(
"Invalid password",
'!'))
102 msg_box.setIcon(QMessageBox.Critical)
103 msg_box.setStandardButtons(QMessageBox.Ok)
104 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
108 self.user_id_label.setText(
trUtf8(
'User id'))
109 self.password_label.setText(
trUtf8(
'Password'))
116 """! The constructor."""
118 QWidget.__init__(self)
123 loadUi(ui_file, self)
125 self.password_edit.setEchoMode(QLineEdit.Password)
126 self.confirm_password_edit.setEchoMode(QLineEdit.Password);
128 self.connect(self.add_user_button, SIGNAL(
"clicked()"),
134 """! Check fields and add user account."""
136 accounts = UserAccounts()
138 user = User(self.user_id_edit.text())
140 password = self.password_edit.text()
141 confirm = self.confirm_password_edit.text()
143 if user.userid ==
"" or \
146 msg_box = MessageBox()
147 msg_box.setText(
trUtf8(
"Some fields are not filled",
'!'))
148 msg_box.setIcon(QMessageBox.Critical)
149 msg_box.setStandardButtons(QMessageBox.Ok)
150 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
154 if confirm != password:
155 msg_box = MessageBox()
156 msg_box.setText(
trUtf8(
'The passwords are different',
'!'))
157 msg_box.setIcon(QMessageBox.Critical)
158 msg_box.setStandardButtons(QMessageBox.Ok)
159 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
163 user.set_password(password)
165 user.privilege = Privilege.TOLEVEL[self.access_rights_combo.currentText().lower()]
169 except Exception
as e:
170 msg_box = MessageBox()
171 msg_box.setText(str(e))
172 msg_box.setIcon(QMessageBox.Critical)
173 msg_box.setStandardButtons(QMessageBox.Ok)
174 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
178 msg_box = MessageBox()
179 msg_box.setText(
trUtf8(
'The user was added successfully',
'.'))
180 msg_box.setIcon(QMessageBox.Information)
181 msg_box.setStandardButtons(QMessageBox.Ok)
182 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
185 self.user_id_edit.setText(
"")
186 self.password_edit.setText(
"")
187 self.confirm_password_edit.setText(
"")
188 self.access_rights_combo.setCurrentIndex(0)
192 self.user_id_label.setText(
trUtf8(
'User id'))
193 self.password_label.setText(
trUtf8(
'Password'))
194 self.cinfirm_password_label.setText(
trUtf8(
'Confirm password'))
195 self.access_rights_label.setText(
trUtf8(
'Access rights'))
196 self.add_user_button.setText(
trUtf8(
'Ok'))
204 """! The constructor."""
206 QWidget.__init__(self)
211 loadUi(ui_file, self)
213 self.new_password_edit.setEchoMode(QLineEdit.Password)
214 self.confirm_new_password_edit.setEchoMode(QLineEdit.Password)
220 self.users_list_combo.addItems(self._accounts.user_list())
223 self.connect(self.modif_user_account_button, SIGNAL(
"clicked()"),
226 self.connect(self.check_password_button, SIGNAL(
"clicked()"),
238 text = self.current_password_edit.text()
240 if text == self.user_selected.get_password(
True):
242 self.current_password_edit.setStyleSheet(
"""background-color: #ffffff;
246 color: rgb(0,255,0);""")
247 privilege = self.user_selected.privilege
248 self.access_rights_combo.setCurrentIndex(privilege+1)
249 self.new_password_edit.setText(self.user_selected.get_password(
True))
250 self.confirm_new_password_edit.setText(self.user_selected.get_password(
True))
252 self.new_password_edit.setEnabled(
True)
253 self.confirm_new_password_edit.setEnabled(
True)
254 self.access_rights_combo.setEnabled(
True)
255 self.modif_user_account_button.setEnabled(
True)
261 self.current_password_edit.setStyleSheet(
"""background-color: #ffffff;
265 color: rgb(255,0,0);""")
269 """! Update user information with user selected.
270 @param index: user list index.
276 self.current_password_edit.setEnabled(
False)
278 self.
user_selected = self._accounts.find(self.users_list_combo.itemText(index))
279 self.current_password_edit.setEnabled(
True)
282 """! Check fields and modify user account."""
284 user_modified = User(self.user_selected.userid)
286 if self.access_rights_combo.currentIndex() == 0:
288 msg_box = MessageBox()
289 msg_box.setText(
trUtf8(
'Select access rights',
'!'))
290 msg_box.setIcon(QMessageBox.Critical)
291 msg_box.setStandardButtons(QMessageBox.Ok)
292 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
295 elif self.new_password_edit.text() != \
296 self.confirm_new_password_edit.text():
298 msg_box = MessageBox()
299 msg_box.setText(
trUtf8(
'The passwords are different',
'!'))
300 msg_box.setIcon(QMessageBox.Critical)
301 msg_box.setStandardButtons(QMessageBox.Ok)
302 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
306 user_modified.privilege = Privilege.TOLEVEL[self.access_rights_combo.currentText().lower()]
307 user_modified.set_password(self.new_password_edit.text())
312 except Exception
as e:
314 msg_box = MessageBox()
315 msg_box.setText(str(e))
316 msg_box.setIcon(QMessageBox.Critical)
317 msg_box.setStandardButtons(QMessageBox.Ok)
318 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
322 msg_box = MessageBox()
323 msg_box.setText(
trUtf8(
'The user was modified successfully',
'.'))
324 msg_box.setIcon(QMessageBox.Information)
325 msg_box.setStandardButtons(QMessageBox.Ok)
326 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
329 self.users_list_combo.setCurrentIndex(0)
334 self.access_rights_combo.setCurrentIndex(0)
335 self.new_password_edit.setText(
'')
336 self.confirm_new_password_edit.setText(
'')
337 self.new_password_edit.setEnabled(
False)
338 self.confirm_new_password_edit.setEnabled(
False)
339 self.access_rights_combo.setEnabled(
False)
340 self.modif_user_account_button.setEnabled(
False)
343 self.current_password_edit.setText(
'')
345 self.current_password_edit.setStyleSheet(
"""background-color: #ffffff;
351 self.select_user_label.setText(
trUtf8(
'Select user'))
352 self.current_password_label.setText(
trUtf8(
'Current password'))
353 self.check_password_button.setText(
trUtf8(
'Ok'))
354 self.access_rights_label.setText(
trUtf8(
'Access rights'))
355 self.new_password_label.setText(
trUtf8(
'New password'))
356 self.confirm_password_label.setText(
trUtf8(
'Confirm password'))
357 self.modif_user_account_button.setText(
trUtf8(
'Ok'))
364 """! The constructor."""
366 QWidget.__init__(self)
371 loadUi(ui_file, self)
373 self.connect(self.remove_button, SIGNAL(
"clicked()"),
378 self.users_list_combo.addItems(self._accounts.user_list())
383 """! Remove user account slected in user list."""
385 if self.users_list_combo.currentIndex() == 0:
386 msg_box = MessageBox()
387 msg_box.setText(
trUtf8(
'Select user',
'!'))
388 msg_box.setIcon(QMessageBox.Critical)
389 msg_box.setStandardButtons(QMessageBox.Ok)
390 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
394 user_id = self.users_list_combo.currentText()
396 self._accounts.remove(User(user_id))
397 self.users_list_combo.removeItem(self.users_list_combo.currentIndex())
398 except Exception
as e:
399 msg_box = MessageBox()
400 msg_box.setText(str(e))
401 msg_box.setIcon(QMessageBox.Critical)
402 msg_box.setStandardButtons(QMessageBox.Ok)
403 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
407 self.users_list_combo.setCurrentIndex(0)
408 msg_box = MessageBox()
409 msg_box.setText(
trUtf8(
'The user was removed successfully',
'.'))
410 msg_box.setIcon(QMessageBox.Information)
411 msg_box.setStandardButtons(QMessageBox.Ok)
412 msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
416 self.user_list_label.setText(
trUtf8(
'User list'))
417 self.remove_button.setText(
trUtf8(
'Ok'))
424 """! The constructor."""
426 QDialog.__init__(self, parent, Qt.FramelessWindowHint)
431 loadUi(ui_file, self)
435 self.connect(self.exit_button, SIGNAL(
"clicked()"), self.close)
442 self.add_button.click()
445 """! Open add user account ui."""
446 self.header_label.setText(
trUtf8(
'Add user account'))
448 self.viewer_area.takeWidget()
450 add_account_ui.resize(self.viewer_area.width()-2,
451 self.viewer_area.height()-2)
452 self.viewer_area.setWidget(add_account_ui)
455 """! Open modif user account ui."""
456 self.header_label.setText(
trUtf8(
'Modif user account'))
458 self.viewer_area.takeWidget()
460 modif_account_ui.resize(self.viewer_area.width()-2,
461 self.viewer_area.height()-2)
462 self.viewer_area.setWidget(modif_account_ui)
465 """! Open remove user account ui."""
466 self.header_label.setText(
trUtf8(
'Remove user account'))
468 self.viewer_area.takeWidget()
470 remove_account.resize(self.viewer_area.width()-2,
471 self.viewer_area.height()-2)
472 self.viewer_area.setWidget(remove_account)
475 self.settings_label.setText(
trUtf8(
'Settings'))
476 self.header_label.setText(
trUtf8(
'Account manager'))
477 self.add_button.setText(
trUtf8(
'Add'))
478 self.modif_button.setText(
trUtf8(
'Modif'))
479 self.remove_button.setText(
trUtf8(
'Remove'))
480 self.exit_button.setText(
trUtf8(
'Exit'))
487 """! The constructor."""
489 QPopup.__init__(self, parent)
496 ui_file = os.path.join(self.
resources_dir,
'ui',
'account_popup.ui')
498 loadUi(ui_file, self)
501 'icons',
'ico_user.png'))
502 self.user_icon_label.setPixmap(user_icon)
504 self.connect(self.connection_button, SIGNAL(
"clicked()"),
506 self.connect(self.accounts_manager_button, SIGNAL(
"clicked()"),
508 self.connect(self.deconnection_button, SIGNAL(
"clicked()"),
510 self.deconnection_button.setEnabled(
True)
512 user_info = GUserAccountCommunicate.get_current_user_account()
514 if user_info.privilege < Privilege.EXPERT:
515 self.accounts_manager_button.setEnabled(
False)
517 self.accounts_manager_button.setEnabled(
True)
519 self.user_id_label.setText(user_info.userid)
521 privilege = Privilege.TOSTR[user_info.privilege]
522 self.access_rights_label.setText(privilege[0].upper()+privilege[1:])
523 self.language_label.setText(trUtf8.language)
524 self.time_label.setText(
'2h:38m')
529 """! Refresh connection time."""
530 self.time_label.setText(self._user.connection_time())
533 """! Open login ui."""
538 """! Open account manager ui."""
543 """! Disconnect current user."""
544 GUserAccountCommunicate.update(User())
550 self.header_label.setText(
trUtf8(
'User account'))
551 self.user_id_header_label.setText(
trUtf8(
'User'))
552 self.access_rights_header_label.setText(
trUtf8(
'Rights'))
553 self.language_header_label.setText(
trUtf8(
'Language'))
554 self.time_header_label.setText(
trUtf8(
'Time'))
555 self.connection_button.setText(
trUtf8(
'Connection'))
556 self.deconnection_button.setText(
trUtf8(
'Disconnection'))
557 self.accounts_manager_button.setText(
trUtf8(
'Account manager'))
564 """! The constructor."""
566 QWidget.__init__(self)
568 self.setMinimumSize(QSize(50, 10))
569 self.setMaximumSize(QSize(600, 30))
574 self._central_layout.setContentsMargins(0, 0, 0, 0)
575 self._central_layout.setSpacing(5)
580 self._user_icon_label.setStyleSheet(
'background-color: transparent;')
581 self._user_icon_label.setMinimumSize(QSize(25,10))
582 self._user_icon_label.setMaximumSize(QSize(30,30))
587 self._user_id_label.setStyleSheet(
'background-color: transparent;')
594 self.connect(GUserAccountCommunicate,
595 SIGNAL(
'userAccountChanged'),
599 """! Update user information.
600 @param user_info: user connected information.
601 @type user_info: UserInfo.
603 self._user_id_label.setText(user.userid)
606 """! Redefine qt methode for resize widget.
607 @param event: qt event.
611 self.setStyleSheet(
"QLabel {font-size: %ipt;}"%(int(self.height()/2)))
612 self.resize(self.width(),self.height())
614 ico_user = QPixmap(os.path.join(get_pkg_dir(
'airbus_cobot_gui'),
619 ico_user = ico_user.scaled(self._user_icon_label.width(),
620 self._user_icon_label.height(),
622 Qt.SmoothTransformation)
623 self._user_icon_label.setPixmap(ico_user)
626 """! Redefine qt methode for resize widget.
627 @param event: qt event.
637 if __name__ ==
"__main__":
639 rospy.init_node(
'unittest_account_ui')
645 QWidget.__init__(self)
651 a = QApplication(sys.argv)
653 translator = QTranslator()
655 translator.load(os.path.join(trans_dir,
'fr.qm'))
656 qApp.installTranslator(translator)
658 utt_appli = QMainWindow()
661 user.userid =
'AirbusGroup'
662 user.privilege = Privilege.EXPERT
666 GUserAccountCommunicate.update(user)
668 utt_appli.setCentralWidget(account_ui)
def load_remove_user_ui
Open remove user account ui.
def account_validation
Check user account validity and connect user.
tuple airbus_cobot_gui_dir
def __init__
The constructor.
def load_modif_user_ui
Open modif user account ui.
def __init__
The constructor.
def load_add_user_ui
Open add user account ui.
User accounts manager ui.