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,6 +454,20 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
if( GetBitmapStore()->ThemeChanged() )
{
ThemeChanged();
}
if( GetMenuBar() )
{
// For icons in menus, icon scaling & hotkeys
ReCreateMenuBar();
GetMenuBar()->Refresh();
}
}
void EDA_BASE_FRAME::ThemeChanged()
{
ClearScaledBitmapCache();
wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
@ -463,14 +477,6 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
toolbar->RefreshBitmaps();
}
}
if( GetMenuBar() )
{
// For icons in menus, icon scaling & hotkeys
ReCreateMenuBar();
GetMenuBar()->Refresh();
}
}

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,7 +679,10 @@ class ActionPlugin(KiCadPlugin, object):
def GetShowToolbarButton( self ):
return self.show_toolbar_button
def GetIconFileName( self ):
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):