molforge-studio 7.4.3__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.
Files changed (219) hide show
  1. main.py +71 -0
  2. molforge/__init__.py +19 -0
  3. molforge/ai/__init__.py +15 -0
  4. molforge/ai/deepseek_harness.py +185 -0
  5. molforge/ai/mcp/desktop_client.py +38 -0
  6. molforge/ai/mcp/desktop_service.py +121 -0
  7. molforge/ai/mcp/mcp_server.py +780 -0
  8. molforge/ai/mcp_bridge.py +945 -0
  9. molforge/ai/observation.py +152 -0
  10. molforge/ai/tools.py +455 -0
  11. molforge/application/__init__.py +22 -0
  12. molforge/application/ai/__init__.py +1 -0
  13. molforge/application/ai/deepseek_client.py +293 -0
  14. molforge/application/ai/observation.py +161 -0
  15. molforge/application/ai/tools.py +200 -0
  16. molforge/application/ai_proposals.py +166 -0
  17. molforge/application/bio_selection.py +143 -0
  18. molforge/application/builtin_commands.py +1445 -0
  19. molforge/application/calculators/__init__.py +10 -0
  20. molforge/application/calculators/base.py +143 -0
  21. molforge/application/calculators/calchem_engine.py +67 -0
  22. molforge/application/calculators/calchem_subprocess_worker.py +109 -0
  23. molforge/application/calculators/gaussian_engine.py +59 -0
  24. molforge/application/calculators/gaussian_job_spec.py +240 -0
  25. molforge/application/calculators/orca_engine.py +92 -0
  26. molforge/application/calculators/qc_input_generator.py +300 -0
  27. molforge/application/calculators/registry.py +29 -0
  28. molforge/application/calculators/rest_engine.py +262 -0
  29. molforge/application/command_bus.py +139 -0
  30. molforge/application/commands.py +55 -0
  31. molforge/application/conformers.py +143 -0
  32. molforge/application/document_session.py +156 -0
  33. molforge/application/events.py +74 -0
  34. molforge/application/fragment_catalog.py +422 -0
  35. molforge/application/fragment_commands.py +268 -0
  36. molforge/application/geometry_commands.py +84 -0
  37. molforge/application/history.py +105 -0
  38. molforge/application/internal_coordinates.py +293 -0
  39. molforge/application/invalidation.py +1174 -0
  40. molforge/application/jobs.py +185 -0
  41. molforge/application/measurement.py +167 -0
  42. molforge/application/measurement_targets.py +264 -0
  43. molforge/application/modeling_commands.py +61 -0
  44. molforge/application/plugins.py +197 -0
  45. molforge/application/ports/editor2d.py +85 -0
  46. molforge/application/reaction.py +75 -0
  47. molforge/application/selection.py +164 -0
  48. molforge/application/selection_commands.py +31 -0
  49. molforge/application/trajectory.py +120 -0
  50. molforge/application/trajectory_analysis.py +231 -0
  51. molforge/application/workspace_registry.py +226 -0
  52. molforge/core/__init__.py +12 -0
  53. molforge/core/conformer.py +45 -0
  54. molforge/core/molecule.py +150 -0
  55. molforge/core/orbital.py +33 -0
  56. molforge/core/properties.py +43 -0
  57. molforge/domain/__init__.py +12 -0
  58. molforge/domain/biomolecule.py +99 -0
  59. molforge/domain/chemical_summary.py +129 -0
  60. molforge/domain/chemistry.py +13 -0
  61. molforge/domain/coordinate_store.py +164 -0
  62. molforge/domain/coordination.py +133 -0
  63. molforge/domain/custom_fragments.py +255 -0
  64. molforge/domain/document.py +469 -0
  65. molforge/domain/element_reference.json +598 -0
  66. molforge/domain/elements.py +188 -0
  67. molforge/domain/ids.py +58 -0
  68. molforge/domain/massive_system.py +246 -0
  69. molforge/domain/periodic.py +116 -0
  70. molforge/domain/provenance.py +115 -0
  71. molforge/domain/topology.py +364 -0
  72. molforge/infrastructure/__init__.py +23 -0
  73. molforge/infrastructure/hpc/cluster_config.py +122 -0
  74. molforge/infrastructure/hpc/remote_executor.py +212 -0
  75. molforge/infrastructure/hpc/slurm_generator.py +93 -0
  76. molforge/io/__init__.py +35 -0
  77. molforge/io/calchem_bridge.py +407 -0
  78. molforge/io/calculators.py +893 -0
  79. molforge/io/cclib_adapter.py +422 -0
  80. molforge/io/conformers.py +183 -0
  81. molforge/io/cube_reader.py +215 -0
  82. molforge/io/custom_fragments.py +79 -0
  83. molforge/io/format_matrix.py +157 -0
  84. molforge/io/gemmi_adapter.py +150 -0
  85. molforge/io/history_skill.py +46 -0
  86. molforge/io/mdanalysis_adapter.py +155 -0
  87. molforge/io/mforge_storage.py +261 -0
  88. molforge/io/multiwfn_driver.py +614 -0
  89. molforge/io/openbabel_adapter.py +265 -0
  90. molforge/io/openbabel_handler.py +33 -0
  91. molforge/io/rdkit_adapter.py +1865 -0
  92. molforge/io/readers/__init__.py +10 -0
  93. molforge/io/readers/cube_reader.py +71 -0
  94. molforge/io/readers/gjf_reader.py +110 -0
  95. molforge/io/readers/glog_reader.py +45 -0
  96. molforge/io/readers/mol2_reader.py +36 -0
  97. molforge/io/readers/mol_reader.py +56 -0
  98. molforge/io/readers/pdb_reader.py +39 -0
  99. molforge/io/readers/smi_reader.py +40 -0
  100. molforge/io/readers/xyz_reader.py +47 -0
  101. molforge/io/registry.py +128 -0
  102. molforge/io/writers/__init__.py +7 -0
  103. molforge/io/writers/gjf_writer.py +68 -0
  104. molforge/io/writers/pdb_writer.py +37 -0
  105. molforge/io/writers/png_writer.py +31 -0
  106. molforge/io/writers/svg_writer.py +111 -0
  107. molforge/io/writers/xyz_writer.py +39 -0
  108. molforge/rendering/__init__.py +21 -0
  109. molforge/rendering/benchmark.py +121 -0
  110. molforge/rendering/bridge.py +60 -0
  111. molforge/rendering/contracts.py +119 -0
  112. molforge/rendering/glyph_scene.py +279 -0
  113. molforge/rendering/ketcher_bridge.py +131 -0
  114. molforge/rendering/ketcher_id_mapping.py +110 -0
  115. molforge/rendering/materials.py +127 -0
  116. molforge/rendering/molstar_backend.py +245 -0
  117. molforge/rendering/native_labels.py +134 -0
  118. molforge/rendering/orbitals.py +139 -0
  119. molforge/rendering/vtk_backend.py +2294 -0
  120. molforge/runtime.py +29 -0
  121. molforge/server/__init__.py +1 -0
  122. molforge/server/api_bridge.py +947 -0
  123. molforge/ui/__init__.py +1 -0
  124. molforge/ui/assets/caffeine_2d.svg +150 -0
  125. molforge/ui/assets/caffeine_3d_preview.svg +209 -0
  126. molforge/ui/assets/caffeine_preview.json +302 -0
  127. molforge/ui/assets/icons/atom.svg +1 -0
  128. molforge/ui/assets/icons/bond.svg +1 -0
  129. molforge/ui/assets/icons/cleanup.svg +1 -0
  130. molforge/ui/assets/icons/export.svg +1 -0
  131. molforge/ui/assets/icons/fragments.svg +1 -0
  132. molforge/ui/assets/icons/history.svg +1 -0
  133. molforge/ui/assets/icons/jobs.svg +1 -0
  134. molforge/ui/assets/icons/measure.svg +1 -0
  135. molforge/ui/assets/icons/molecules.svg +1 -0
  136. molforge/ui/assets/icons/overview.svg +1 -0
  137. molforge/ui/assets/icons/ring.svg +1 -0
  138. molforge/ui/assets/icons/search.svg +1 -0
  139. molforge/ui/assets/icons/select.svg +1 -0
  140. molforge/ui/assets/icons/settings.svg +1 -0
  141. molforge/ui/assets/icons/templates.svg +1 -0
  142. molforge/ui/assets/molforge_logo.ico +0 -0
  143. molforge/ui/assets/molforge_logo.png +0 -0
  144. molforge/ui/atom_labels.py +92 -0
  145. molforge/ui/bio_structure_dialog.py +57 -0
  146. molforge/ui/conformer_dialog.py +151 -0
  147. molforge/ui/dialogs/__init__.py +2 -0
  148. molforge/ui/dialogs/aim_qtaim_dialog.py +533 -0
  149. molforge/ui/dialogs/calchem_orbitals_dialog.py +287 -0
  150. molforge/ui/dialogs/element_fragments.py +130 -0
  151. molforge/ui/dialogs/gaussian_calculation_setup.py +308 -0
  152. molforge/ui/dialogs/hpc_job_dialog.py +427 -0
  153. molforge/ui/dialogs/vibrational_spectrum_dialog.py +381 -0
  154. molforge/ui/editor2d_widget.py +1803 -0
  155. molforge/ui/element_picker.py +218 -0
  156. molforge/ui/gmv_window_manager.py +65 -0
  157. molforge/ui/gromacs_job_dialog.py +47 -0
  158. molforge/ui/hotkeys.py +107 -0
  159. molforge/ui/i18n.py +237 -0
  160. molforge/ui/live_llm_dialog.py +135 -0
  161. molforge/ui/llm_config_dialog.py +103 -0
  162. molforge/ui/modeling_actions.py +176 -0
  163. molforge/ui/molstar_widget.py +98 -0
  164. molforge/ui/molstar_window.py +85 -0
  165. molforge/ui/panels.py +2966 -0
  166. molforge/ui/qc_result_dialog.py +1924 -0
  167. molforge/ui/render3d_widget.py +1579 -0
  168. molforge/ui/scrolling.py +52 -0
  169. molforge/ui/settings_panel.py +330 -0
  170. molforge/ui/shells/__init__.py +4 -0
  171. molforge/ui/shells/base_shell.py +72 -0
  172. molforge/ui/shells/document_tabs.py +715 -0
  173. molforge/ui/shells/studio_2d.py +339 -0
  174. molforge/ui/shells/studio_3d.py +401 -0
  175. molforge/ui/shells/studio_split.py +370 -0
  176. molforge/ui/shells/workflow_inputs.py +698 -0
  177. molforge/ui/theme.py +719 -0
  178. molforge/ui/trajectory_window.py +333 -0
  179. molforge/ui/views.py +892 -0
  180. molforge/ui/vtk_multiview_widget.py +141 -0
  181. molforge/ui/welcome_window.py +223 -0
  182. molforge/ui/window.py +3320 -0
  183. molforge/workflows/__init__.py +25 -0
  184. molforge/workflows/assets/OSC_MD_workflows/templates/01-MD/delete_solvent.py +216 -0
  185. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms.py +60 -0
  186. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms_example.py +22 -0
  187. molforge/workflows/assets/OSC_MD_workflows/templates/03-/342/225/244/320/225/342/225/250/342/226/221/342/225/250/320/246/342/225/244/320/227/342/225/250/342/225/226/342/225/250/342/224/220/342/225/244/320/225/342/225/250/320/247/342/225/250/342/226/221/342/225/244/320/224/321/202/320/245/320/254/342/225/250/320/265/analysis_mol.py +244 -0
  188. molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/rms_roughness.py +33 -0
  189. molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/xpm_2.py +117 -0
  190. molforge/workflows/assets/OSC_MD_workflows/templates/09-/342/225/244/320/231/342/225/250/320/240/342/225/250/320/277/342/225/244/320/227/342/225/250/320/256/342/225/250/320/247/marcus_rate.py +60 -0
  191. molforge/workflows/assets/esp-surface-analysis/scripts/compute_descriptors.py +134 -0
  192. molforge/workflows/assets/esp-surface-analysis/scripts/parse_surfanalysis.py +58 -0
  193. molforge/workflows/assets/esp-surface-analysis/scripts/plot_esp_hist.py +115 -0
  194. molforge/workflows/assets/homo-lumo-plot/extract_orb_energy.py +57 -0
  195. molforge/workflows/assets/homo-lumo-plot/make_level_plot.py +76 -0
  196. molforge/workflows/assets/homo-lumo-plot/run_pipeline.py +84 -0
  197. molforge/workflows/assets/osc-energy-level-diagram/scripts/extract_levels.py +60 -0
  198. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_editable_pptx.py +122 -0
  199. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_energy_table.py +66 -0
  200. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_level_lines_diagram.py +148 -0
  201. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_rectangle_diagram.py +148 -0
  202. molforge/workflows/assets/osc-energy-level-diagram/scripts/verify_from_log.py +45 -0
  203. molforge/workflows/dipole_analysis.py +32 -0
  204. molforge/workflows/esp_surface.py +36 -0
  205. molforge/workflows/gromacs_submit.py +167 -0
  206. molforge/workflows/homo_lumo_plot.py +59 -0
  207. molforge/workflows/igmh_interaction.py +111 -0
  208. molforge/workflows/md_rdf_analysis.py +134 -0
  209. molforge/workflows/md_studio.py +255 -0
  210. molforge/workflows/osc_energy_diagram.py +24 -0
  211. molforge/workflows/planarity_analysis.py +66 -0
  212. molforge/workflows/reorganization_energy.py +166 -0
  213. molforge/workflows/scientific_workflows.py +650 -0
  214. molforge_studio-7.4.3.dist-info/METADATA +215 -0
  215. molforge_studio-7.4.3.dist-info/RECORD +219 -0
  216. molforge_studio-7.4.3.dist-info/WHEEL +5 -0
  217. molforge_studio-7.4.3.dist-info/entry_points.txt +3 -0
  218. molforge_studio-7.4.3.dist-info/licenses/LICENSE +93 -0
  219. molforge_studio-7.4.3.dist-info/top_level.txt +2 -0
