MoleditPy-linux 2.0.0__py3-none-any.whl → 2.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ from PyQt6.QtGui import QFont, QColor
16
16
  from rdkit import Chem
17
17
 
18
18
  #Version
19
- VERSION = '2.0.0'
19
+ VERSION = '2.1.0'
20
20
 
21
21
  ATOM_RADIUS = 18
22
22
  BOND_OFFSET = 3.5
@@ -1214,6 +1214,8 @@ class MainWindowMainInit(object):
1214
1214
  reload_plugins_action = QAction("Reload Plugins", self)
1215
1215
  reload_plugins_action.triggered.connect(lambda: self.update_plugin_menu(plugin_menu))
1216
1216
  plugin_menu.addAction(reload_plugins_action)
1217
+
1218
+
1217
1219
 
1218
1220
  plugin_menu.addSeparator()
1219
1221
 
@@ -1723,19 +1725,53 @@ class MainWindowMainInit(object):
1723
1725
  reload_plugins_action = QAction("Reload Plugins", self)
1724
1726
  reload_plugins_action.triggered.connect(lambda: self.update_plugin_menu(plugin_menu))
1725
1727
  plugin_menu.addAction(reload_plugins_action)
1728
+
1729
+ explore_plugins_action = QAction("Explore Plugins", self)
1730
+ explore_plugins_action.triggered.connect(
1731
+ lambda: QDesktopServices.openUrl(QUrl("https://github.com/HiroYokoyama/moleditpy-plugins"))
1732
+ )
1733
+ plugin_menu.addAction(explore_plugins_action)
1726
1734
 
1727
1735
  plugin_menu.addSeparator()
1728
1736
 
1729
1737
  # Add dynamic plugin actions
1730
1738
  plugins = self.plugin_manager.discover_plugins(self)
1739
+
1731
1740
  if not plugins:
1732
1741
  no_plugin_action = QAction("(No plugins found)", self)
1733
1742
  no_plugin_action.setEnabled(False)
1734
1743
  plugin_menu.addAction(no_plugin_action)
1735
1744
  else:
1745
+ # Sort plugins: directories first (to create menus), then alphabetical by name
1746
+ # Actually simple sort by rel_folder, name is fine
1747
+ plugins.sort(key=lambda x: (x.get('rel_folder', ''), x['name']))
1748
+
1749
+ # Dictionary to keep track of created submenus: path -> QMenu
1750
+ menus = { "": plugin_menu }
1751
+
1736
1752
  for p in plugins:
1737
- # Use default param in lambda to capture the current p
1753
+ rel_folder = p.get('rel_folder', "")
1754
+
1755
+ # Get or create the parent menu for this plugin
1756
+ parent_menu = menus.get("") # Start at root
1757
+
1758
+ if rel_folder:
1759
+ # Split path and traverse/create submenus
1760
+ parts = rel_folder.split(os.sep)
1761
+ current_path = ""
1762
+ for part in parts:
1763
+ new_path = os.path.join(current_path, part) if current_path else part
1764
+
1765
+ if new_path not in menus:
1766
+ # Create new submenu
1767
+ sub_menu = parent_menu.addMenu(part)
1768
+ menus[new_path] = sub_menu
1769
+
1770
+ parent_menu = menus[new_path]
1771
+ current_path = new_path
1772
+
1773
+ # Add action to the resolved parent_menu
1738
1774
  action = QAction(p['name'], self)
1739
1775
  action.triggered.connect(lambda checked, mod=p['module']: self.plugin_manager.run_plugin(mod, self.mw if hasattr(self, 'mw') else self))
1740
- plugin_menu.addAction(action)
1776
+ parent_menu.addAction(action)
1741
1777
 
@@ -34,7 +34,8 @@ class PluginManager:
34
34
 
35
35
  def discover_plugins(self, parent=None):
36
36
  """
37
- Scans the plugin directory for .py files and attempts to import them.
37
+ Recursively scans the plugin directory for .py files and attempts to import them.
38
+ Ignores __pycache__ and other directories starting with "__".
38
39
  Returns a list of valid loaded plugins.
39
40
  """
40
41
  self.ensure_plugin_dir()
@@ -43,35 +44,69 @@ class PluginManager:
43
44
  if not os.path.exists(self.plugin_dir):
44
45
  return []
45
46
 
46
- for filename in os.listdir(self.plugin_dir):
47
- if filename.endswith(".py") and not filename.startswith("__"):
48
- filepath = os.path.join(self.plugin_dir, filename)
49
- try:
50
- # Dynamically import the module
51
- spec = importlib.util.spec_from_file_location(filename[:-3], filepath)
52
- if spec and spec.loader:
53
- module = importlib.util.module_from_spec(spec)
54
- sys.modules[spec.name] = module # helper for relative imports if needed
55
- spec.loader.exec_module(module)
56
-
57
- # Check for required attributes
58
- plugin_name = getattr(module, 'PLUGIN_NAME', filename[:-3])
47
+ for root, dirs, files in os.walk(self.plugin_dir):
48
+ # Modify dirs in-place to skip hidden directories and __pycache__
49
+ dirs[:] = [d for d in dirs if not d.startswith('__') and d != '__pycache__']
50
+
51
+ for filename in files:
52
+ if filename.endswith(".py") and not filename.startswith("__"):
53
+ filepath = os.path.join(root, filename)
54
+
55
+ # Calculate relative folder path for menu structure
56
+ # equivalent to: rel_path = os.path.relpath(root, self.plugin_dir)
57
+ # if root is plugin_dir, rel_path is '.'
58
+ rel_folder = os.path.relpath(root, self.plugin_dir)
59
+ if rel_folder == '.':
60
+ rel_folder = ""
61
+
62
+ try:
63
+ # Unique module name based on file path to avoid conflicts
64
+ # e.g. plugins.subdir.myplugin
65
+ module_name = os.path.splitext(os.path.relpath(filepath, self.plugin_dir))[0].replace(os.sep, '.')
59
66
 
60
- # Validate that it has a run function
61
- if hasattr(module, 'run') and callable(module.run):
62
- self.plugins.append({
63
- 'name': plugin_name,
64
- 'module': module
65
- })
66
- else:
67
- print(f"Plugin {filename} skipped: Missing 'run(main_window)' function.")
68
- except Exception as e:
69
- # Robust error handling with user notification
70
- msg = f"Failed to load plugin {filename}:\n{e}"
71
- print(msg)
72
- traceback.print_exc()
73
- if parent:
74
- QMessageBox.warning(parent, "Plugin Load Error", msg)
67
+ spec = importlib.util.spec_from_file_location(module_name, filepath)
68
+ if spec and spec.loader:
69
+ module = importlib.util.module_from_spec(spec)
70
+ sys.modules[spec.name] = module
71
+ spec.loader.exec_module(module)
72
+
73
+ # Check for required attributes
74
+ plugin_name = getattr(module, 'PLUGIN_NAME', filename[:-3])
75
+
76
+ # Valid plugin if it has 'run' OR 'autorun'
77
+ has_run = hasattr(module, 'run') and callable(module.run)
78
+ has_autorun = hasattr(module, 'autorun') and callable(module.autorun)
79
+
80
+ if has_run:
81
+ self.plugins.append({
82
+ 'name': plugin_name,
83
+ 'module': module,
84
+ 'rel_folder': rel_folder
85
+ })
86
+
87
+ if has_autorun:
88
+ try:
89
+ if parent:
90
+ module.autorun(parent)
91
+ else:
92
+ print(f"Skipping autorun for {plugin_name}: parent not provided.")
93
+ except Exception as e:
94
+ print(f"Error executing autorun for {filename}: {e}")
95
+ traceback.print_exc()
96
+
97
+ if not has_run and not has_autorun:
98
+ print(f"Plugin {filename} skipped: Missing 'run(main_window)' or 'autorun(main_window)' function.")
99
+
100
+ except Exception as e:
101
+ # Robust error handling
102
+ msg = f"Failed to load plugin {filename}:\n{e}"
103
+ print(msg)
104
+ traceback.print_exc()
105
+ if parent:
106
+ # Use print/status bar instead of popups for non-critical failures during bulk load?
107
+ # For now, keep it visible but maybe less intrusive if many fail?
108
+ # sticking to original logic just in catch block
109
+ pass
75
110
 
76
111
  return self.plugins
77
112
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MoleditPy-linux
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: A cross-platform, simple, and intuitive molecular structure editor built in Python. It allows 2D molecular drawing and 3D structure visualization. It supports exporting structure files for input to DFT calculation software.
5
5
  Author-email: HiroYokoyama <titech.yoko.hiro@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -12,7 +12,7 @@ moleditpy_linux/modules/bond_item.py,sha256=eVkEeKvM4igYI67DYxpey3FllqDyt_iWDo4V
12
12
  moleditpy_linux/modules/bond_length_dialog.py,sha256=k5x_DhK9Q8CSwouKhEo_kLRRdaYHDaK84KDNmuDNLvY,14868
13
13
  moleditpy_linux/modules/calculation_worker.py,sha256=KiGQY7i-QCQofEoE0r65KoQgpEGFcbhmxWv6egfkUdc,42324
14
14
  moleditpy_linux/modules/color_settings_dialog.py,sha256=Ow44BhCOLo0AFb6klO001k6B4drOgKX9DeNBQhZLp5o,15474
15
- moleditpy_linux/modules/constants.py,sha256=oymYKVgSZfnEmImv_QkbSUxjf7xw-XmQi0MVUQybUb4,4702
15
+ moleditpy_linux/modules/constants.py,sha256=oZuMoNzSH87-nWDMDeJ8pi5WxslbauU2b5LTAtM3u1k,4702
16
16
  moleditpy_linux/modules/constrained_optimization_dialog.py,sha256=IEdNVhFoNSEMeA5ABpUH9Q88-YzDXFloQM2gwnPwnHY,30150
17
17
  moleditpy_linux/modules/custom_interactor_style.py,sha256=NjsXE2a43IDNEanZBlcG9eR4ZIERT1MsQC6lbfesapQ,38453
18
18
  moleditpy_linux/modules/custom_qt_interactor.py,sha256=MFaTuDh-FPeFBS4303CqxsxmsOIOW4QXUz6USwI8PHQ,2451
@@ -25,7 +25,7 @@ moleditpy_linux/modules/main_window_dialog_manager.py,sha256=S1ROCWqzB2uVSKHY4o5
25
25
  moleditpy_linux/modules/main_window_edit_3d.py,sha256=uY203adPg3CLyAdbG2NCThG2Am0WduzPDan9rXAlc14,19841
26
26
  moleditpy_linux/modules/main_window_edit_actions.py,sha256=lUFxNFTUQzeXN8CNlb4_4S9j4M1EEq8kpJmh9dCzM3M,64818
27
27
  moleditpy_linux/modules/main_window_export.py,sha256=e0HA_jeaokIOBunQqGxUn5QKdniCmE8GrsE1Igy6zm8,38351
28
- moleditpy_linux/modules/main_window_main_init.py,sha256=LyL6oUju8KH982UwC0O8ZlN0UW4zDl5DIN2mnN4OGlM,78220
28
+ moleditpy_linux/modules/main_window_main_init.py,sha256=brmB2zwiW58SFNDxFDqCxXlIdj77fMP5FGarflp7Am0,79797
29
29
  moleditpy_linux/modules/main_window_molecular_parsers.py,sha256=Ex4-urYsKf6PyHp4XToOhgXzuYWa_n7q--QmHci4OCU,48401
30
30
  moleditpy_linux/modules/main_window_project_io.py,sha256=q1vEmWQDqla32HVkmk8-j0OY9ut5TI5NJ4ikahewkEo,17259
31
31
  moleditpy_linux/modules/main_window_string_importers.py,sha256=mQVDv2Dj4MwnPgMRe2IqdAAKnB_quE6QfYeAgCjfv28,10892
