Perliminary properties viewer plugin

This commit is contained in:
2022-07-16 02:33:25 -05:00
parent bcc04dda3c
commit b1bf8785c6
7 changed files with 1050 additions and 77 deletions

View File

@@ -19,6 +19,9 @@ class State:
tab: type = None
icon_grid: gi.overrides.Gtk.IconView = None
store: gi.overrides.Gtk.ListStore = None
selected_files: [] = None
to_copy_files: [] = None
to_cut_files: [] = None
class Controller_Data:
@@ -138,6 +141,18 @@ class Controller_Data:
state.icon_grid = self.builder.get_object(f"{state.wid}|{state.tid}|icon_grid")
state.store = state.icon_grid.get_model()
selected_files = state.icon_grid.get_selected_items()
# if self.selected_files:
if selected_files:
state.selected_files = self.format_to_uris(state.store, state.wid, state.tid, selected_files, True)
# if self.to_copy_files:
# state.to_copy_files = self.format_to_uris(state.store, state.wid, state.tid, self.to_copy_files, True)
#
# if self.to_cut_files:
# state.to_cut_files = self.format_to_uris(state.store, state.wid, state.tid, self.to_cut_files, True)
return state

View File

@@ -16,7 +16,7 @@ class Plugin:
author: str = None
version: str = None
support: str = None
permissions:{} = None
requests:{} = None
reference: type = None
@@ -53,72 +53,76 @@ class Plugins:
print(f"Loading plugins...")
parent_path = os.getcwd()
for file in os.listdir(self._plugins_path):
for path, folder in [[join(self._plugins_path, item), item] if os.path.isdir(join(self._plugins_path, item)) else None for item in os.listdir(self._plugins_path)]:
try:
path = join(self._plugins_path, file)
if isdir(path):
module = self.load_plugin_module(path, file)
plugin = self.collect_info(module, path)
loading_data = self.parse_permissions(plugin)
target = join(path, "plugin.py")
if not os.path.exists(target):
raise Exception("Invalid Plugin Structure: Plugin doesn't have 'plugin.py'. Aboarting load...")
self.execute_plugin(module, plugin, loading_data)
module = self.load_plugin_module(path, folder, target)
plugin = self.collect_info(module, path)
loading_data = self.parse_requests(plugin)
self.execute_plugin(module, plugin, loading_data)
except Exception as e:
print("Malformed plugin! Not loading!")
print(f"Malformed Plugin: Not loading -->: '{folder}' !")
traceback.print_exc()
# if debug:
# traceback.print_exc()
os.chdir(parent_path)
def load_plugin_module(self, path, file):
def load_plugin_module(self, path, folder, target):
os.chdir(path)
sys.path.insert(0, path)
spec = importlib.util.spec_from_file_location(file, join(path, "plugin.py"))
spec = importlib.util.spec_from_file_location(folder, target)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def collect_info(self, module, path) -> Plugin:
plugin = Plugin()
plugin.path = module.Manifest.path
plugin.name = module.Manifest.name
plugin.author = module.Manifest.author
plugin.version = module.Manifest.version
plugin.support = module.Manifest.support
plugin.permissions = module.Manifest.permissions
plugin = Plugin()
plugin.path = module.Manifest.path
plugin.name = module.Manifest.name
plugin.author = module.Manifest.author
plugin.version = module.Manifest.version
plugin.support = module.Manifest.support
plugin.requests = module.Manifest.requests
return plugin
def parse_permissions(self, plugin):
def parse_requests(self, plugin):
loading_data = {}
permissions = plugin.permissions
keys = permissions.keys()
requests = plugin.requests
keys = requests.keys()
if "ui_target" in keys:
if permissions["ui_target"] in [
"none", "other", "main_Window", "main_menu_bar", "path_menu_bar", "plugin_control_list",
"context_menu", "window_1", "window_2", "window_3", "window_4"
]:
if permissions["ui_target"] == "other":
if requests["ui_target"] in [
"none", "other", "main_Window", "main_menu_bar", "path_menu_bar", "plugin_control_list",
"context_menu", "window_1", "window_2", "window_3", "window_4"
]:
if requests["ui_target"] == "other":
if "ui_target_id" in keys:
loading_data["ui_target"] = self._builder.get_object(permissions["ui_target_id"])
loading_data["ui_target"] = self._builder.get_object(requests["ui_target_id"])
if loading_data["ui_target"] == None:
raise Exception('Invalid "ui_target_id" given in permissions. Must have one if setting "ui_target" to "other"...')
raise Exception('Invalid "ui_target_id" given in requests. Must have one if setting "ui_target" to "other"...')
else:
raise Exception('Invalid "ui_target_id" given in permissions. Must have one if setting "ui_target" to "other"...')
raise Exception('Invalid "ui_target_id" given in requests. Must have one if setting "ui_target" to "other"...')
else:
loading_data["ui_target"] = self._builder.get_object(permissions["ui_target"])
loading_data["ui_target"] = self._builder.get_object(requests["ui_target"])
else:
raise Exception('Unknown "ui_target" given in permissions.')
raise Exception('Unknown "ui_target" given in requests.')
if "pass_fm_events" in keys:
if permissions["pass_fm_events"] in ["true"]:
if requests["pass_fm_events"] in ["true"]:
loading_data["pass_fm_events"] = True
if "bind_keys" in keys:
if isinstance(permissions["bind_keys"], list):
loading_data["bind_keys"] = permissions["bind_keys"]
if isinstance(requests["bind_keys"], list):
loading_data["bind_keys"] = requests["bind_keys"]
return loading_data