def OnTransparency(self, event): transparency = ArtManager.Get().GetTransparency() dlg = wx.TextEntryDialog(self, 'Please enter a value for menu transparency', 'FlatMenu Transparency', str(transparency)) if dlg.ShowModal() != wx.ID_OK: dlg.Destroy() return value = dlg.GetValue() dlg.Destroy() try: value = int(value) except: dlg = wx.MessageDialog(self, "Invalid transparency value!", "Error", wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() if value < 0 or value > 255: dlg = wx.MessageDialog(self, "Invalid transparency value!", "Error", wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() ArtManager.Get().SetTransparency(value)
def DrawToolBarBg(self, dc, rect): if not ArtManager.Get().GetRaiseToolbar(): return # fill with gradient startColor = ArtManager.Get().GetMenuBarFaceColour() dc.SetPen(wx.Pen(startColor)) dc.SetBrush(wx.Brush(startColor)) dc.DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight())
def DrawMenuBarBackground(self, dc, rect): # For office style, we simple draw a rectangle with a gradient colouring vertical = ArtManager.Get().GetMBVerticalGradient() dcsaver = DCSaver(dc) # fill with gradient startColour = self.menuBarFaceColour endColour = ArtManager.Get().LightColour(startColour, 90) dc.SetPen(wx.Pen(endColour)) dc.SetBrush(wx.Brush(endColour)) dc.DrawRectangle(rect)
def OnStyle(self, event): eventId = event.GetId() if eventId == MENU_STYLE_2007: ArtManager.Get().SetMenuTheme(FM.Style2007) elif eventId == MENU_STYLE_XP: ArtManager.Get().SetMenuTheme(FM.StyleXP) elif eventId == MENU_STYLE_MY: ArtManager.Get().SetMenuTheme(self.newMyTheme) self._mb.Refresh() self._mtb.Refresh() self.Update()
def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE, log=None): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.SetIcon(images.Mondrian.GetIcon()) if _hasAUI: self._mgr = AuiManager() self._mgr.SetManagedWindow(self) self._popUpMenu = None # Add log window self.log = log self.statusbar = self.CreateStatusBar(4) self.statusbar.SetStatusWidths([-2, -1, -2, -1]) self.statusbar.SetStatusText(" 系统正在运行......", 0) self.statusbar.SetStatusText("", 1) self.timer = wx.PyTimer(self.Notify) self.timer.Start(100) self.CreateMenu() self.ConnectEvents() # # self._notebook_style = aui.AUI_NB_DEFAULT_STYLE | wx.NO_BORDER self._notebook_style &= ~( aui.AUI_NB_CLOSE_BUTTON | aui.AUI_NB_CLOSE_ON_ACTIVE_TAB | aui.AUI_NB_CLOSE_ON_ALL_TABS | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_EXTERNAL_MOVE) self._notebook_theme = 5 ArtManager.Get().SetMBVerticalGradient(True) ArtManager.Get().SetRaiseToolbar(False) self._mb.Refresh() # self._mtb.Refresh() self.CenterOnScreen()
def DrawButton(self, dc, rect, state, colour=None): if state == ControlFocus: penColour = switchRGBtoBGR(ArtManager.Get().FrameColour()) brushColour = switchRGBtoBGR(ArtManager.Get().BackgroundColour()) elif state == ControlPressed: penColour = switchRGBtoBGR(ArtManager.Get().FrameColour()) brushColour = switchRGBtoBGR(ArtManager.Get().HighlightBackgroundColour()) else: # ControlNormal, ControlDisabled, default penColour = switchRGBtoBGR(ArtManager.Get().FrameColour()) brushColour = switchRGBtoBGR(ArtManager.Get().BackgroundColour()) # Draw the button borders dc.SetPen(wx.Pen(penColour)) dc.SetBrush(wx.Brush(brushColour)) dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height,4)
def __init__(self, parent, log): wx.Frame.__init__(self, parent, size=(700, 500), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) self.SetIcon(images.Mondrian.GetIcon()) wx.SystemOptions.SetOption("msw.remap", "0") self.SetTitle("FlatMenu wxPython Demo ;-D") if _hasAUI: self._mgr = AuiManager() self._mgr.SetManagedWindow(self) self._popUpMenu = None mainSizer = wx.BoxSizer(wx.VERTICAL) # Create a main panel and place some controls on it mainPanel = wx.Panel(self, wx.ID_ANY) panelSizer = wx.BoxSizer(wx.VERTICAL) mainPanel.SetSizer(panelSizer) # Create minibar Preview Panel minibarPanel= wx.Panel(self, wx.ID_ANY) self.CreateMinibar(minibarPanel) miniSizer = wx.BoxSizer(wx.VERTICAL) miniSizer.Add(self._mtb, 0, wx.EXPAND) minibarPanel.SetSizer(miniSizer) # Add log window self.log = log hs = wx.BoxSizer(wx.HORIZONTAL) btn = wx.Button(mainPanel, wx.ID_ANY, "Press me for pop up menu!") hs.Add(btn, 0, wx.ALL, 5) # Connect a button btn.Bind(wx.EVT_BUTTON, self.OnButtonClicked) btn = wx.Button(mainPanel, wx.ID_ANY, "Press me for a long menu!") hs.Add(btn, 0, wx.ALL, 5) panelSizer.Add(hs, 0, wx.ALL, 5) # Connect a button btn.Bind(wx.EVT_BUTTON, self.OnLongButtonClicked) statusbar = self.CreateStatusBar(2) statusbar.SetStatusWidths([-2, -1]) # statusbar fields statusbar_fields = [("FlatMenu wxPython Demo, Andrea Gavana @ 01 Nov 2006"), ("Welcome To wxPython!")] for i in range(len(statusbar_fields)): statusbar.SetStatusText(statusbar_fields[i], i) self.CreateMenu() self.ConnectEvents() mainSizer.Add(self._mb, 0, wx.EXPAND) mainSizer.Add(mainPanel, 1, wx.EXPAND) self.SetSizer(mainSizer) mainSizer.Layout() if _hasAUI: # AUI support self._mgr.AddPane(mainPanel, AuiPaneInfo().Name("main_panel"). CenterPane()) self._mgr.AddPane(minibarPanel, AuiPaneInfo().Name("minibar_panel"). Caption("Minibar Preview").Right(). MinSize(wx.Size(150, 200))) self._mb.PositionAUI(self._mgr) self._mgr.Update() ArtManager.Get().SetMBVerticalGradient(True) ArtManager.Get().SetRaiseToolbar(False) self._mb.Refresh() self._mtb.Refresh() self.CenterOnScreen()
def CreateMenu(self): # Create the menubar self._mb = FM.FlatMenuBar(self, wx.ID_ANY, 32, 5, options = FM_OPT_SHOW_TOOLBAR | FM_OPT_SHOW_CUSTOMIZE) fileMenu = FM.FlatMenu() styleMenu = FM.FlatMenu() editMenu = FM.FlatMenu() multipleMenu = FM.FlatMenu() subMenu = FM.FlatMenu() helpMenu = FM.FlatMenu() subMenu1 = FM.FlatMenu() subMenuExit = FM.FlatMenu() self.newMyTheme = ArtManager.Get().AddMenuTheme(FM_MyRenderer()) ArtManager.Get().SetMenuTheme(self.newMyTheme) # Load toolbar icons (32x32) copy_bmp = wx.Bitmap(os.path.join(bitmapDir, "editcopy.png"), wx.BITMAP_TYPE_PNG) cut_bmp = wx.Bitmap(os.path.join(bitmapDir, "editcut.png"), wx.BITMAP_TYPE_PNG) paste_bmp = wx.Bitmap(os.path.join(bitmapDir, "editpaste.png"), wx.BITMAP_TYPE_PNG) open_folder_bmp = wx.Bitmap(os.path.join(bitmapDir, "fileopen.png"), wx.BITMAP_TYPE_PNG) new_file_bmp = wx.Bitmap(os.path.join(bitmapDir, "filenew.png"), wx.BITMAP_TYPE_PNG) new_folder_bmp = wx.Bitmap(os.path.join(bitmapDir, "folder_new.png"), wx.BITMAP_TYPE_PNG) save_bmp = wx.Bitmap(os.path.join(bitmapDir, "filesave.png"), wx.BITMAP_TYPE_PNG) context_bmp = wx.Bitmap(os.path.join(bitmapDir, "contexthelp-16.png"), wx.BITMAP_TYPE_PNG) colBmp = wx.Bitmap(os.path.join(bitmapDir, "month-16.png"), wx.BITMAP_TYPE_PNG) view1Bmp = wx.Bitmap(os.path.join(bitmapDir, "view_choose.png"), wx.BITMAP_TYPE_PNG) view2Bmp = wx.Bitmap(os.path.join(bitmapDir, "view_detailed.png"), wx.BITMAP_TYPE_PNG) view3Bmp = wx.Bitmap(os.path.join(bitmapDir, "view_icon.png"), wx.BITMAP_TYPE_PNG) view4Bmp = wx.Bitmap(os.path.join(bitmapDir, "view_multicolumn.png"), wx.BITMAP_TYPE_PNG) # Set an icon to the exit/help/transparency menu item exitImg = wx.Bitmap(os.path.join(bitmapDir, "exit-16.png"), wx.BITMAP_TYPE_PNG) helpImg = wx.Bitmap(os.path.join(bitmapDir, "help-16.png"), wx.BITMAP_TYPE_PNG) ghostBmp = wx.Bitmap(os.path.join(bitmapDir, "field-16.png"), wx.BITMAP_TYPE_PNG) # Create a context menu context_menu = FM.FlatMenu() # Create the menu items menuItem = FM.FlatMenuItem(context_menu, wx.ID_ANY, "Test Item", "", wx.ITEM_NORMAL, None, context_bmp) context_menu.AppendItem(menuItem) item = FM.FlatMenuItem(fileMenu, MENU_NEW_FILE, "&New File\tCtrl+N", "New File", wx.ITEM_NORMAL) fileMenu.AppendItem(item) item.SetContextMenu(context_menu) self._mb.AddTool(MENU_NEW_FILE, "New File", new_file_bmp) item = FM.FlatMenuItem(fileMenu, MENU_SAVE, "&Save File\tCtrl+S", "Save File", wx.ITEM_NORMAL) fileMenu.AppendItem(item) self._mb.AddTool(MENU_SAVE, "Save File", save_bmp) item = FM.FlatMenuItem(fileMenu, MENU_OPEN_FILE, "&Open File\tCtrl+O", "Open File", wx.ITEM_NORMAL) fileMenu.AppendItem(item) self._mb.AddTool(MENU_OPEN_FILE, "Open File", open_folder_bmp) self._mb.AddSeparator() # Toolbar separator item = FM.FlatMenuItem(fileMenu, MENU_NEW_FOLDER, "N&ew Folder\tCtrl+E", "New Folder", wx.ITEM_NORMAL) fileMenu.AppendItem(item) self._mb.AddTool(MENU_NEW_FOLDER, "New Folder",new_folder_bmp) self._mb.AddSeparator() # Toobar separator item = FM.FlatMenuItem(fileMenu, MENU_COPY, "&Copy\tCtrl+C", "Copy", wx.ITEM_NORMAL) fileMenu.AppendItem(item) self._mb.AddTool(MENU_COPY, "Copy", copy_bmp) item = FM.FlatMenuItem(fileMenu, MENU_CUT, "Cut\tCtrl+X", "Cut", wx.ITEM_NORMAL) fileMenu.AppendItem(item) self._mb.AddTool(MENU_CUT, "Cut", cut_bmp) item = FM.FlatMenuItem(fileMenu, MENU_PASTE, "Paste\tCtrl+V", "Paste", wx.ITEM_NORMAL, subMenuExit) fileMenu.AppendItem(item) self._mb.AddTool(MENU_PASTE, "Paste", paste_bmp) self._mb.AddSeparator() # Separator # Add a wx.ComboBox to FlatToolbar combo = wx.ComboBox(self._mb, -1, choices=["Hello", "World", "wxPython"]) self._mb.AddControl(combo) self._mb.AddSeparator() # Separator stext = wx.StaticText(self._mb, -1, "Hello") #stext.SetBackgroundStyle(wx.BG_STYLE_CUSTOM ) self._mb.AddControl(stext) self._mb.AddSeparator() # Separator # Add another couple of bitmaps self._mb.AddRadioTool(wx.ID_ANY, "View Column", view1Bmp) self._mb.AddRadioTool(wx.ID_ANY, "View Icons", view2Bmp) self._mb.AddRadioTool(wx.ID_ANY, "View Details", view3Bmp) self._mb.AddRadioTool(wx.ID_ANY, "View Multicolumn", view4Bmp) # Add non-toolbar item item = FM.FlatMenuItem(subMenuExit, wx.ID_EXIT, "E&xit\tAlt+X", "Exit demo", wx.ITEM_NORMAL, None, exitImg) subMenuExit.AppendItem(item) fileMenu.AppendSeparator() item = FM.FlatMenuItem(subMenuExit, wx.ID_EXIT, "E&xit\tAlt+Q", "Exit demo", wx.ITEM_NORMAL, None, exitImg) fileMenu.AppendItem(item) # Second menu item = FM.FlatMenuItem(styleMenu, MENU_STYLE_MY, "Menu style Custom (Default)\tAlt+N", "Menu style Custom (Default)", wx.ITEM_RADIO) styleMenu.AppendItem(item) item.Check(True) item = FM.FlatMenuItem(styleMenu, MENU_STYLE_XP, "Menu style XP\tAlt+P", "Menu style XP", wx.ITEM_RADIO) styleMenu.AppendItem(item) item = FM.FlatMenuItem(styleMenu, MENU_STYLE_2007, "Menu style 2007\tAlt+V", "Menu style 2007", wx.ITEM_RADIO) styleMenu.AppendItem(item) styleMenu.AppendSeparator() item = FM.FlatMenuItem(styleMenu, MENU_USE_CUSTOM, "Show Customize DropDown", "Shows the customize drop down arrow", wx.ITEM_CHECK) item.Check(True) styleMenu.AppendItem(item) styleMenu.AppendSeparator() item = FM.FlatMenuItem(styleMenu, MENU_LCD_MONITOR, "Use LCD monitors option", "Instructs FlatMenu to use LCD drawings", wx.ITEM_CHECK) styleMenu.AppendItem(item) # Add some radio items styleMenu.AppendSeparator() # Add sub-menu to main menu item = FM.FlatMenuItem(styleMenu, wx.ID_ANY, "Sub-&menu radio items", "", wx.ITEM_NORMAL, subMenu1) styleMenu.AppendItem(item) item.SetContextMenu(context_menu) item = FM.FlatMenuItem(subMenu1, wx.ID_ANY, "Radio Item 1", "Radio Item 1", wx.ITEM_RADIO) subMenu1.AppendItem(item) item = FM.FlatMenuItem(subMenu1, wx.ID_ANY, "Radio Item 2", "Radio Item 2", wx.ITEM_RADIO) subMenu1.AppendItem(item) item.Check(True) item = FM.FlatMenuItem(subMenu1, wx.ID_ANY, "Radio Item 3", "Radio Item 3", wx.ITEM_RADIO) subMenu1.AppendItem(item) item = FM.FlatMenuItem(editMenu, MENU_REMOVE_MENU, "Remove menu", "Remove menu", wx.ITEM_NORMAL) editMenu.AppendItem(item) item = FM.FlatMenuItem(editMenu, MENU_DISABLE_MENU_ITEM, "Disable Menu Item ...", "Disable Menu Item", wx.ITEM_NORMAL) editMenu.AppendItem(item) editMenu.AppendSeparator() item = FM.FlatMenuItem(editMenu, MENU_TRANSPARENCY, "Set FlatMenu transparency...", "Sets the FlatMenu transparency", wx.ITEM_NORMAL, None, ghostBmp) editMenu.AppendItem(item) # Add some dummy entries to the sub menu # Add sub-menu to main menu item = FM.FlatMenuItem(editMenu, 9001, "Sub-&menu items", "", wx.ITEM_NORMAL, subMenu) editMenu.AppendItem(item) # Create the submenu items and add them item = FM.FlatMenuItem(subMenu, 9002, "&Sub-menu Item 1", "", wx.ITEM_NORMAL) subMenu.AppendItem(item) item = FM.FlatMenuItem(subMenu, 9003, "Su&b-menu Item 2", "", wx.ITEM_NORMAL) subMenu.AppendItem(item) item = FM.FlatMenuItem(subMenu, 9004, "Sub-menu Item 3", "", wx.ITEM_NORMAL) subMenu.AppendItem(item) item = FM.FlatMenuItem(subMenu, 9005, "Sub-menu Item 4", "", wx.ITEM_NORMAL) subMenu.AppendItem(item) maxItems = 17 numCols = 2 switch = int(math.ceil(maxItems/float(numCols))) for i in xrange(17): row, col = i%switch, i/switch bmp = (random.randint(0, 1) == 1 and [colBmp] or [wx.NullBitmap])[0] item = FM.FlatMenuItem(multipleMenu, wx.ID_ANY, "Row %d, Col %d"%((row+1, col+1)), "", wx.ITEM_NORMAL, None, bmp) multipleMenu.AppendItem(item) multipleMenu.SetNumberColumns(2) item = FM.FlatMenuItem(helpMenu, MENU_HELP, "&About\tCtrl+A", "About...", wx.ITEM_NORMAL, None, helpImg) helpMenu.AppendItem(item) # Add menu to the menu bar self._mb.Append(fileMenu, "&File") self._mb.Append(styleMenu, "&Style") self._mb.Append(editMenu, "&Edit") self._mb.Append(multipleMenu, "&Multiple Columns") self._mb.Append(helpMenu, "&Help")