@@ -38,7 +38,7 @@ moleditpy_linux/modules/molecule_scene.py,sha256=c5GNL7LrzerXYWshmpY_6Rg-2cBlF7x
38
38
  moleditpy_linux/modules/move_group_dialog.py,sha256=65HVXTJSaQ9lp03XFhI1l7OzUsXmH_aqd8OgwjpjfGg,27174
39
39
  moleditpy_linux/modules/periodic_table_dialog.py,sha256=ItEZUts1XCietz9paY-spvbzxh6SXak3GnikwqkHZCw,4006
40
40
  moleditpy_linux/modules/planarize_dialog.py,sha256=yY8o-SxT8vGEHVWnjDTXecRv5NUaEejEsXH-836Xk8g,8681
41
- moleditpy_linux/modules/plugin_manager.py,sha256=Qbje9i-b4f81k_gxiDkfH8bv2eNTTya1563L93USQQA,3441
41
+ moleditpy_linux/modules/plugin_manager.py,sha256=2GwuJurN09VVmPYjnr5GhrBf4JSxqLFVeVbqoKo5T24,5570
42
42
  moleditpy_linux/modules/settings_dialog.py,sha256=Nr7yE8UmYRi3VObWvRlrnv0DnjSjmYXbvqryZ02O12k,65348
43
43
  moleditpy_linux/modules/template_preview_item.py,sha256=Ks3C35pYFuLT5G4fsloI7ljE6ESXoYyGvLkM22qcmt0,6673
44
44
  moleditpy_linux/modules/template_preview_view.py,sha256=4OCHZDO51BvJpKdfrBWJ4_4WfLfFSKxsVIyf7I-Kj2E,3350
@@ -48,9 +48,9 @@ moleditpy_linux/modules/zoomable_view.py,sha256=hjwljui13QpvjvxJHY4Evot4jMQvxRBQ
48
48
  moleditpy_linux/modules/assets/icon.icns,sha256=wD5R6-Vw7K662tVKhu2E1ImN0oUuyAP4youesEQsn9c,139863
49
49
  moleditpy_linux/modules/assets/icon.ico,sha256=RfgFcx7-dHY_2STdsOQCQziY5SNhDr3gPnjO6jzEDPI,147975
50
50
  moleditpy_linux/modules/assets/icon.png,sha256=kCFN1WacYIdy0GN6SFEbNA00ef39pCczBnFdkkBI8Bs,147110
51
- moleditpy_linux-2.0.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
52
- moleditpy_linux-2.0.0.dist-info/METADATA,sha256=CZGaO8ZM37diuIQeFF8Q7vTDuBvzyL7uTMEMe_1ERH4,59064
53
- moleditpy_linux-2.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
54
- moleditpy_linux-2.0.0.dist-info/entry_points.txt,sha256=-OzipSi__yVwlimNtu3eiRP5t5UMg55Cs0udyhXYiyw,60
55
- moleditpy_linux-2.0.0.dist-info/top_level.txt,sha256=qyqe-hDYL6CXyin9E5Me5rVl3PG84VqiOjf9bQvfJLs,16
56
- moleditpy_linux-2.0.0.dist-info/RECORD,,
51
+ moleditpy_linux-2.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
52
+ moleditpy_linux-2.1.0.dist-info/METADATA,sha256=5Q6RrfsvnCTkV7JQTkJkmmzpdLCx0FB68Y1IuVgmM_o,59064
53
+ moleditpy_linux-2.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
54
+ moleditpy_linux-2.1.0.dist-info/entry_points.txt,sha256=-OzipSi__yVwlimNtu3eiRP5t5UMg55Cs0udyhXYiyw,60
55
+ moleditpy_linux-2.1.0.dist-info/top_level.txt,sha256=qyqe-hDYL6CXyin9E5Me5rVl3PG84VqiOjf9bQvfJLs,16
56
+ moleditpy_linux-2.1.0.dist-info/RECORD,,