Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion addon/globalPlugins/MathCAT/MathCATPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from logHandler import log # logging
from collections.abc import Callable
from .MathCAT import convertSSMLTextForNVDA
from ._libmathcat_loader import libmathcat
from speech import speak
from zipfile import ZipFile

Expand Down Expand Up @@ -59,10 +60,43 @@ def __init__(self, parent: wx.Window | None):
# initialize parent class
MathCATgui.MathCATPreferencesDialog.__init__(self, parent)

# show the MathCAT rules engine version below the logo
try:
# Translators: shows the version of the MathCAT rules engine, e.g. "Version 0.5.14"
self._staticTextVersion.SetLabel(_("Version {version}").format(version=libmathcat.GetVersion()))
except Exception as e:
log.exception(f"MathCAT: An exception occurred getting the MathCAT version: {e}")

# load the logo into the dialog
fullPathToLogo: str = os.path.join(os.path.dirname(os.path.abspath(__file__)), "logo.png")
if os.path.exists(fullPathToLogo):
self._bitmapLogo.SetBitmap(wx.Bitmap(fullPathToLogo))
logoImage: wx.Image = wx.Image(fullPathToLogo, wx.BITMAP_TYPE_PNG)
# 200 DIP; the source image is 300x300 so it stays sharp on hi-DPI displays
targetLogoSize: int = 200
# BitmapBundle pins the logical size from the smallest bitmap and paints the
# full-resolution one on hi-DPI displays
baselineBitmap: wx.Bitmap = wx.Bitmap(logoImage.Scale(targetLogoSize, targetLogoSize, wx.IMAGE_QUALITY_HIGH))
nativeBitmap: wx.Bitmap = wx.Bitmap(logoImage)
self._logoBitmapBundle: wx.BitmapBundle = wx.BitmapBundle.FromBitmaps([baselineBitmap, nativeBitmap])

# wx.StaticBitmap on Windows paints an opaque background through the PNG alpha.
# Replace it with a panel we paint ourselves so transparency (and the dark-mode pill) work.
logoPanel: wx.Panel = wx.Panel(
self._panelCategories,
wx.ID_ANY,
size=wx.Size(targetLogoSize, targetLogoSize),
)
logoPanel.SetBackgroundColour(self._panelCategories.GetBackgroundColour())
logoPanel.Bind(wx.EVT_PAINT, self.onPaintLogo)
self._bitmapLogo.GetContainingSizer().Replace(self._bitmapLogo, logoPanel)
self._bitmapLogo.Destroy()
self._bitmapLogo = logoPanel

# The dialog was already fitted around a null placeholder; refit now that the logo size is known.
self._panelCategories.Layout()
self.Layout()
self.GetSizer().Fit(self)
self.Centre(wx.BOTH)

# load in the system values followed by the user prefs (if any)
UserInterface.loadDefaultPreferences()
Expand Down Expand Up @@ -90,6 +124,34 @@ def __init__(self, parent: wx.Window | None):
# set the ui items to match the preferences
UserInterface.setUIValues(self)

def onPaintLogo(self, event: wx.PaintEvent) -> None:
"""Paint the MathCAT logo onto its panel, with a light pill behind it on dark backgrounds.

The logo's black text/outline is invisible against a dark dialog background, so a light pill
is drawn behind it for contrast. On light backgrounds the pill is skipped.
"""
dc: wx.PaintDC = wx.PaintDC(self._bitmapLogo)
graphicsContext: wx.GraphicsContext | None = wx.GraphicsContext.Create(dc)
if graphicsContext is None:
return
panelSize: wx.Size = self._bitmapLogo.GetClientSize()
# IsDark() can report dark mode even when this unthemed dialog has a light background,
# so decide from the panel's actual background colour.
backgroundColour: wx.Colour = self._bitmapLogo.GetBackgroundColour()
backgroundLuminance: float = (
0.299 * backgroundColour.Red() + 0.587 * backgroundColour.Green() + 0.114 * backgroundColour.Blue()
)
if backgroundLuminance < 128:
# light grey rather than white, so the pill is not glaring on a dark dialog
graphicsContext.SetBrush(wx.Brush(wx.Colour(210, 210, 210)))
graphicsContext.SetPen(wx.TRANSPARENT_PEN)
# fixed 20 DIP radius so this stays a rounded rectangle, not a circle
cornerRadius: int = 20
graphicsContext.DrawRoundedRectangle(0, 0, panelSize.width, panelSize.height, cornerRadius)
# scale to the panel size so a hi-DPI bitmap is not drawn at native pixel size
bitmap: wx.Bitmap = self._logoBitmapBundle.GetBitmapFor(self._bitmapLogo)
graphicsContext.DrawBitmap(bitmap, 0, 0, panelSize.width, panelSize.height)

@staticmethod
def pathToLanguagesFolder() -> str:
r"""Returns the full path to the Languages rules folder.
Expand Down
15 changes: 14 additions & 1 deletion addon/globalPlugins/MathCAT/MathCATgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,24 @@ def __init__(self, parent: wx.Window | None):
wx.ID_ANY,
wx.NullBitmap,
wx.DefaultPosition,
wx.Size(126, 85),
wx.DefaultSize,
0,
)

bSizerCategories.Add(self._bitmapLogo, 0, wx.ALL, 5)

self._staticTextVersion: wx.StaticText = wx.StaticText(
self._panelCategories,
wx.ID_ANY,
"",
wx.DefaultPosition,
wx.DefaultSize,
wx.ALIGN_CENTRE_HORIZONTAL,
)
self._staticTextVersion.Wrap(-1)

bSizerCategories.Add(self._staticTextVersion, 0, wx.ALL | wx.EXPAND, 5)

self._panelCategories.SetSizer(bSizerCategories)
self._panelCategories.Layout()
bSizerCategories.Fit(self._panelCategories)
Expand Down
Binary file modified addon/globalPlugins/MathCAT/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions wxFormBuilder/MathCATgui.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,67 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticTextVersion</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxALIGN_CENTRE_HORIZONTAL</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
</object>
</object>
</object>
Expand Down
Binary file modified wxFormBuilder/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading