KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_plugin_settings.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <api/api_server.h>
24#include <widgets/ui_common.h>
25#include <pgm_base.h>
26#include <api/python_manager.h>
29
30
34{
35 wxFont helpFont = KIUI::GetInfoFont( this ).Italic();
36 m_stPythonStatus->SetFont( helpFont );
37 m_stApiStatus->SetFont( helpFont );
38}
39
40
44
45
58
59
61{
63 COMMON_SETTINGS* settings = mgr.GetCommonSettings();
64 wxString interpreter = m_pickerPythonInterpreter->GetTextCtrlValue();
65
66 if( m_pythonInterpreterValid || interpreter.IsEmpty() )
67 {
68 bool interpreterChanged = !interpreter.IsEmpty()
69 && interpreter != settings->m_Api.python_interpreter;
70
71 settings->m_Api.python_interpreter = interpreter;
72
73 if( interpreterChanged )
75 }
76
77 settings->m_Api.enable_server = m_cbEnableApi->GetValue();
78
79 return true;
80}
81
82
83void PANEL_PLUGIN_SETTINGS::OnPythonInterpreterChanged( wxFileDirPickerEvent& event )
84{
86}
87
88
90{
91 wxString interpreter = PYTHON_MANAGER::FindPythonInterpreter();
92
93 if( !interpreter.IsEmpty() )
94 {
95 m_pickerPythonInterpreter->SetPath( interpreter );
97 }
98}
99
100
106
107
109{
110 if( m_cbEnableApi->GetValue() && Pgm().GetApiServer().Running() )
111 {
112 m_stApiStatus->SetLabel( wxString::Format( _( "Listening at %s" ),
113 Pgm().GetApiServer().SocketPath() ) );
114 }
115 else
116 {
117 m_stApiStatus->SetLabel( wxEmptyString );
118 }
119}
120
121
123{
124 if( !m_cbEnableApi->GetValue() )
125 {
126 m_stPythonStatus->SetLabel( _( "KiCad API is not enabled; external Python plugins will "
127 "not be available" ) );
128 return;
129 }
130
132
133 wxFileName pythonExe( m_pickerPythonInterpreter->GetTextCtrlValue() );
134
135 if( !pythonExe.FileExists() )
136 {
137 m_stPythonStatus->SetLabel( _( "No valid Python interpreter chosen; external Python "
138 "plugins will not be available" ) );
139 return;
140 }
141
142 PYTHON_MANAGER manager( pythonExe.GetFullPath() );
143
144 manager.Execute( { wxS( "--version" ) },
145 [&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
146 {
147 wxString msg;
148
149 if( aRetCode == 0 && aStdOut.Contains( wxS( "Python 3" ) ) )
150 {
151 msg = wxString::Format( _( "Found %s" ), aStdOut );
153 }
154 else
155 {
156 msg = _( "Not a valid Python 3 interpreter" );
157 }
158
159 m_stPythonStatus->SetLabel( msg );
160 Layout();
161 },
162 /* aEnv = */ nullptr,
163 /* aSaveOutput = */ true );
164}
PANEL_PLUGIN_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnPythonInterpreterChanged(wxFileDirPickerEvent &event) override
void ResetPanel() override
Reset the contents of this panel.
PANEL_PLUGIN_SETTINGS(wxWindow *aParent)
void OnEnableApiChecked(wxCommandEvent &aEvent) override
void OnBtnDetectAutomaticallyClicked(wxCommandEvent &aEvent) override
bool TransferDataFromWindow() override
virtual API_PLUGIN_MANAGER & GetPluginManager() const
Definition pgm_base.h:139
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
static wxString FindPythonInterpreter()
Searches for a Python intepreter on the user's system.
long Execute(const std::vector< wxString > &aArgs, const std::function< void(int, const wxString &, const wxString &)> &aCallback, const wxExecuteEnv *aEnv=nullptr, bool aSaveOutput=false)
Launches the Python interpreter with the given arguments.
COMMON_SETTINGS * GetCommonSettings() const
Retrieve the common settings shared by all applications.
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.