admin_event.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import time
  2. from tool.type_ import *
  3. from sql.db import DB
  4. from sql.user import find_user_by_name
  5. from event import TkEventBase, TkThreading, TkEventException
  6. import admin
  7. class AdminEventBase(TkEventBase):
  8. def __init__(self, station):
  9. super(AdminEventBase, self).__init__()
  10. self.station: admin.AdminStationBase = station
  11. self._db: DB = station.get_db()
  12. def get_title(self) -> str:
  13. return "AdminEvent"
  14. class LoginEvent(AdminEventBase):
  15. def __init__(self, station):
  16. super().__init__(station)
  17. self.thread: Optional[TkThreading] = None
  18. def login(self, name, passwd):
  19. return find_user_by_name(name, passwd, self._db)
  20. def start(self, name, passwd):
  21. self.thread = TkThreading(self.login, name, passwd)
  22. return self
  23. def is_end(self) -> bool:
  24. return not self.thread.is_alive()
  25. def done_after_event(self):
  26. self.station.login(self.thread.wait_event())
  27. class TestProgressEvent(AdminEventBase):
  28. @staticmethod
  29. def func(sleep_time):
  30. time.sleep(sleep_time)
  31. def __init__(self, station):
  32. super(TestProgressEvent, self).__init__(station)
  33. self.thread = TkThreading(self.func, 5)
  34. def is_end(self) -> bool:
  35. return not self.thread.is_alive()