-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
132 lines (111 loc) · 4.57 KB
/
plugin.py
File metadata and controls
132 lines (111 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3
"""
Plugin Manager GUI - Main plugin implementation.
Provides a graphical interface for discovering, installing, and managing
community plugins from the TonieToolbox marketplace.
"""
from pathlib import Path
from typing import Optional
from TonieToolbox.core.plugins.base import BasePlugin, PluginContext, PluginManifest, PluginMetadata, PluginType
from TonieToolbox.core.plugins.manager import get_plugin_manager
from TonieToolbox.core.utils.logging import get_logger
logger = get_logger('TonieToolbox.plugin.PluginManager')
class PluginManagerGUI(BasePlugin):
"""
GUI plugin for managing community plugins.
Features:
- Browse and search plugin marketplace
- Install plugins with automatic dependency resolution
- Update installed plugins
- Enable/disable plugins
- Configure plugin settings
"""
def get_manifest(self) -> PluginManifest:
"""Return the plugin manifest."""
metadata = PluginMetadata(
id="com.tonietoolbox.plugin_manager",
name="Plugin Manager",
version="1.0.0",
author="TonieToolbox",
description="GUI for browsing, installing, and managing community plugins",
plugin_type=PluginType.GUI,
homepage="https://github.com/TonieToolbox/TonieToolbox",
license="GPL-3.0",
min_tonietoolbox_version="1.0.0",
tags=["gui", "plugin", "marketplace", "manager"]
)
return PluginManifest(
metadata=metadata,
permissions=["gui", "network", "filesystem"]
)
def initialize(self, context: PluginContext) -> bool:
"""
Initialize the plugin.
Args:
context: Plugin context with app services
Returns:
True if initialization succeeded
"""
try:
self._context = context
logger.info("Plugin Manager GUI initialized")
return True
except Exception as e:
logger.error(f"Failed to initialize Plugin Manager GUI: {e}")
return False
def enable(self) -> bool:
"""
Enable the plugin and register GUI components.
Returns:
True if plugin was enabled
"""
try:
# Register menu item
from TonieToolbox.core.plugins.builtin.plugin_manager.ui.manager_window import PluginManagerWindow
# Store reference to window class
self._window_class = PluginManagerWindow
logger.info("Plugin Manager GUI enabled")
return super().enable()
except Exception as e:
logger.error(f"Failed to enable Plugin Manager GUI: {e}", exc_info=True)
return False
def disable(self) -> bool:
"""
Disable the plugin.
Returns:
True if plugin was disabled
"""
try:
# Cleanup will happen in cleanup()
logger.info("Plugin Manager GUI disabled")
return super().disable()
except Exception as e:
logger.error(f"Failed to disable Plugin Manager GUI: {e}", exc_info=True)
return False
def cleanup(self) -> None:
"""Clean up plugin resources."""
try:
self._window_class = None
logger.info("Plugin Manager GUI cleaned up")
except Exception as e:
logger.error(f"Error during Plugin Manager GUI cleanup: {e}", exc_info=True)
def show_manager_window(self):
"""Show the plugin manager window."""
try:
if not hasattr(self, '_window_class') or not self._window_class:
logger.error("Plugin Manager window class not initialized")
return
# Get the actual plugin manager from context (the one that loaded us)
plugin_manager = self._context._plugin_manager if self._context and hasattr(self._context, '_plugin_manager') else None
if not plugin_manager:
logger.error("Plugin manager not available in context")
return
config_manager = self._context.config_manager if self._context else None
window = self._window_class(
plugin_manager=plugin_manager,
config_manager=config_manager,
context=self._context
)
window.exec()
except Exception as e:
logger.error(f"Failed to show plugin manager window: {e}", exc_info=True)