molforge/ui/theme.py ADDED
@@ -0,0 +1,719 @@
1
+ """
2
+ ui/theme.py - 工业级深色科学工作台视觉主题系统(高对比度激活高亮 + 纵横双向胶囊滚动条)
3
+ ========================================================================================
4
+ 核心升级:
5
+ 1. 彻底解决“点哪个按钮都不亮”的问题:
6
+ - 未选中按钮采用深海蓝灰 (`#142334`,文字 `#9AB0C2`,边框 `#243B52`)
7
+ - 选中/激活按钮 (`:checked` 或 `[active="true"]`) 采用高对比度荧光青翠填充
8
+ (`background-color: #0D9488`, 亮青描边 `2px solid #5EEAD4`, 纯白加粗文字 `#FFFFFF`),
9
+ 亮度对比度提升 400%,点按瞬间高亮发光!
10
+ 2. 新增水平滚动条 (`QScrollBar:horizontal`) 极简 5px 胶囊样式,配合顶栏与画布标头的鼠标滚轮横向滚动。
11
+ 3. 保持所有文本标签、滑块、复选框、滚动视口严格透明,杜绝色块补丁。
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ from pathlib import Path
18
+
19
+
20
+ def _load_design_tokens() -> dict:
21
+ possible_paths = [
22
+ Path(__file__).parent.parent.parent.parent / "docs" / "UI_Design_Kit_v1" / "MolForge_UI_Design_Kit" / "design_tokens.json",
23
+ Path(__file__).parent.parent / "resources" / "design_tokens.json",
24
+ ]
25
+ for p in possible_paths:
26
+ if p.exists():
27
+ try:
28
+ with open(p, "r", encoding="utf-8") as f:
29
+ return json.load(f)
30
+ except Exception:
31
+ pass
32
+ return {}
33
+
34
+
35
+ _TOKENS = _load_design_tokens()
36
+
37
+ C = {
38
+ "bg": "#09111B",
39
+ "shell": "#0C1622",
40
+ "sidebar": "#0F1B29",
41
+ "panel": "#142334",
42
+ "raised": "#17283B",
43
+ "border": "#243B52",
44
+ "text": "#EAF2F6",
45
+ "secondary": "#9AB0C2",
46
+ "muted": "#688094",
47
+ "teal": "#66DEC9",
48
+ "blue": "#7DAEFA",
49
+ "paper": "#F4F3EE",
50
+ "warning": "#E5B567",
51
+ "error": "#F2777A",
52
+ }
53
+
54
+ S = {"xs": 4, "sm": 8, "md": 12, "lg": 16, "xl": 20, "2xl": 24, "3xl": 32}
55
+ R = {"button": 6, "input": 7, "panel": 9, "overlay": 8}
56
+
57
+ THEMES = {
58
+ "Dark Professional": {
59
+ "bg": "#09111B",
60
+ "shell": "#0C1622",
61
+ "sidebar": "#0F1B29",
62
+ "panel": "#142334",
63
+ "card_header": "#182A3E",
64
+ "raised": "#17283B",
65
+ "border": "#243B52",
66
+ "border_subtle": "#1A2C3E",
67
+ "text": "#EAF2F6",
68
+ "secondary": "#9AB0C2",
69
+ "muted": "#688094",
70
+ "teal": "#66DEC9",
71
+ "blue": "#7DAEFA",
72
+ "paper": "#F4F3EE",
73
+ "hover": "#213A54",
74
+ "active_bg": "#0D9488",
75
+ "active_border": "#5EEAD4",
76
+ "active_text": "#FFFFFF",
77
+ "elem_active_bg": "#14B8A6",
78
+ "elem_active_text": "#021815",
79
+ "navcheck": "#0D9488",
80
+ "navborder": "#5EEAD4",
81
+ "inputbg": "#0D1825",
82
+ "inputborder": "#28425A",
83
+ "scroll": "#2D4960",
84
+ "scroll_hover": "#66DEC9",
85
+ "scrollbg": "transparent",
86
+ "splitter": "#192B3C",
87
+ },
88
+ "Light Clean": {
89
+ "bg": "#EEF2F6",
90
+ "shell": "#F7F9FB",
91
+ "sidebar": "#F0F4F8",
92
+ "panel": "#FFFFFF",
93
+ "card_header": "#F3F7FA",
94
+ "raised": "#E8EEF3",
95
+ "border": "#D0DBE5",
96
+ "border_subtle": "#E2E9F0",
97
+ "text": "#1C2B39",
98
+ "secondary": "#526575",
99
+ "muted": "#7F91A0",
100
+ "teal": "#0F9D86",
101
+ "blue": "#2B6CB0",
102
+ "paper": "#FFFFFF",
103
+ "hover": "#DAE5F0",
104
+ "active_bg": "#0D9488",
105
+ "active_border": "#0F766E",
106
+ "active_text": "#FFFFFF",
107
+ "elem_active_bg": "#0D9488",
108
+ "elem_active_text": "#FFFFFF",
109
+ "navcheck": "#0D9488",
110
+ "navborder": "#0F766E",
111
+ "inputbg": "#FFFFFF",
112
+ "inputborder": "#C2D0DC",
113
+ "scroll": "#B8C7D4",
114
+ "scroll_hover": "#0F9D86",
115
+ "scrollbg": "transparent",
116
+ "splitter": "#D5DEE6",
117
+ },
118
+ "High Contrast": {
119
+ "bg": "#000000",
120
+ "shell": "#05080C",
121
+ "sidebar": "#080D14",
122
+ "panel": "#0E1520",
123
+ "card_header": "#141F2E",
124
+ "raised": "#182436",
125
+ "border": "#4A6B8A",
126
+ "border_subtle": "#2C445C",
127
+ "text": "#FFFFFF",
128
+ "secondary": "#E0EAF2",
129
+ "muted": "#A8BAC8",
130
+ "teal": "#00FFCC",
131
+ "blue": "#38B6FF",
132
+ "paper": "#FFFFFF",
133
+ "hover": "#22344A",
134
+ "active_bg": "#00D4AA",
135
+ "active_border": "#FFFFFF",
136
+ "active_text": "#001812",
137
+ "elem_active_bg": "#00FFCC",
138
+ "elem_active_text": "#001812",
139
+ "navcheck": "#00D4AA",
140
+ "navborder": "#FFFFFF",
141
+ "inputbg": "#050A10",
142
+ "inputborder": "#5A7D9E",
143
+ "scroll": "#5A7D9E",
144
+ "scroll_hover": "#00FFCC",
145
+ "scrollbg": "transparent",
146
+ "splitter": "#4A6B8A",
147
+ },
148
+ }
149
+
150
+
151
+ def build_style(theme_name: str = "Dark Professional", accent: str | None = None, font_family: str | None = None, font_size: int | None = None) -> str:
152
+ t = THEMES.get(theme_name, THEMES["Dark Professional"])
153
+ if accent:
154
+ t = dict(t)
155
+ t["teal"] = accent
156
+ t["active_bg"] = accent
157
+ ff = font_family or '"Microsoft YaHei UI", "PingFang SC", "Segoe UI", -apple-system, sans-serif'
158
+ fs = font_size or 14
159
+ fs_xs = max(10, fs - 3)
160
+ fs_sm = max(11, fs - 2)
161
+ fs_md = max(12, fs - 1)
162
+ fs_lg = fs + 1
163
+ fs_xl = fs + 2
164
+ fs_brand = fs + 4
165
+ return f"""
166
+ QMainWindow, QDialog {{
167
+ background-color: {t['shell']};
168
+ color: {t['text']};
169
+ font-family: {ff};
170
+ font-size: {fs}px;
171
+ }}
172
+ QWidget {{
173
+ color: {t['text']};
174
+ font-family: {ff};
175
+ font-size: {fs}px;
176
+ }}
177
+ QWidget#CentralShell, QWidget#WorkspaceContainer {{
178
+ background-color: {t['shell']};
179
+ }}
180
+ QWidget#ScrollPage, QWidget#ToolbarStrip, QScrollArea, QScrollArea > QWidget > QWidget {{
181
+ background-color: transparent;
182
+ border: none;
183
+ }}
184
+ QFrame#ToolbarFrame {{
185
+ background-color: {t['bg']};
186
+ border: 1px solid {t['border']};
187
+ border-radius: 8px;
188
+ }}
189
+ QTableWidget, QTableView, QTreeView, QListView {{
190
+ background-color: {t['panel']}; color: {t['text']};
191
+ alternate-background-color: {t['shell']}; gridline-color: {t['border_subtle']};
192
+ selection-background-color: {t['active_bg']}; selection-color: #FFFFFF;
193
+ border: 1px solid {t['border']};
194
+ border-radius: 6px;
195
+ outline: none;
196
+ font-size: {fs}px;
197
+ font-family: {ff};
198
+ }}
199
+ QTableWidget::item, QTableView::item, QTreeView::item, QListView::item {{
200
+ padding: 6px 8px;
201
+ border: none;
202
+ border-bottom: 1px solid {t['border_subtle']};
203
+ font-size: {fs}px;
204
+ }}
205
+ QTableWidget::item:selected, QTableView::item:selected {{
206
+ background-color: {t['active_bg']};
207
+ color: #FFFFFF;
208
+ font-weight: 600;
209
+ }}
210
+ QTableWidget::item:hover, QTableView::item:hover {{
211
+ background-color: {t['hover']};
212
+ }}
213
+ QHeaderView {{
214
+ background-color: {t['shell']};
215
+ border: none;
216
+ }}
217
+ QHeaderView::section {{
218
+ background-color: {t['raised']};
219
+ color: {t['secondary']};
220
+ font-weight: 700;
221
+ font-size: {fs_sm}px;
222
+ padding: 6px 10px;
223
+ border: none;
224
+ border-bottom: 2px solid {t['border']};
225
+ border-right: 1px solid {t['border_subtle']};
226
+ }}
227
+ QHeaderView::section:hover {{
228
+ background-color: {t['hover']};
229
+ color: {t['teal']};
230
+ }}
231
+ QTableCornerButton::section {{
232
+ background-color: {t['raised']};
233
+ border: none;
234
+ }}
235
+ QLabel, QCheckBox, QRadioButton, QSlider {{
236
+ background-color: transparent;
237
+ border: none;
238
+ font-size: {fs}px;
239
+ font-family: {ff};
240
+ }}
241
+ QMenuBar {{
242
+ background-color: {t['bg']};
243
+ color: {t['secondary']};
244
+ border-bottom: 1px solid {t['border']};
245
+ padding: 3px 10px;
246
+ font-size: {fs}px;
247
+ }}
248
+ QMenuBar::item {{
249
+ padding: 4px 10px;
250
+ border-radius: 5px;
251
+ background: transparent;
252
+ font-size: {fs}px;
253
+ }}
254
+ QMenuBar::item:selected {{
255
+ background-color: {t['hover']};
256
+ color: {t['text']};
257
+ }}
258
+ QMenu {{
259
+ background-color: {t['panel']};
260
+ color: {t['text']};
261
+ border: 1px solid {t['active_border']};
262
+ border-radius: 8px;
263
+ padding: 6px;
264
+ font-size: {fs}px;
265
+ }}
266
+ QMenu::item {{
267
+ padding: 7px 24px 7px 14px;
268
+ border-radius: 5px;
269
+ font-size: {fs}px;
270
+ }}
271
+ QMenu::item:selected {{
272
+ background-color: {t['active_bg']};
273
+ color: {t['active_text']};
274
+ font-weight: 700;
275
+ }}
276
+ QMenu::separator {{
277
+ height: 1px;
278
+ background: {t['border']};
279
+ margin: 4px 6px;
280
+ }}
281
+ QVTKOpenGLNativeWidget, QVTKOpenGLWindow, QOpenGLWidget {{
282
+ background-color: transparent;
283
+ border: none;
284
+ }}
285
+ QFrame#TopBar {{
286
+ background-color: {t['bg']};
287
+ border-bottom: 1px solid {t['border']};
288
+ }}
289
+ QFrame#NavRail {{
290
+ background-color: {t['bg']};
291
+ border-right: 1px solid {t['border']};
292
+ }}
293
+ QFrame#Sidebar, QFrame#LeftPanel {{
294
+ background-color: {t['sidebar']};
295
+ border-right: 1px solid {t['border']};
296
+ font-size: {fs}px;
297
+ font-family: {ff};
298
+ }}
299
+ QFrame#RightPanel {{
300
+ background-color: {t['sidebar']};
301
+ border-left: 1px solid {t['border']};
302
+ font-size: {fs}px;
303
+ font-family: {ff};
304
+ }}
305
+ QFrame#TabStripFrame {{
306
+ background-color: {t['bg']};
307
+ border: 1px solid {t['border']};
308
+ border-radius: 8px;
309
+ }}
310
+ QFrame#CollapsibleCard, QFrame#InfoCard {{
311
+ background-color: {t['panel']};
312
+ border: 1px solid {t['border']};
313
+ border-radius: 8px;
314
+ }}
315
+ QPushButton#CardHeaderBtn {{
316
+ background-color: {t['card_header']};
317
+ border: none;
318
+ border-top-left-radius: 7px;
319
+ border-top-right-radius: 7px;
320
+ border-bottom: 1px solid {t['border_subtle']};
321
+ padding: 7px 11px;
322
+ color: {t['text']};
323
+ font-size: {fs}px;
324
+ font-weight: 700;
325
+ text-align: left;
326
+ font-family: {ff};
327
+ }}
328
+ QPushButton#CardHeaderBtn:hover {{
329
+ background-color: {t['hover']};
330
+ color: {t['teal']};
331
+ }}
332
+ QPushButton#CardHeaderBtn:checked {{
333
+ background-color: {t['card_header']};
334
+ color: {t['teal']};
335
+ border: none;
336
+ border-bottom: 1px solid {t['border_subtle']};
337
+ }}
338
+ QLabel[role="title"] {{
339
+ color: {t['text']};
340
+ font-size: {fs_lg}px;
341
+ font-weight: 700;
342
+ }}
343
+ QLabel[role="section"] {{
344
+ color: {t['muted']};
345
+ font-size: {fs}px;
346
+ font-weight: 700;
347
+ letter-spacing: 0.6px;
348
+ }}
349
+ QLabel[role="muted"] {{
350
+ color: {t['secondary']};
351
+ font-size: {fs_sm}px;
352
+ }}
353
+ QLabel[role="value"] {{
354
+ color: {t['teal']};
355
+ font-size: {fs}px;
356
+ font-weight: 700;
357
+ font-family: "Consolas", "JetBrains Mono", "Segoe UI", monospace;
358
+ }}
359
+ QLabel[role="brand"] {{
360
+ color: {t['text']};
361
+ font-size: {fs_brand}px;
362
+ font-weight: 800;
363
+ letter-spacing: 0.4px;
364
+ }}
365
+ QLabel[role="cardtitle"] {{
366
+ color: {t['text']};
367
+ font-size: {fs}px;
368
+ font-weight: 700;
369
+ }}
370
+ QPushButton {{
371
+ background-color: {t['raised']};
372
+ border: 1px solid {t['border']};
373
+ border-radius: 6px;
374
+ padding: 5px 11px;
375
+ color: {t['secondary']};
376
+ font-size: {fs}px;
377
+ font-weight: 600;
378
+ font-family: {ff};
379
+ }}
380
+ QPushButton:hover:!disabled {{
381
+ background-color: {t['hover']};
382
+ color: {t['text']};
383
+ border: 1px solid {t['teal']};
384
+ }}
385
+ QPushButton:disabled {{
386
+ color: {t['muted']};
387
+ background-color: transparent;
388
+ border: 1px solid transparent;
389
+ }}
390
+ /* 强视觉对比的激活/选中状态:一眼看清当前点亮了哪个工具/模式/视图! */
391
+ QPushButton:checked, QPushButton[active="true"] {{
392
+ background-color: {t['active_bg']};
393
+ color: {t['active_text']};
394
+ border: 2px solid {t['active_border']};
395
+ font-weight: 800;
396
+ }}
397
+ QPushButton[role="nav"] {{
398
+ background-color: transparent;
399
+ border: 1px solid transparent;
400
+ border-radius: 6px;
401
+ text-align: left;
402
+ padding: 6px 10px;
403
+ font-size: {fs}px;
404
+ font-family: {ff};
405
+ }}
406
+ QPushButton[role="nav"]:hover {{
407
+ background-color: {t['hover']};
408
+ color: {t['text']};
409
+ }}
410
+ QPushButton[role="nav"]:checked, QPushButton[role="nav"][active="true"] {{
411
+ background-color: {t['active_bg']};
412
+ color: {t['active_text']};
413
+ border: 1px solid {t['active_border']};
414
+ font-weight: 800;
415
+ }}
416
+ QPushButton[role="tab"] {{
417
+ background-color: transparent;
418
+ border: 1px solid transparent;
419
+ border-radius: 6px;
420
+ text-align: center;
421
+ padding: 5px 6px;
422
+ font-size: {fs}px;
423
+ font-weight: 600;
424
+ font-family: {ff};
425
+ }}
426
+ QPushButton[role="tab"]:hover {{
427
+ color: {t['text']};
428
+ background-color: {t['hover']};
429
+ }}
430
+ QPushButton[role="tab"]:checked, QPushButton[role="tab"][active="true"] {{
431
+ background-color: {t['active_bg']};
432
+ color: {t['active_text']};
433
+ border: 1px solid {t['active_border']};
434
+ font-weight: 800;
435
+ }}
436
+ QPushButton[role="chip"] {{
437
+ background-color: {t['inputbg']};
438
+ border: 1px solid {t['border']};
439
+ border-radius: 6px;
440
+ padding: 5px 8px;
441
+ font-size: {fs_sm}px;
442
+ color: {t['text']};
443
+ text-align: center;
444
+ font-family: {ff};
445
+ }}
446
+ QPushButton[role="chip"]:hover {{
447
+ background-color: {t['hover']};
448
+ color: {t['teal']};
449
+ border: 1px solid {t['teal']};
450
+ }}
451
+ QPushButton[role="chip"]:checked, QPushButton[role="chip"][active="true"] {{
452
+ background-color: {t['active_bg']};
453
+ color: {t['active_text']};
454
+ border: 2px solid {t['active_border']};
455
+ font-weight: 800;
456
+ }}
457
+ QPushButton[role="elem"] {{
458
+ padding: 4px 8px;
459
+ min-width: 30px;
460
+ text-align: center;
461
+ font-weight: 700;
462
+ border-radius: 6px;
463
+ background-color: {t['raised']};
464
+ color: {t['text']};
465
+ border: 1px solid {t['border']};
466
+ font-size: {fs}px;
467
+ }}
468
+ QPushButton[role="elem"]:hover {{
469
+ background-color: {t['hover']};
470
+ border: 1px solid {t['teal']};
471
+ }}
472
+ QPushButton[role="elem"]:checked, QPushButton[role="elem"][active="true"] {{
473
+ background-color: {t['elem_active_bg']};
474
+ color: {t['elem_active_text']};
475
+ border: 2px solid {t['active_border']};
476
+ font-weight: 800;
477
+ }}
478
+ QPushButton[role="action"] {{
479
+ color: #031B17;
480
+ background-color: {t['teal']};
481
+ font-weight: 800;
482
+ text-align: center;
483
+ border: 1px solid {t['active_border']};
484
+ border-radius: 6px;
485
+ padding: 6px 12px;
486
+ font-size: {fs}px;
487
+ }}
488
+ QPushButton[role="action"]:hover:!disabled {{
489
+ background-color: #80F0DC;
490
+ color: #021411;
491
+ }}
492
+ QLineEdit, QPlainTextEdit, QTextEdit, QComboBox, QSpinBox, QDoubleSpinBox {{
493
+ color: {t['text']};
494
+ background-color: {t['inputbg']};
495
+ padding: 5px 9px;
496
+ border-radius: 6px;
497
+ border: 1px solid {t['inputborder']};
498
+ selection-background-color: {t['teal']};
499
+ selection-color: #041F1A;
500
+ font-size: {fs}px;
501
+ font-family: {ff};
502
+ }}
503
+ QLineEdit:focus, QPlainTextEdit:focus, QTextEdit:focus, QComboBox:focus, QSpinBox:focus, QDoubleSpinBox:focus {{
504
+ border: 1px solid {t['teal']};
505
+ }}
506
+ QComboBox::drop-down {{
507
+ border: none;
508
+ width: 20px;
509
+ }}
510
+ QComboBox QAbstractItemView {{
511
+ background-color: {t['panel']};
512
+ color: {t['text']};
513
+ border: 1px solid {t['border']};
514
+ selection-background-color: {t['active_bg']};
515
+ selection-color: {t['active_text']};
516
+ }}
517
+ QSlider::groove:horizontal {{
518
+ height: 12px;
519
+ background: {t['inputbg']};
520
+ border: 1px solid {t['border_subtle']};
521
+ border-radius: 3px;
522
+ }}
523
+ QSlider::sub-page:horizontal {{
524
+ background: {t['teal']};
525
+ border-radius: 3px;
526
+ }}
527
+ QSlider::handle:horizontal {{
528
+ background: {t['text']};
529
+ border: 2px solid {t['teal']};
530
+ width: 12px;
531
+ height: 12px;
532
+ margin: -5px 0;
533
+ border-radius: 7px;
534
+ }}
535
+ QSlider::handle:horizontal:hover {{
536
+ background: {t['teal']};
537
+ }}
538
+ QTabWidget::pane {{
539
+ border: 1px solid {t['border']};
540
+ border-radius: 8px;
541
+ background: {t['panel']};
542
+ }}
543
+ QTabBar::tab {{
544
+ background: {t['sidebar']};
545
+ color: {t['secondary']};
546
+ padding: 7px 14px;
547
+ border: 1px solid {t['border']};
548
+ border-bottom: none;
549
+ border-top-left-radius: 6px;
550
+ border-top-right-radius: 6px;
551
+ margin-right: 3px;
552
+ font-weight: 600;
553
+ }}
554
+ QTabBar::tab:selected {{
555
+ background: {t['active_bg']};
556
+ color: {t['active_text']};
557
+ font-weight: 800;
558
+ }}
559
+ QSplitter::handle {{
560
+ background-color: {t['splitter']};
561
+ }}
562
+ QSplitter::handle:hover {{
563
+ background-color: {t['teal']};
564
+ }}
565
+ QScrollBar:vertical {{
566
+ background: transparent;
567
+ width: 7px;
568
+ margin: 2px 1px 2px 1px;
569
+ }}
570
+ QScrollBar::handle:vertical {{
571
+ background: {t['scroll']};
572
+ border-radius: 3px;
573
+ min-height: 32px;
574
+ }}
575
+ QScrollBar::handle:vertical:hover {{
576
+ background: {t['scroll_hover']};
577
+ }}
578
+ QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical,
579
+ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {{
580
+ height: 0px;
581
+ background: transparent;
582
+ }}
583
+ QScrollBar:horizontal {{
584
+ background: transparent;
585
+ height: 12px;
586
+ margin: 0px 2px 0px 2px;
587
+ }}
588
+ QScrollBar::handle:horizontal {{
589
+ background: {t['scroll']};
590
+ border-radius: 2px;
591
+ min-width: 28px;
592
+ }}
593
+ QScrollBar::handle:horizontal:hover {{
594
+ background: {t['scroll_hover']};
595
+ }}
596
+ QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal,
597
+ QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {{
598
+ width: 0px;
599
+ background: transparent;
600
+ }}
601
+ """
602
+
603
+
604
+ STYLE = build_style("Dark Professional")
605
+
606
+
607
+ def refresh_button_visual(btn, active: bool | None = None) -> None:
608
+ """强制刷新按钮的 checked / active 视觉状态,确保点击后 100% 立即点亮!"""
609
+ if active is not None:
610
+ if btn.isCheckable():
611
+ btn.setChecked(bool(active))
612
+ btn.setProperty("active", "true" if active else "false")
613
+ else:
614
+ btn.setProperty("active", "true" if btn.isChecked() else "false")
615
+ st = btn.style()
616
+ if st is not None:
617
+ st.unpolish(btn)
618
+ st.polish(btn)
619
+ btn.update()
620
+
621
+
622
+ def load_saved_typography() -> tuple[str, int]:
623
+ """读取并验证持久化的全局字体系列与基准字号。"""
624
+ from PyQt6.QtCore import QSettings
625
+ store = QSettings("MolForge", "Typography")
626
+ family = str(store.value("font_family", "Microsoft YaHei UI") or "Microsoft YaHei UI")
627
+ try:
628
+ size = int(store.value("font_size", 14) or 14)
629
+ except Exception:
630
+ size = 14
631
+ size = max(10, min(28, size))
632
+ return family, size
633
+
634
+
635
+ def load_saved_theme() -> tuple[str, str | None]:
636
+ """读取持久化的界面主题与自定义强调色。"""
637
+ from PyQt6.QtCore import QSettings
638
+ store = QSettings("MolForge", "Appearance")
639
+ theme_name = str(store.value("theme_name", "Dark Professional") or "Dark Professional")
640
+ if theme_name not in THEMES:
641
+ theme_name = "Dark Professional"
642
+ accent = store.value("accent", None)
643
+ accent_str = str(accent).strip() if accent else None
644
+ return theme_name, (accent_str or None)
645
+
646
+
647
+ def apply_global_typography(
648
+ family: str,
649
+ size: int,
650
+ theme_name: str | None = None,
651
+ accent: str | None = None,
652
+ ) -> None:
653
+ """将字体与字号应用到 QApplication 全部窗口、左右侧边栏与内联样式控件。"""
654
+ from PyQt6.QtWidgets import QApplication, QWidget, QTableView, QTreeView
655
+ from PyQt6.QtGui import QFont
656
+
657
+ saved_theme, saved_accent = load_saved_theme()
658
+ use_theme = theme_name or saved_theme
659
+ use_accent = accent if accent is not None else saved_accent
660
+
661
+ app = QApplication.instance()
662
+ if app is None:
663
+ return
664
+ sz = max(10, min(28, int(size)))
665
+ font = QFont(family)
666
+ font.setPixelSize(sz)
667
+ font.setStyleStrategy(QFont.StyleStrategy.PreferAntialias)
668
+ app.setFont(font)
669
+
670
+ new_css = build_style(use_theme, use_accent, font_family=family, font_size=sz)
671
+ app.setStyleSheet(new_css)
672
+
673
+ for top_widget in app.topLevelWidgets():
674
+ top_widget.setFont(font)
675
+ for child in top_widget.findChildren(QWidget):
676
+ child.setFont(font)
677
+ if isinstance(child, (QTableView, QTreeView)):
678
+ child.verticalHeader().setDefaultSectionSize(sz + 18)
679
+ if hasattr(child, "apply_typography"):
680
+ try:
681
+ child.apply_typography(family, sz)
682
+ except Exception:
683
+ pass
684
+ if hasattr(top_widget, "apply_typography"):
685
+ try:
686
+ top_widget.apply_typography(family, sz)
687
+ except Exception:
688
+ pass
689
+ st = top_widget.style()
690
+ if st is not None:
691
+ st.unpolish(top_widget)
692
+ st.polish(top_widget)
693
+ top_widget.update()
694
+ app.processEvents()
695
+
696
+
697
+ def apply_theme(window, theme_name: str, accent: str | None = None):
698
+ from PyQt6.QtCore import QSettings
699
+ from PyQt6.QtWidgets import QApplication
700
+ store = QSettings("MolForge", "Appearance")
701
+ store.setValue("theme_name", theme_name)
702
+ if accent is not None:
703
+ store.setValue("accent", accent)
704
+ elif store.value("accent", None):
705
+ store.remove("accent")
706
+
707
+ family, size = load_saved_typography()
708
+ full = build_style(theme_name, accent, font_family=family, font_size=size)
709
+ app = QApplication.instance()
710
+ if app is not None:
711
+ app.setStyleSheet(full)
712
+ app.processEvents()
713
+ vtk_widget = window.workspace.view3d_real
714
+ if getattr(vtk_widget, "plotter", None) is not None and hasattr(vtk_widget.plotter, "set_background"):
715
+ if theme_name == "Light Clean":
716
+ vtk_widget.plotter.set_background(color=[0.88, 0.91, 0.95], top=[0.96, 0.98, 1.0])
717
+ else:
718
+ vtk_widget.plotter.set_background(color=[0.067, 0.114, 0.173], top=[0.145, 0.227, 0.314])
719
+ vtk_widget.set_document(window.document)