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:
qu1ck 2021-03-21 21:50:42 -07:00 committed by Jon Evans
parent 7e8bd2e561
commit 75819206a0
9 changed files with 56 additions and 18 deletions

View File

@ -454,15 +454,7 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
if( GetBitmapStore()->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();
}
ThemeChanged();
}
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 )
{
if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )

View File

@ -480,6 +480,11 @@ public:
*/
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
/**
* Process light/dark theme change.
*/
virtual void ThemeChanged();
/**
* Notification event that the project has changed.
*/

View File

@ -28,6 +28,8 @@
*/
#include "action_plugin.h"
#include "bitmaps.h"
#include "bitmap_store.h"
ACTION_PLUGIN::~ACTION_PLUGIN()
@ -156,16 +158,17 @@ void ACTION_PLUGINS::register_action( ACTION_PLUGIN* aAction )
}
// Load icon if supplied
if( !aAction->GetIconFileName().IsEmpty() )
wxString icon_file_name = aAction->GetIconFileName( GetBitmapStore()->IsDarkTheme() );
if( !icon_file_name.IsEmpty() )
{
{
wxLogNull eat_errors;
aAction->iconBitmap.LoadFile( aAction->GetIconFileName() , wxBITMAP_TYPE_PNG );
aAction->iconBitmap.LoadFile( icon_file_name, wxBITMAP_TYPE_PNG );
}
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 " );
}
}

View File

@ -83,9 +83,10 @@ public:
/**
* Function GetIconFileName
* @param dark true if requesting dark theme icon
* @return a path to icon for the action plugin button
*/
virtual wxString GetIconFileName() = 0;
virtual wxString GetIconFileName( bool dark ) = 0;
/**
* Function GetPluginPath

View File

@ -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()
{
PythonSyncProjectName();

View File

@ -824,6 +824,11 @@ public:
*/
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
/**
* Called when light/dark theme is changed.
*/
void ThemeChanged() override;
void ProjectChanged() override;
wxString GetCurrentFileName() const override;

View File

@ -138,11 +138,17 @@ bool PYTHON_ACTION_PLUGIN::GetShowToolbarButton()
}
wxString PYTHON_ACTION_PLUGIN::GetIconFileName()
wxString PYTHON_ACTION_PLUGIN::GetIconFileName( bool dark )
{
PyLOCK lock;
return CallRetStrMethod( "GetIconFileName" );
PyObject* arglist = Py_BuildValue( "(i)", (int) dark );
wxString result = CallRetStrMethod( "GetIconFileName", arglist );
Py_DECREF( arglist );
return result;
}

View File

@ -52,7 +52,7 @@ public:
wxString GetName() override;
wxString GetDescription() override;
bool GetShowToolbarButton() override;
wxString GetIconFileName() override;
wxString GetIconFileName( bool dark ) override;
wxString GetPluginPath() override;
void Run() override;
void* GetObject() override;

View File

@ -658,6 +658,7 @@ class ActionPlugin(KiCadPlugin, object):
def __init__( self ):
KiCadPlugin.__init__( self )
self.icon_file_name = ""
self.dark_icon_file_name = ""
self.show_toolbar_button = False
self.defaults()
@ -678,8 +679,11 @@ class ActionPlugin(KiCadPlugin, object):
def GetShowToolbarButton( self ):
return self.show_toolbar_button
def GetIconFileName( self ):
return self.icon_file_name
def GetIconFileName( self, dark ):
if dark and self.dark_icon_file_name:
return self.dark_icon_file_name
else:
return self.icon_file_name
def Run(self):
return