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 along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <api/api_server.h>
23#include <widgets/ui_common.h>
24#include <pgm_base.h>
25#include <python_manager.h>
28
29
32 m_pythonInterpreterValid( false )
33{
34 wxFont helpFont = KIUI::GetInfoFont( this ).Italic();
35 m_stPythonStatus->SetFont( helpFont );
36 m_stApiStatus->SetFont( helpFont );
37}
38
39
41{
42}
43
44
46{
48 COMMON_SETTINGS* settings = mgr.GetCommonSettings();
49
50 m_cbEnableApi->SetValue( settings->m_Api.enable_server );
51 m_pickerPythonInterpreter->SetFileName( settings->m_Api.python_interpreter );
54
55 return true;
56}
57
58
60{
62 COMMON_SETTINGS* settings = mgr.GetCommonSettings();
63 wxString interpreter = m_pickerPythonInterpreter->GetTextCtrlValue();
64
65 if( m_pythonInterpreterValid || interpreter.IsEmpty() )
66 settings->m_Api.python_interpreter = interpreter;
67
68 settings->m_Api.enable_server = m_cbEnableApi->GetValue();
69
70 return true;
71}
72
73
74void PANEL_PLUGIN_SETTINGS::OnPythonInterpreterChanged( wxFileDirPickerEvent& event )
75{
77}
78
79
81{
82 wxString interpreter = PYTHON_MANAGER::FindPythonInterpreter();
83
84 if( !interpreter.IsEmpty() )
85 {
86 m_pickerPythonInterpreter->SetPath( interpreter );
88 }
89}
90
91
92void PANEL_PLUGIN_SETTINGS::OnEnableApiChecked( wxCommandEvent& aEvent )
93{
96}
97
98
100{
101#ifdef KICAD_IPC_API
102 if( m_cbEnableApi->GetValue() && Pgm().GetApiServer().Running() )
103 {
104 m_stApiStatus->SetLabel( wxString::Format( _( "Listening at %s" ),
105 Pgm().GetApiServer().SocketPath() ) );
106 }
107 else
108 {
109 m_stApiStatus->SetLabel( wxEmptyString );
110 }
111#else
112 m_stApiStatus->SetLabel( _( "This installation of KiCad does not have API support enabled." ) );
113#endif
114}
115
116
118{
119 if( !m_cbEnableApi->GetValue() )
120 {
121 m_stPythonStatus->SetLabel( _( "KiCad API is not enabled; external Python plugins will "
122 "not be available" ) );
123 return;
124 }
125
127
128 wxFileName pythonExe( m_pickerPythonInterpreter->GetTextCtrlValue() );
129
130 if( !pythonExe.FileExists() )
131 {
132 m_stPythonStatus->SetLabel( _( "No valid Python interpreter chosen; external Python "
133 "plugins will not be available" ) );
134 return;
135 }
136
137 PYTHON_MANAGER manager( pythonExe.GetFullPath() );
138
139 manager.Execute( wxS( "--version" ),
140 [&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
141 {
142 wxString msg;
143
144 if( aRetCode == 0 && aStdOut.Contains( wxS( "Python 3" ) ) )
145 {
146 msg = wxString::Format( _( "Found %s" ), aStdOut );
148 }
149 else
150 {
151 msg = _( "Not a valid Python 3 interpreter" );
152 }
153
154 m_stPythonStatus->SetLabel( msg );
155 Layout();
156 },
157 /* aEnv = */ nullptr,
158 /* aSaveOutput = */ true );
159}
Class PANEL_PLUGIN_SETTINGS_BASE.
wxFilePickerCtrl * m_pickerPythonInterpreter
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
bool TransferDataToWindow() override
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
COMMON_SETTINGS * GetCommonSettings() const
Retrieve the common settings shared by all applications.
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:155
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.