Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

Bug with context menu and bold style font

Open Ecco37 opened this issue 3 years ago • 3 comments

Operating system: Windows 11 wxPython version & source: wxPython 4.2.0a1.dev5449+3ac1e526 Python version & source: Python 3.10.5

Description of the problem:

Bug with context menu and bold style font (see attachment).

Code Example (click to expand)
import os
import sys
import wx

app_dir = os.path.split(os.path.abspath(sys.argv[0]))[0]
bmp_dir = os.path.join(app_dir, "bitmaps")

class MyPopupMenuBold2(wx.Menu):
    def __init__(self, parent):
        super(MyPopupMenuBold2, self).__init__()
        
        self.parent = parent
        
        mmi = wx.MenuItem(self, -1, 'MiniSize')
        self.Append(mmi)
        self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)

        bmp = wx.Bitmap(os.path.join(bmp_dir,
                                     "exit.png"),
                        type=wx.BITMAP_TYPE_PNG)
        
        if True or "__WXMSW__" in wx.PlatformInfo:
            font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
            font.SetWeight(wx.BOLD)
            
        cmi = wx.MenuItem(self, -1,'Close')
        cmi.SetBitmap(bmp)
        cmi.SetFont(font)
        self.Append(cmi)
        self.Bind(wx.EVT_MENU, self.OnClose, cmi)
       
    def OnMinimize(self, event):
        self.parent.Iconize()

    def OnClose(self, event):
        self.parent.Close()

        
class MyPopupMenuBold1(wx.Menu):
    def __init__(self, parent):
        super(MyPopupMenuBold1, self).__init__()
        
        self.parent = parent

        bmp = wx.Bitmap(os.path.join(bmp_dir,
                                     "about.png"),
                        type=wx.BITMAP_TYPE_PNG)
        
        mmi = wx.MenuItem(self, -1, 'MiniSize')
        mmi.SetBitmap(bmp)
        self.Append(mmi)
        self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)

        bmp = wx.Bitmap(os.path.join(bmp_dir,
                                     "exit.png"),
                        type=wx.BITMAP_TYPE_PNG)
        
        if True or "__WXMSW__" in wx.PlatformInfo:
            font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
            font.SetWeight(wx.BOLD)
            
        cmi = wx.MenuItem(self, -1,'Close')
        cmi.SetBitmap(bmp)
        cmi.SetFont(font)
        self.Append(cmi)
        self.Bind(wx.EVT_MENU, self.OnClose, cmi)
       
    def OnMinimize(self, event):
        self.parent.Iconize()

    def OnClose(self, event):
        self.parent.Close()


class MyPopupMenuStd(wx.Menu):
    def __init__(self, parent):
        super(MyPopupMenuStd, self).__init__()
        
        self.parent = parent
        
        mmi = wx.MenuItem(self, -1,'MiniSize')
        self.Append(mmi)
        self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)
        
        cmi = wx.MenuItem(self, -1,'Close')
        self.Append(cmi)
        self.Bind(wx.EVT_MENU, self.OnClose, cmi)
        
    def OnMinimize(self, event):
        self.parent.Iconize()

    def OnClose(self, event):
        self.parent.Close()

        
class Example(wx.Frame):
    def __init__(self,*args,**kw):
        super(Example, self).__init__(*args,**kw)
        
        self.InitUI()
        
    def InitUI(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
    
        pnlOne = wx.Panel(self)
        label1 = wx.StaticText(pnlOne, -1, "Test - 1")
        pnlOne.SetBackgroundColour("cyan")
        pnlOne.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDownStd)

        pnlTwo = wx.Panel(self)
        label2 = wx.StaticText(pnlTwo, -1, "Test - 2")
        pnlTwo.SetBackgroundColour("yellow")
        pnlTwo.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDownBold1)

        pnlThree = wx.Panel(self)
        label3 = wx.StaticText(pnlThree, -1, "Test - 3")
        pnlThree.SetBackgroundColour("#eceade")
        pnlThree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDownBold2)
        
        sizer.Add(pnlOne, 1, wx.EXPAND)
        sizer.Add(pnlTwo, 1, wx.EXPAND)
        sizer.Add(pnlThree, 1, wx.EXPAND)
        self.SetSizer(sizer)
    
        self.SetSize((400, 200))
        self.SetTitle('wx.Menu (popup or context menu)')
        
        self.Centre()
        self.Show(True)

    def OnRightDownStd(self, event):
        self.PopupMenu(MyPopupMenuStd(self), event.GetPosition())

    def OnRightDownBold1(self, event):
        self.PopupMenu(MyPopupMenuBold1(self), event.GetPosition())

    def OnRightDownBold2(self, event):
        self.PopupMenu(MyPopupMenuBold2(self), event.GetPosition())
        
def main():    
    ex = wx.App()
    Example(None)
    ex.MainLoop()    


if __name__ == '__main__':
    main()
![test-1](https://user-images.githubusercontent.com/52381775/183291412-df30e6ef-0117-4af5-949b-bd7808c90bec.png) ![test-2](https://user-images.githubusercontent.com/52381775/183291413-30286670-007b-4ab0-9d2a-97e483a2ed51.png) ![test-3](https://user-images.githubusercontent.com/52381775/183291419-2f45000e-0dbd-4b01-95e6-1ee1ce9b0af9.png)

Ecco37 avatar Aug 07 '22 12:08 Ecco37

test-1 test-2 test-3

Ecco37 avatar Aug 09 '22 10:08 Ecco37

Same here. It is enought to simply call MenuItem.SetFont(font) or MenuItem.SetDisabledBitmap(bmp). The font can be the default font, it don't has to be bold.

Mscht avatar Jan 17 '23 06:01 Mscht