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 (C) 2023 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{
33 wxFont helpFont = KIUI::GetInfoFont( this ).Italic();
34 m_stPythonStatus->SetFont( helpFont );
35 m_stApiStatus->SetFont( helpFont );
36}
37
38
40{
41}
42
43
45{
47 COMMON_SETTINGS* settings = mgr.GetCommonSettings();
48
49 m_cbEnableApi->SetValue( settings->m_Api.enable_server );
50 m_pickerPythonInterpreter->SetFileName( settings->m_Api.python_interpreter );
53
54 return true;
55}
56
57
59{
61 COMMON_SETTINGS* settings = mgr.GetCommonSettings();
62 wxString interpreter = m_pickerPythonInterpreter->GetTextCtrlValue();
63
64 if( m_pythonInterpreterValid || interpreter.IsEmpty() )
65 settings->m_Api.python_interpreter = interpreter;
66
67 settings->m_Api.enable_server = m_cbEnableApi->GetValue();
68
69 return true;
70}
71
72
73void PANEL_PLUGIN_SETTINGS::OnPythonInterpreterChanged( wxFileDirPickerEvent& event )
74{
76}
77
78
80{
81 wxString interpreter = PYTHON_MANAGER::FindPythonInterpreter();
82
83 if( !interpreter.IsEmpty() )
84 {
85 m_pickerPythonInterpreter->SetPath( interpreter );
87 }
88}
89
90
91void PANEL_PLUGIN_SETTINGS::OnEnableApiChecked( wxCommandEvent& aEvent )
92{
95}
96
97
99{
100#ifdef KICAD_IPC_API
101 if( m_cbEnableApi->GetValue() && Pgm().GetApiServer().Running() )
102 {
103 m_stApiStatus->SetLabel( wxString::Format( _( "Listening at %s" ),
104 Pgm().GetApiServer().SocketPath() ) );
105 }
106 else
107 {
108 m_stApiStatus->SetLabel( wxEmptyString );
109 }
110#else
111 m_stApiStatus->SetLabel( _( "This installation of KiCad does not have API support enabled." ) );
112#endif
113}
114
115
117{
118 if( !m_cbEnableApi->GetValue() )
119 {
120 m_stPythonStatus->SetLabel( _( "KiCad API is not enabled; external Python plugins will "
121 "not be available" ) );
122 return;
123 }
124
126
127 wxFileName pythonExe( m_pickerPythonInterpreter->GetTextCtrlValue() );
128
129 if( !pythonExe.FileExists() )
130 {
131 m_stPythonStatus->SetLabel( _( "No valid Python interpreter chosen; external Python "
132 "plugins will not be available" ) );
133 return;
134 }
135
136 PYTHON_MANAGER manager( pythonExe.GetFullPath() );
137
138 manager.Execute( wxS( "--version" ),
139 [&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
140 {
141 wxString msg;
142
143 if( aRetCode == 0 && aStdOut.Contains( wxS( "Python 3" ) ) )
144 {
145 msg = wxString::Format( _( "Found %s" ), aStdOut );
147 }
148 else
149 {
150 msg = _( "Not a valid Python 3 interpreter" );
151 }
152
153 m_stPythonStatus->SetLabel( msg );
154 } );
155}
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:142
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.