bms_login_ctl.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from sys import argv
  4. from utils.globalvar import SD
  5. from widget.bms_login import Win_Login
  6. from controller.bms_home_ctl import BmsHomeControll
  7. from utils.qt import QApplication
  8. class BmsLoginControll:
  9. def __init__(self):
  10. # 不需要从命令行输入参数
  11. self._app = QApplication(argv)
  12. self._view = Win_Login()
  13. self.init()
  14. def init(self):
  15. self._view.login_signal.connect(self._verify_user)
  16. self._view.cancel_signal.connect(self._login_cancel)
  17. self._view.home_show_signal.connect(self._show_main)
  18. self._view.language_signal.connect(self._change_language)
  19. def _verify_user(self):
  20. password = self._view.edt_password.text().strip()
  21. if self._view.cb_role.currentIndex() == 0:
  22. self._view.on_success()
  23. elif self._view.cb_role.currentIndex() == 1:
  24. if password == "embmstest":
  25. self._view.on_success()
  26. else:
  27. self._view.on_error()
  28. elif self._view.cb_role.currentIndex() == 2:
  29. if password == "embms":
  30. self._view.on_success()
  31. else:
  32. self._view.on_error()
  33. elif self._view.cb_role.currentIndex() == 3:
  34. if password == "embmspack":
  35. self._view.on_success()
  36. else:
  37. self._view.on_error()
  38. elif self._view.cb_role.currentIndex() == 4:
  39. if password == "embmsAdministrator":
  40. self._view.on_success()
  41. else:
  42. self._view.on_error()
  43. def _show_main(self):
  44. self.home = BmsHomeControll()
  45. self.home.run()
  46. def _login_cancel(self):
  47. self._view.close()
  48. def _change_language(self, index):
  49. SD.SYSTEM_LANGUAGE = index
  50. self._view.setWindowTitle("用户登录" if SD.SYSTEM_LANGUAGE == 0 else "Login")
  51. self._view.lb_role.setText("登录角色" if SD.SYSTEM_LANGUAGE == 0 else "Role")
  52. self._view.lb_password.setText("登录密码" if SD.SYSTEM_LANGUAGE == 0 else "PassWord")
  53. self._view.lb_prj.setText("登录项目" if SD.SYSTEM_LANGUAGE == 0 else "Project")
  54. self._view.lb_con_type.setText("通讯类型" if SD.SYSTEM_LANGUAGE == 0 else "Conn Type")
  55. self._view.lb_channel.setText("索引号" if SD.SYSTEM_LANGUAGE == 0 else "Index")
  56. self._view.lb_index.setText("通道号" if SD.SYSTEM_LANGUAGE == 0 else "Channel")
  57. self._view.lb_baudrate.setText("波特率" if SD.SYSTEM_LANGUAGE == 0 else "BPS")
  58. self._view.edt_password.setPlaceholderText("密码" if SD.SYSTEM_LANGUAGE == 0 else "PassWord")
  59. self._view.btn_login.setText("登录" if SD.SYSTEM_LANGUAGE == 0 else "Login")
  60. self._view.btn_cancel.setText("取消" if SD.SYSTEM_LANGUAGE == 0 else "Cancel")
  61. self._view.cb_role.setItemText(0, "普通用户" if SD.SYSTEM_LANGUAGE == 0 else "Normal")
  62. self._view.cb_role.setItemText(1, "调试工程师" if SD.SYSTEM_LANGUAGE == 0 else "Test")
  63. self._view.cb_role.setItemText(2, "BMS产线操作员" if SD.SYSTEM_LANGUAGE == 0 else "Em")
  64. self._view.cb_role.setItemText(3, "PACK产线操作" if SD.SYSTEM_LANGUAGE == 0 else "Pack")
  65. self._view.cb_role.setItemText(4, "系统管理员" if SD.SYSTEM_LANGUAGE == 0 else "Manager")
  66. self._view.cb_prj.setItemText(0, "户储" if SD.SYSTEM_LANGUAGE == 0 else "Home")
  67. self._view.cb_prj.setItemText(1, "工商业" if SD.SYSTEM_LANGUAGE == 0 else "Industry")
  68. def run(self):
  69. self._view.show()
  70. return self._app.exec_()