Skip to content

Commit

Permalink
#113 修复关闭游戏
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Dec 24, 2023
1 parent 9fdaa9a commit 380f184
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, page: ft.Page, ctx: Context):
page.padding = 0

theme: ThemeColors = gui_config.theme()
self.display_view: SrBasicView = one_stop_view.get(ctx)
self.display_view: SrBasicView = one_stop_view.get(page, ctx)
self.display_part = ft.Container(content=self.display_view, padding=10)

self.app_rail = ft.NavigationRail(
Expand Down Expand Up @@ -185,7 +185,7 @@ def _get_secondary_rail(self):

def _get_view_component(self) -> Optional[SrBasicView]:
if self.app_rail.selected_index == 0:
return one_stop_view.get(self.ctx)
return one_stop_view.get(self.page, self.ctx)
elif self.app_rail.selected_index == 1:
if self.world_patrol_rail.selected_index == 0:
return world_patrol_run_view.get(self.page, self.ctx)
Expand Down
37 changes: 18 additions & 19 deletions src/gui/one_stop_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ def set_disabled(self, disabled: bool):

class OneStopView(ft.Row, SrBasicView):

def __init__(self, ctx: Context):
self.ctx: Context = ctx
theme: ThemeColors = gui_config.theme()
def __init__(self, page: ft.Page, ctx: Context):
SrBasicView.__init__(self, page, ctx)

self.update_time = Label2NormalValueRow('数据更新时间', '2023-11-09 00:00:00', width=info_text_width*2)
self.power = Label2NormalValueRow('开拓力', '200/240')
Expand Down Expand Up @@ -271,7 +270,7 @@ def handle_after_show(self):
self._update_app_list_status()
self._update_character_status()
scheduler.every_second(self._update_app_list_status, tag='_update_app_list_status')
self.ctx.register_status_changed_handler(self,
self.sr_ctx.register_status_changed_handler(self,
self._after_start,
self._after_pause,
self._after_resume,
Expand All @@ -281,14 +280,14 @@ def handle_after_show(self):
def handle_after_hide(self):
scheduler.cancel_with_tag('_update_app_list_status')
scheduler.cancel_with_tag('_update_running_app_name')
self.ctx.unregister(self)
self.sr_ctx.unregister(self)

def _check_ctx_stop(self) -> bool:
"""
检查是否在停止状态
:return: 是否在停止状态
"""
if not self.ctx.is_stop:
if not self.sr_ctx.is_stop:
msg: str = '其它任务正在执行 请先完成或停止'
snack_bar.show_message(msg, self.page)
log.info(msg)
Expand All @@ -301,7 +300,7 @@ def run_app(self, app_id: str):

run_record = one_stop_service.get_app_run_record_by_id(app_id)
run_record.check_and_update_status()
self.running_app = one_stop_service.get_app_by_id(app_id, self.ctx)
self.running_app = one_stop_service.get_app_by_id(app_id, self.sr_ctx)
if self.running_app is None:
log.error('非法的任务入参')
self.running_app = None
Expand All @@ -315,32 +314,32 @@ def on_click_start(self, e):
return
self.start_btn.disabled = True
self.update()
self.running_app = OneStopService(self.ctx)
self.running_app = OneStopService(self.sr_ctx)

t = threading.Thread(target=self.running_app.execute)
t.start()

def on_click_pause(self, e):
self.ctx.switch()
self.sr_ctx.switch()

def on_click_resume(self, e):
self.ctx.switch()
self.sr_ctx.switch()

def on_click_stop(self, e):
self.ctx.stop_running()
self.sr_ctx.stop_running()

def _update_status_component(self):
"""
更新显示状态相关的组件
:return:
"""
self.start_btn.visible = self.ctx.is_stop
self.start_btn.visible = self.sr_ctx.is_stop
self.start_btn.disabled = False
self.pause_btn.visible = self.ctx.is_running
self.resume_btn.visible = self.ctx.is_pause
self.stop_btn.disabled = self.ctx.is_stop
self.running_ring.visible = self.ctx.is_running
self.running_status.update_label(self.ctx.status_text)
self.pause_btn.visible = self.sr_ctx.is_running
self.resume_btn.visible = self.sr_ctx.is_pause
self.stop_btn.disabled = self.sr_ctx.is_stop
self.running_ring.visible = self.sr_ctx.is_running
self.running_status.update_label(self.sr_ctx.status_text)
self.update()

def _after_start(self):
Expand Down Expand Up @@ -440,8 +439,8 @@ def _update_character_status_local_part(self):
osv: OneStopView = None


def get(ctx: Context):
def get(page: ft.Page, ctx: Context):
global osv
if osv is None:
osv = OneStopView(ctx)
osv = OneStopView(page, ctx)
return osv

0 comments on commit 380f184

Please sign in to comment.