Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/mp_plugins/base/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def __message_dispatching(self, message: Message) -> None:
return
for handler in self._event_handlers[message.data.__class__]:
event = handler(self, message.data)
if event.__class__ != message.data.__class__:
raise TypeError(
f"Event handler must return the same event type got {event.__class__.__name__} expected {message.data.__class__.__name__}"
)
message.data = event
self.__message_queue.put(message)
else:
Expand All @@ -163,7 +167,7 @@ def __message_dispatching(self, message: Message) -> None:
if hasattr(self, "_context"):
self._context = message.data
self.initialize()
self._context = message.class_name
self._context = message.data
elif message.mode == MessageMode.Error:
pass
elif message.mode == MessageMode.Unknown:
Expand Down
6 changes: 3 additions & 3 deletions src/mp_plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self) -> None:
self.__error_callback = None

self.__running = False
self.__context: BaseContext = None
self.__context: BaseContext | None = None

# -------------------------
# 单例
Expand All @@ -78,7 +78,7 @@ def port(self):

@property
def context(self) -> BaseContext:
return self.__context
return self.__context # type: ignore

@context.setter
def context(self, context: BaseContext):
Expand Down Expand Up @@ -230,7 +230,7 @@ def send_event(
if message.id in self.__event_dict:
del self.__event_dict[message.id]

return result
return result # type: ignore

# -------------------------
# 发消息入口(入队)
Expand Down
30 changes: 17 additions & 13 deletions src/pluginDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
_translate = QCoreApplication.translate


class PluginManagerUI(RoundQDialog):
class PluginManagerUI(QDialog):

def __init__(self, plugin_names: list[str]):
"""
Expand All @@ -64,8 +64,10 @@ def __init__(self, plugin_names: list[str]):
# ================= 左侧插件列表 =================
self.list_widget = QListWidget()
for name in self.plugin_names:
self.list_widget.addItem(
PluginManager.instance().Get_Context_By_Name(name).display_name)
ctx = PluginManager.instance().Get_Context_By_Name(name)
if ctx is None:
continue
self.list_widget.addItem(ctx.display_name)

self.list_widget.currentRowChanged.connect(self.on_plugin_selected)
root_layout.addWidget(self.list_widget, 1)
Expand Down Expand Up @@ -167,6 +169,8 @@ def update_context(self, index: int):

ctx = PluginManager.instance().Get_Context_By_Name(
self.plugin_names[index])
if ctx is None:
return

# --- PluginContext 原样填充 ---
for key, value in msgspec.structs.asdict(ctx).items():
Expand All @@ -184,8 +188,11 @@ def load_settings(self, settings: Dict[str, BaseSetting]):
# 清空原控件
while self.scroll_layout.count():
item = self.scroll_layout.takeAt(0)
if item.widget():
item.widget().deleteLater()
if item is None:
continue
widget = item.widget()
if widget is not None:
widget.deleteLater()

self.current_settings_widgets.clear()

Expand Down Expand Up @@ -221,14 +228,11 @@ def load_settings(self, settings: Dict[str, BaseSetting]):
# 保存按钮
# ===================================================================
def on_save_clicked(self):
ctx = self.plugin_contexts[self.list_widget.currentRow()]

# --- PluginContext 原样填充 ---
for key, label in self.detail_labels.items():
value = getattr(ctx, key)
if isinstance(value, list):
value = ", ".join(value)
label.setText(str(value))
ctx = PluginManager.instance().Get_Context_By_Name(
self.plugin_names[self.list_widget.currentRow()]
)
if ctx is None:
return

# --- 你自己的获取 settings 的函数 ---
settings_dict = PluginManager.instance().Get_Settings(ctx.name)
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/History/History.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sys
import os
import msgspec
Expand Down Expand Up @@ -78,8 +77,8 @@ def shutdown(self) -> None:
return super().shutdown()

@BasePlugin.event_handler(GameEndEvent)
def on_game_end(self, event: GameEndEvent) -> None:
pass
def on_game_end(self, event: GameEndEvent):
return event


if __name__ == "__main__":
Expand Down