-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.py
More file actions
207 lines (166 loc) · 7.04 KB
/
help.py
File metadata and controls
207 lines (166 loc) · 7.04 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"""
KiRender Help Module
====================
Help tab UI with dropdown menu style.
"""
import os
import sys
import platform
import subprocess
import datetime
import webbrowser
import wx
import pcbnew
# URLs
HELP_URL = "https://pcbtools.xyz/tools/kirender"
GET_INVOLVED_URL = "https://github.com/way2pramil/KiRender"
DONATE_URL = "https://pcbtools.xyz/tools/kirender#sponsor"
REPORT_BUG_URL = "https://github.com/way2pramil/KiRender/issues"
def create_help_tab(parent, plugin_version, kicad_cli, ffmpeg_path, pcb_path, project_dir, config_file):
"""Create the Help tab with a dropdown menu button."""
panel = wx.Panel(parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
# Store data for menu callbacks
panel._plugin_version = plugin_version
panel._kicad_cli = kicad_cli
panel._ffmpeg_path = ffmpeg_path
panel._pcb_path = pcb_path
panel._project_dir = project_dir
panel._config_file = config_file
# Help menu button
help_btn = wx.Button(panel, label="Help2", size=(100, 30))
help_btn.Bind(wx.EVT_BUTTON, lambda e: show_help_menu(panel, help_btn))
main_sizer.Add(help_btn, 0, wx.ALL, 10)
# main_sizer.AddStretchSpacer()
panel.SetSizer(main_sizer)
return panel
def show_help_menu(panel, button):
"""Show the help dropdown menu."""
menu = wx.Menu()
# Menu items
help_item = menu.Append(wx.ID_ANY, "Help")
menu.AppendSeparator()
involve_item = menu.Append(wx.ID_ANY, "Get Involved")
donate_item = menu.Append(wx.ID_ANY, "Donate")
bug_item = menu.Append(wx.ID_ANY, "Report Bug")
menu.AppendSeparator()
debug_item = menu.Append(wx.ID_ANY, "Debug Info")
menu.AppendSeparator()
about_item = menu.Append(wx.ID_ANY, "About KiRender")
# Bind events
panel.Bind(wx.EVT_MENU, lambda e: webbrowser.open(HELP_URL), help_item)
panel.Bind(wx.EVT_MENU, lambda e: webbrowser.open(GET_INVOLVED_URL), involve_item)
panel.Bind(wx.EVT_MENU, lambda e: webbrowser.open(DONATE_URL), donate_item)
panel.Bind(wx.EVT_MENU, lambda e: webbrowser.open(REPORT_BUG_URL), bug_item)
panel.Bind(wx.EVT_MENU, lambda e: show_debug_dialog(panel), debug_item)
panel.Bind(wx.EVT_MENU, lambda e: show_about_dialog(panel), about_item)
# Show menu below the button
btn_pos = button.GetPosition()
btn_size = button.GetSize()
panel.PopupMenu(menu, (btn_pos.x, btn_pos.y + btn_size.height))
menu.Destroy()
def show_debug_dialog(panel):
"""Show debug info in a dialog."""
debug_info = get_debug_info(panel._plugin_version, panel._kicad_cli,
panel._ffmpeg_path, panel._pcb_path,
panel._project_dir, panel._config_file)
dlg = wx.Dialog(panel, title="Debug Information", size=(500, 350),
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
sizer = wx.BoxSizer(wx.VERTICAL)
info_text = wx.StaticText(dlg, label="Copy and share this info when reporting issues:")
sizer.Add(info_text, 0, wx.ALL, 10)
text_ctrl = wx.TextCtrl(dlg, value=debug_info,
style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
text_ctrl.SetFont(wx.Font(9, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
sizer.Add(text_ctrl, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
copy_btn = wx.Button(dlg, label="Copy to Clipboard")
copy_btn.Bind(wx.EVT_BUTTON, lambda e: copy_to_clipboard(debug_info))
close_btn = wx.Button(dlg, wx.ID_CLOSE, "Close")
close_btn.Bind(wx.EVT_BUTTON, lambda e: dlg.EndModal(wx.ID_OK))
btn_sizer.Add(copy_btn, 0, wx.ALL, 5)
btn_sizer.AddStretchSpacer()
btn_sizer.Add(close_btn, 0, wx.ALL, 5)
sizer.Add(btn_sizer, 0, wx.EXPAND | wx.ALL, 5)
dlg.SetSizer(sizer)
dlg.Centre()
dlg.ShowModal()
dlg.Destroy()
def get_debug_info(plugin_version, kicad_cli, ffmpeg_path, pcb_path, project_dir, config_file):
"""Generate debug information string."""
# Get KiCad version
try:
kicad_version = pcbnew.Version()
except:
kicad_version = "Unknown"
# Check if kicad-cli exists
cli_exists = os.path.exists(kicad_cli) if kicad_cli else False
# Check if ffmpeg exists
ffmpeg_exists = False
ffmpeg_version = "Not found"
try:
startupinfo = None
creationflags = 0
if sys.platform == "win32":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
creationflags = subprocess.CREATE_NO_WINDOW
result = subprocess.run(
[ffmpeg_path, "-version"],
capture_output=True,
text=True,
startupinfo=startupinfo,
creationflags=creationflags
)
if result.returncode == 0:
ffmpeg_exists = True
ffmpeg_version = result.stdout.split('\n')[0]
except Exception as e:
ffmpeg_version = f"Error: {str(e)}"
debug_info = f"""=== KiRender Debug Info ===
Version: {plugin_version}
Date: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
OS: {platform.system()} {platform.release()} ({platform.machine()})
Python: {sys.version.split()[0]}
KiCad: {kicad_version}
PCB: {pcb_path}
kicad-cli: {kicad_cli} [{'OK' if cli_exists else 'NOT FOUND'}]
FFmpeg: {ffmpeg_path} [{'OK' if ffmpeg_exists else 'NOT FOUND'}]
FFmpeg Ver: {ffmpeg_version}
Config: {config_file}
"""
return debug_info
def copy_to_clipboard(text):
"""Copy text to clipboard."""
if wx.TheClipboard.Open():
wx.TheClipboard.SetData(wx.TextDataObject(text))
wx.TheClipboard.Close()
wx.MessageBox("Debug info copied to clipboard!", "Copied", wx.OK | wx.ICON_INFORMATION)
def show_about_dialog(panel):
"""Show the About dialog."""
plugin_version = panel._plugin_version
about_text = f"""KiRender v{plugin_version}
Bringing your PCB designs to life! ✨
Create beautiful 3D spinning animations, high-quality
renders, and SVG exports of your PCB designs directly
from KiCad - no command line needed.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
REQUIREMENTS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• KiCad 9.0 or later
• FFmpeg (for videos/GIFs)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CREDITS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• arturo182 - Original kicad_mp4.sh
• linalinn - kicad-render GitHub Action
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LINKS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Website: pcbtools.xyz/tools/kirender
GitHub: github.com/way2pramil/KiRender
Made with 💚 for the KiCad community
"""
dlg = wx.MessageDialog(panel, about_text, "About KiRender", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()