Add support for dark theme in plugin icons
Action plugin authors can specify alternative icon path for dark theme. If it's not specified then standard icon will be used for both light and dark themes. If neither icon is specified then the default puzzle piece icon is used. Fixes #7984
This commit is contained in:
parent
7e8bd2e561
commit
75819206a0
|
@ -454,15 +454,7 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
|
||||||
|
|
||||||
if( GetBitmapStore()->ThemeChanged() )
|
if( GetBitmapStore()->ThemeChanged() )
|
||||||
{
|
{
|
||||||
ClearScaledBitmapCache();
|
ThemeChanged();
|
||||||
|
|
||||||
wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
|
|
||||||
|
|
||||||
for( size_t i = 0; i < panes.GetCount(); ++i )
|
|
||||||
{
|
|
||||||
if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
|
|
||||||
toolbar->RefreshBitmaps();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( GetMenuBar() )
|
if( GetMenuBar() )
|
||||||
|
@ -474,6 +466,20 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EDA_BASE_FRAME::ThemeChanged()
|
||||||
|
{
|
||||||
|
ClearScaledBitmapCache();
|
||||||
|
|
||||||
|
wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
|
||||||
|
|
||||||
|
for( size_t i = 0; i < panes.GetCount(); ++i )
|
||||||
|
{
|
||||||
|
if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
|
||||||
|
toolbar->RefreshBitmaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
|
void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
|
||||||
{
|
{
|
||||||
if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
|
if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
|
||||||
|
|
|
@ -480,6 +480,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process light/dark theme change.
|
||||||
|
*/
|
||||||
|
virtual void ThemeChanged();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification event that the project has changed.
|
* Notification event that the project has changed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "action_plugin.h"
|
#include "action_plugin.h"
|
||||||
|
#include "bitmaps.h"
|
||||||
|
#include "bitmap_store.h"
|
||||||
|
|
||||||
|
|
||||||
ACTION_PLUGIN::~ACTION_PLUGIN()
|
ACTION_PLUGIN::~ACTION_PLUGIN()
|
||||||
|
@ -156,16 +158,17 @@ void ACTION_PLUGINS::register_action( ACTION_PLUGIN* aAction )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load icon if supplied
|
// Load icon if supplied
|
||||||
if( !aAction->GetIconFileName().IsEmpty() )
|
wxString icon_file_name = aAction->GetIconFileName( GetBitmapStore()->IsDarkTheme() );
|
||||||
|
if( !icon_file_name.IsEmpty() )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
wxLogNull eat_errors;
|
wxLogNull eat_errors;
|
||||||
aAction->iconBitmap.LoadFile( aAction->GetIconFileName() , wxBITMAP_TYPE_PNG );
|
aAction->iconBitmap.LoadFile( icon_file_name, wxBITMAP_TYPE_PNG );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !aAction->iconBitmap.IsOk() )
|
if ( !aAction->iconBitmap.IsOk() )
|
||||||
{
|
{
|
||||||
wxLogVerbose( "Failed to load icon " + aAction->GetIconFileName() + " for action plugin " );
|
wxLogVerbose( "Failed to load icon " + icon_file_name + " for action plugin " );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,10 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetIconFileName
|
* Function GetIconFileName
|
||||||
|
* @param dark true if requesting dark theme icon
|
||||||
* @return a path to icon for the action plugin button
|
* @return a path to icon for the action plugin button
|
||||||
*/
|
*/
|
||||||
virtual wxString GetIconFileName() = 0;
|
virtual wxString GetIconFileName( bool dark ) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetPluginPath
|
* Function GetPluginPath
|
||||||
|
|
|
@ -1688,6 +1688,14 @@ void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PCB_EDIT_FRAME::ThemeChanged()
|
||||||
|
{
|
||||||
|
PCB_BASE_EDIT_FRAME::ThemeChanged();
|
||||||
|
|
||||||
|
PythonPluginsReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PCB_EDIT_FRAME::ProjectChanged()
|
void PCB_EDIT_FRAME::ProjectChanged()
|
||||||
{
|
{
|
||||||
PythonSyncProjectName();
|
PythonSyncProjectName();
|
||||||
|
|
|
@ -824,6 +824,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when light/dark theme is changed.
|
||||||
|
*/
|
||||||
|
void ThemeChanged() override;
|
||||||
|
|
||||||
void ProjectChanged() override;
|
void ProjectChanged() override;
|
||||||
|
|
||||||
wxString GetCurrentFileName() const override;
|
wxString GetCurrentFileName() const override;
|
||||||
|
|
|
@ -138,11 +138,17 @@ bool PYTHON_ACTION_PLUGIN::GetShowToolbarButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString PYTHON_ACTION_PLUGIN::GetIconFileName()
|
wxString PYTHON_ACTION_PLUGIN::GetIconFileName( bool dark )
|
||||||
{
|
{
|
||||||
PyLOCK lock;
|
PyLOCK lock;
|
||||||
|
|
||||||
return CallRetStrMethod( "GetIconFileName" );
|
PyObject* arglist = Py_BuildValue( "(i)", (int) dark );
|
||||||
|
|
||||||
|
wxString result = CallRetStrMethod( "GetIconFileName", arglist );
|
||||||
|
|
||||||
|
Py_DECREF( arglist );
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
wxString GetName() override;
|
wxString GetName() override;
|
||||||
wxString GetDescription() override;
|
wxString GetDescription() override;
|
||||||
bool GetShowToolbarButton() override;
|
bool GetShowToolbarButton() override;
|
||||||
wxString GetIconFileName() override;
|
wxString GetIconFileName( bool dark ) override;
|
||||||
wxString GetPluginPath() override;
|
wxString GetPluginPath() override;
|
||||||
void Run() override;
|
void Run() override;
|
||||||
void* GetObject() override;
|
void* GetObject() override;
|
||||||
|
|
|
@ -658,6 +658,7 @@ class ActionPlugin(KiCadPlugin, object):
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
KiCadPlugin.__init__( self )
|
KiCadPlugin.__init__( self )
|
||||||
self.icon_file_name = ""
|
self.icon_file_name = ""
|
||||||
|
self.dark_icon_file_name = ""
|
||||||
self.show_toolbar_button = False
|
self.show_toolbar_button = False
|
||||||
self.defaults()
|
self.defaults()
|
||||||
|
|
||||||
|
@ -678,8 +679,11 @@ class ActionPlugin(KiCadPlugin, object):
|
||||||
def GetShowToolbarButton( self ):
|
def GetShowToolbarButton( self ):
|
||||||
return self.show_toolbar_button
|
return self.show_toolbar_button
|
||||||
|
|
||||||
def GetIconFileName( self ):
|
def GetIconFileName( self, dark ):
|
||||||
return self.icon_file_name
|
if dark and self.dark_icon_file_name:
|
||||||
|
return self.dark_icon_file_name
|
||||||
|
else:
|
||||||
|
return self.icon_file_name
|
||||||
|
|
||||||
def Run(self):
|
def Run(self):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue