Create a customized frame - Part 5 (Phoenix)

Keywords : Shaped frame, Customized frame, Customized button, Transparency, Roll, Unroll, Fade in, Fade out, Shape, Region, BufferedPaintDC, BufferedDC, ClientDC, GCDC, AutoBufferedPaintDCFactory, Config, AcceleratorTable.


Demonstrating (only Windows) :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Frame without resize border and pattern :

First possibility

img_sample_one.png

   1 # sample_one.py
   2 
   3 import sys
   4 import os
   5 import platform
   6 import wx
   7 import wx.lib.fancytext as fancytext
   8 import wx.lib.agw.flatmenu as FM
   9 from   wx.lib.agw.artmanager import ArtManager, RendererBase, DCSaver
  10 from   wx.lib.agw.fmresources import ControlFocus, ControlPressed
  11 import wx.lib.mixins.listctrl as listmix
  12 import wx.dataview as dv
  13 import wx.lib.colourdb
  14 import rectshapedbitmapbutton as SBB
  15 import rectshapedbitmapbuttonTwo as SBBTwo
  16 import data
  17 
  18 musicdata = sorted(data.musicdata.items())
  19 musicdata = [[str(k)] + list(v) for k,v in musicdata]
  20 
  21 # def SwitchRGBtoBGR
  22 # def CreateBackgroundBitmap
  23 # class MyMenuRenderer
  24 # class MyListCtrlPnl
  25 # class MyStatusBar
  26 # class MyTitleBar
  27 # class MyAboutDlg
  28 # class MyPopupMenu
  29 # class MyTitleBarPnl
  30 # class MyMainPnl
  31 # class MyFrame
  32 # class MyApp
  33 
  34 SHOW_BACKGROUND = 1
  35 
  36 ID_FULLSCREEN = wx.NewIdRef()
  37 ID_MAIN_PNL = wx.NewIdRef()
  38 ID_BTN_FULLSCREEN = wx.NewIdRef()
  39 ID_BTN_ABOUT = wx.NewIdRef()
  40 ID_BTN_QUIT = wx.NewIdRef()
  41 ID_HELLO = wx.NewIdRef()
  42 
  43 #---------------------------------------------------------------------------
  44 
  45 def SwitchRGBtoBGR(colour):
  46     """
  47     ...
  48     """
  49 
  50     return wx.Colour(colour.Blue(), colour.Green(), colour.Red())
  51 
  52 #---------------------------------------------------------------------------
  53 
  54 def CreateBackgroundBitmap():
  55     """
  56     ...
  57     """
  58 
  59     mem_dc = wx.MemoryDC()
  60     bmp = wx.Bitmap(121, 300)
  61     mem_dc.SelectObject(bmp)
  62 
  63     mem_dc.Clear()
  64 
  65     # Colour the menu face with background colour.
  66     mem_dc.SetPen(wx.Pen("#a0a0a0", 0))
  67     mem_dc.SetBrush(wx.Brush("#76b9ed"))
  68     mem_dc.DrawRectangle(0, 15, 121, 300)
  69     mem_dc.DrawLine(0, 0, 300, 0)
  70 
  71     mem_dc.SelectObject(wx.NullBitmap)
  72     return bmp
  73 
  74 #---------------------------------------------------------------------------
  75 
  76 class MyMenuRenderer(FM.FMRenderer):
  77     """
  78     Thanks to Andrea Gavana.
  79     A custom renderer class for FlatMenu.
  80     """
  81     def __init__(self):
  82         FM.FMRenderer.__init__(self)
  83 
  84     #-----------------------------------------------------------------------
  85 
  86     def DrawMenuButton(self, dc, rect, state):
  87         """
  88         Draws the highlight on a FlatMenu.
  89         """
  90 
  91         self.DrawButton(dc, rect, state)
  92 
  93 
  94     def DrawMenuBarButton(self, dc, rect, state):
  95         """
  96         Draws the highlight on a FlatMenuBar.
  97         """
  98 
  99         self.DrawButton(dc, rect, state)
 100 
 101 
 102     def DrawButton(self, dc, rect, state, colour=None):
 103         """
 104         ...
 105         """
 106 
 107         if state == ControlFocus:
 108             penColour = SwitchRGBtoBGR(ArtManager.Get().FrameColour())
 109             brushColour = SwitchRGBtoBGR(ArtManager.Get().BackgroundColour())
 110         elif state == ControlPressed:
 111             penColour = SwitchRGBtoBGR(ArtManager.Get().FrameColour())
 112             brushColour = SwitchRGBtoBGR(ArtManager.Get().HighlightBackgroundColour())
 113         else:   # ControlNormal, ControlDisabled, default.
 114             penColour = SwitchRGBtoBGR(ArtManager.Get().FrameColour())
 115             brushColour = SwitchRGBtoBGR(ArtManager.Get().BackgroundColour())
 116 
 117         # Draw the button borders.
 118         dc = wx.GCDC(dc)
 119         dc.SetPen(wx.Pen(penColour))
 120         dc.SetBrush(wx.Brush(brushColour))
 121         dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height-3, 4)
 122 
 123 
 124     def DrawMenuBarBackground(self, dc, rect):
 125         """
 126         ...
 127         """
 128 
 129         # For office style, we simple draw a rectangle
 130         # with a gradient colouring.
 131         vertical = ArtManager.Get().GetMBVerticalGradient()
 132 
 133         dcsaver = DCSaver(dc)
 134 
 135         # Fill with gradient.
 136         startColour = self.menuBarFaceColour
 137         endColour   = ArtManager.Get().LightColour(startColour, 0)
 138 
 139         dc.SetPen(wx.Pen(endColour))
 140         dc.SetBrush(wx.Brush(endColour))
 141         dc.DrawRectangle(rect)
 142 
 143 
 144     def DrawToolBarBg(self, dc, rect):
 145         """
 146         ...
 147         """
 148 
 149         if not ArtManager.Get().GetRaiseToolbar():
 150             return
 151 
 152         # Fill with gradient.
 153         startColour = self.menuBarFaceColour()
 154         dc.SetPen(wx.Pen(startColour))
 155         dc.SetBrush(wx.Brush(startColour))
 156         dc.DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight())
 157 
 158 #---------------------------------------------------------------------------
 159 
 160 class MyListCtrlPnl(wx.Panel):
 161     """
 162     Thanks to Robin Dunn.
 163     """
 164     def __init__(self, parent):
 165         wx.Panel.__init__(self, parent, -1)
 166 
 167         # Create the listctrl.
 168         self.dvlc = dv.DataViewListCtrl(self,
 169                                         style=wx.BORDER_SIMPLE|
 170                                               dv.DV_ROW_LINES|
 171                                               dv.DV_HORIZ_RULES|
 172                                               dv.DV_VERT_RULES)
 173 
 174         # Give it some columns.
 175         # The ID col we'll customize a bit :
 176         self.dvlc.AppendTextColumn("Id", width=40)
 177         self.dvlc.AppendTextColumn("Artist", width=170)
 178         self.dvlc.AppendTextColumn("Title", width=260)
 179         self.dvlc.AppendTextColumn("Genre", width=80)
 180 
 181         # Load the data. Each item (row) is added as a sequence
 182         # of values whose order matches the columns.
 183         for itemvalues in musicdata:
 184             self.dvlc.AppendItem(itemvalues)
 185 
 186         self.dvlc.SetBackgroundColour("#c9f72b")
 187         self.dvlc.SetForegroundColour("black")
 188 
 189         # Set the layout so the listctrl fills the panel.
 190         self.Sizer = wx.BoxSizer()
 191         self.Sizer.Add(self.dvlc, 1, wx.EXPAND)
 192 
 193 #---------------------------------------------------------------------------
 194 
 195 class MyStatusBar(wx.StatusBar) :
 196     """
 197     Thanks to ???.
 198     Simple custom colorized StatusBar.
 199     """
 200     def __init__(self, parent, id) :
 201         wx.StatusBar.__init__(self, parent, id)
 202 
 203         #------------
 204 
 205         # Return config file.
 206         self.config = wx.GetApp().GetConfig()
 207 
 208         #------------
 209 
 210         # Simplified init method.
 211         self.SetProperties()
 212         self.BindEvents()
 213 
 214     #-----------------------------------------------------------------------
 215 
 216     def SetProperties(self):
 217         """
 218         ...
 219         """
 220 
 221         # Read config file.
 222         self.SetBackgroundColour(wx.Colour(self.config.Read("Color1")))
 223 
 224 
 225     def BindEvents(self):
 226         """
 227         Bind some events to an events handler.
 228         """
 229 
 230         self.Bind(wx.EVT_PAINT, self.OnPaint)
 231 
 232 
 233     def OnPaint(self, event) :
 234         """
 235         ...
 236         """
 237 
 238         dc = wx.BufferedPaintDC(self)
 239         self.Draw(dc)
 240 
 241 
 242     def Draw(self, dc) :
 243         """
 244         ...
 245         """
 246 
 247         # Read config file.
 248         dc.SetBackground(wx.Brush(wx.WHITE))
 249         dc.Clear()
 250 
 251         textVertOffset = 3      # Perfect for MSW.
 252         textHorzOffset = 5      # Arbitrary - looks nicer.
 253 
 254         dc.SetTextForeground("gray")
 255         dc.DrawText(self.GetStatusText(), textHorzOffset, textVertOffset)
 256 
 257 #---------------------------------------------------------------------------
 258 
 259 class MyTitleBar(wx.Control):
 260     """
 261     Thanks to Cody Precord.
 262     """
 263     def __init__(self, parent, label, size):
 264         style = (wx.BORDER_NONE)
 265         super(MyTitleBar, self).__init__(parent,
 266                                          style=style)
 267 
 268         #------------
 269 
 270         # Return bitmaps folder.
 271         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
 272 
 273         #------------
 274 
 275         # Attributes.
 276         self.parent = parent
 277         self.label = label
 278         self.size = size
 279 
 280         #------------
 281 
 282         # Simplified init method.
 283         self.SetBackground()
 284         self.SetProperties(label, size)
 285         self.CreateCtrls()
 286         self.DoLayout()
 287         self.BindEvents()
 288 
 289     #-----------------------------------------------------------------------
 290 
 291     def SetBackground(self):
 292         """
 293         ...
 294         """
 295 
 296         self.SetBackgroundColour(wx.Colour(wx.WHITE))
 297         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
 298 
 299 
 300     def SetProperties(self, label, size):
 301         """
 302         ...
 303         """
 304 
 305         self.label = label
 306         self.size = size
 307 
 308         self.label_font = self.GetFont()
 309         self.label_font.SetFamily(wx.SWISS)
 310         self.label_font.SetPointSize(size)
 311         self.label_font.SetWeight(wx.BOLD)
 312         self.SetFont(self.label_font)
 313 
 314 
 315     def CreateCtrls(self):
 316         """
 317         ...
 318         """
 319 
 320         w, h = self.GetSize()
 321         w1, h1 = self.GetClientSize()
 322 
 323         #------------
 324 
 325         # Load an icon bitmap for titlebar.
 326         # bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
 327         #                              "icon_app.png"),
 328         #                 type=wx.BITMAP_TYPE_PNG)
 329 
 330         # self.ico = wx.StaticBitmap(self, -1, bmp)
 331         # self.ico.SetBackgroundColour(wx.Colour(self.config.Read("Color2")))
 332         # self.ico.SetPosition((300, 1))
 333         # self.ico.SetToolTip("This is a customized icon.")
 334         # self.ico.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
 335 
 336         #------------
 337 
 338         # Button Exit.
 339         self.btn3 = SBBTwo.ShapedBitmapButton(self, -1,
 340             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
 341                                           "btn_gloss_exit_normal_1.png"),
 342                              type=wx.BITMAP_TYPE_PNG),
 343 
 344             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 345                                               "btn_gloss_exit_selected_1.png"),
 346                                  type=wx.BITMAP_TYPE_PNG),
 347 
 348             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 349                                             "btn_gloss_exit_normal_1.png"),
 350                                type=wx.BITMAP_TYPE_PNG),
 351 
 352             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 353                                                "btn_gloss_exit_normal_1.png"),
 354                                   type=wx.BITMAP_TYPE_PNG),
 355 
 356             label="",
 357             labelForeColour=wx.WHITE,
 358             labelFont=wx.Font(9,
 359                               wx.FONTFAMILY_DEFAULT,
 360                               wx.FONTSTYLE_NORMAL,
 361                               wx.FONTWEIGHT_BOLD),
 362             style=wx.BORDER_NONE)
 363 
 364         #------------
 365 
 366         # Button Maximize.
 367         self.btn4 = SBBTwo.ShapedBitmapButton(self, -1,
 368             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
 369                                           "btn_gloss_maximize_normal_1.png"),
 370                              type=wx.BITMAP_TYPE_PNG),
 371 
 372             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 373                                               "btn_gloss_maximize_selected_1.png"),
 374                                  type=wx.BITMAP_TYPE_PNG),
 375 
 376             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 377                                             "btn_gloss_maximize_normal_1.png"),
 378                                type=wx.BITMAP_TYPE_PNG),
 379 
 380             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 381                                                "btn_gloss_maximize_normal_1.png"),
 382                                   type=wx.BITMAP_TYPE_PNG),
 383 
 384             label="",
 385             labelForeColour=wx.WHITE,
 386             labelFont=wx.Font(9,
 387                               wx.FONTFAMILY_DEFAULT,
 388                               wx.FONTSTYLE_NORMAL,
 389                               wx.FONTWEIGHT_BOLD),
 390             style=wx.BORDER_NONE)
 391 
 392         #------------
 393 
 394         # Thanks to MCOW.
 395         # Button Reduce.
 396         self.btn5 = SBBTwo.ShapedBitmapButton(self, -1,
 397             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
 398                                           "btn_gloss_reduce_normal_1.png"),
 399                              type=wx.BITMAP_TYPE_PNG),
 400 
 401             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 402                                               "btn_gloss_reduce_selected_1.png"),
 403                                  type=wx.BITMAP_TYPE_PNG),
 404 
 405             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 406                                             "btn_gloss_reduce_normal_1.png"),
 407                                type=wx.BITMAP_TYPE_PNG),
 408 
 409             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 410                                                "btn_gloss_reduce_normal_1.png"),
 411                                   type=wx.BITMAP_TYPE_PNG),
 412 
 413             label="",
 414             labelForeColour=wx.WHITE,
 415             labelFont=wx.Font(9,
 416                               wx.FONTFAMILY_DEFAULT,
 417                               wx.FONTSTYLE_NORMAL,
 418                               wx.FONTWEIGHT_BOLD),
 419             style=wx.BORDER_NONE)
 420 
 421         #------------
 422 
 423         # Button Roll.
 424         self.btn6 = SBBTwo.ShapedBitmapButton(self, -1,
 425             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
 426                                           "btn_gloss_roll_normal_1.png"),
 427                              type=wx.BITMAP_TYPE_PNG),
 428 
 429             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 430                                               "btn_gloss_roll_selected_1.png"),
 431                                  type=wx.BITMAP_TYPE_PNG),
 432 
 433             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 434                                             "btn_gloss_roll_normal_1.png"),
 435                                type=wx.BITMAP_TYPE_PNG),
 436 
 437             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
 438                                                "btn_gloss_roll_normal_1.png"),
 439                                   type=wx.BITMAP_TYPE_PNG),
 440 
 441             label="",
 442             labelForeColour=wx.WHITE,
 443             labelFont=wx.Font(9,
 444                               wx.FONTFAMILY_DEFAULT,
 445                               wx.FONTSTYLE_NORMAL,
 446                               wx.FONTWEIGHT_BOLD),
 447             style=wx.BORDER_NONE)
 448 
 449 
 450     def DoLayout(self):
 451         """
 452         ...
 453         """
 454 
 455         mainSizer = wx.BoxSizer(wx.HORIZONTAL)
 456 
 457         #------------
 458 
 459         mainSizer.Add(self.btn3, 0, wx.LEFT | wx.TOP, 4)
 460         mainSizer.Add(self.btn4, 0, wx.LEFT | wx.TOP, 4)
 461         mainSizer.Add(self.btn5, 0, wx.LEFT | wx.TOP, 4)
 462         mainSizer.Add(self.btn6, 0, wx.LEFT | wx.TOP, 4)
 463 
 464         #------------
 465 
 466         self.SetSizer(mainSizer)
 467         self.Layout()
 468 
 469 
 470     def BindEvents(self):
 471         """
 472         Bind some events to an events handler.
 473         """
 474 
 475         # self.ico.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
 476         # self.ico.Bind(wx.EVT_LEFT_DOWN, self.OnRightDown)
 477 
 478         self.Bind(wx.EVT_PAINT, self.OnPaint)
 479         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
 480         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
 481 
 482         self.btn3.Bind(wx.EVT_BUTTON, self.OnBtnClose)
 483         self.btn4.Bind(wx.EVT_BUTTON, self.OnFullScreen)
 484         self.btn5.Bind(wx.EVT_BUTTON, self.OnIconfiy)
 485         self.btn6.Bind(wx.EVT_BUTTON, self.OnRoll)
 486 
 487 
 488     def OnRightDown(self, event):
 489         """
 490         ...
 491         """
 492 
 493         self.PopupMenu(MyPopupMenu(self), event.GetPosition())
 494 
 495         print("Right down.")
 496 
 497 
 498     def OnLeftDown(self, event):
 499         """
 500         ...
 501         """
 502 
 503         self.GetTopLevelParent().OnLeftDown(event)
 504 
 505 
 506     def OnLeftUp(self, event):
 507         """
 508         ...
 509         """
 510 
 511         self.GetTopLevelParent().OnLeftUp(event)
 512 
 513 
 514     def SetLabel(self, label):
 515         """
 516         ...
 517         """
 518 
 519         self.label = label
 520         self.Refresh()
 521 
 522 
 523     def DoGetBestSize(self):
 524         """
 525         ...
 526         """
 527 
 528         dc = wx.ClientDC(self)
 529         dc.SetFont(self.GetFont())
 530 
 531         textWidth, textHeight = dc.GetTextExtent(self.label)
 532         spacing = 10
 533         totalWidth = textWidth + (spacing)
 534         totalHeight = textHeight + (spacing)
 535 
 536         best = wx.Size(totalWidth, totalHeight)
 537         self.CacheBestSize(best)
 538 
 539         return best
 540 
 541 
 542     def GetLabel(self):
 543         """
 544         ...
 545         """
 546 
 547         return self.label
 548 
 549 
 550     def GetLabelColor(self):
 551         """
 552         ...
 553         """
 554 
 555         return self.foreground
 556 
 557 
 558     def GetLabelSize(self):
 559         """
 560         ...
 561         """
 562 
 563         return self.size
 564 
 565 
 566     def SetLabelColour(self, colour):
 567         """
 568         ...
 569         """
 570 
 571         self.labelColour = colour
 572 
 573 
 574     def OnPaint(self, event):
 575         """
 576         ...
 577         """
 578 
 579         dc = wx.BufferedPaintDC(self)
 580         gcdc = wx.GCDC(dc)
 581 
 582         gcdc.Clear()
 583 
 584         # Setup the GraphicsContext.
 585         gc = gcdc.GetGraphicsContext()
 586 
 587         # Get the working size we can draw in.
 588         width, height = self.GetSize()
 589 
 590         # Use the GCDC to draw the text.
 591         # Read config file.
 592         brush = wx.WHITE
 593         gcdc.SetPen(wx.Pen(brush, 1))
 594         gcdc.SetBrush(wx.Brush(brush))
 595         gcdc.DrawRectangle(0, 0, width, height)
 596 
 597         # Get the system font.
 598         gcdc.SetFont(self.GetFont())
 599 
 600         textWidth, textHeight = gcdc.GetTextExtent(self.label)
 601         tposx, tposy = ((width/2)-(textWidth/2), (height/3)-(textHeight/3))
 602 
 603         tposx += 0
 604         tposy += 0
 605 
 606         # Set position and text color.
 607         gcdc.SetTextForeground("white")
 608         gcdc.DrawText(self.label, int(tposx), int(tposy+1))
 609 
 610         gcdc.SetTextForeground(self.labelColour)
 611         gcdc.DrawText(self.label, int(tposx), int(tposy))
 612 
 613 
 614     def OnRoll(self, event):
 615         """
 616         ...
 617         """
 618 
 619         self.GetTopLevelParent().OnRoll(True)
 620 
 621         print("Roll/unRoll button was clicked.")
 622 
 623 
 624     def OnIconfiy(self, event):
 625         """
 626         ...
 627         """
 628 
 629         self.GetTopLevelParent().OnIconfiy(self)
 630 
 631         print("Iconfiy button was clicked.")
 632 
 633 
 634     def OnFullScreen(self, event):
 635         """
 636         ...
 637         """
 638 
 639         self.GetTopLevelParent().OnFullScreen(self)
 640 
 641         print("FullScreen button was clicked.")
 642 
 643 
 644     def OnBtnClose(self, event):
 645         """
 646         ...
 647         """
 648 
 649         self.GetTopLevelParent().OnCloseWindow(self)
 650 
 651         print("Close button was clicked.")
 652 
 653 #---------------------------------------------------------------------------
 654 
 655 class MyAboutDlg(wx.Frame):
 656     """
 657     Thanks to Robin Dunn.
 658     """
 659     def __init__(self, parent):
 660         style = (wx.FRAME_SHAPED | wx.NO_BORDER |
 661                  wx.CLIP_CHILDREN | wx.STAY_ON_TOP |
 662                  wx.SYSTEM_MENU | wx.CLOSE_BOX |
 663                  wx.NO_FULL_REPAINT_ON_RESIZE)
 664         wx.Frame.__init__(self,
 665                           parent,
 666                           id=-1,
 667                           title="About...",
 668                           style=style)
 669 
 670         #------------
 671 
 672         # Attributes.
 673         self.SetTransparent(0)
 674         self.opacity_in = 0
 675         self.opacity_out = 255
 676         self.deltaN = -70
 677         self.hasShape = False
 678         self.delta = wx.Point(0,0)
 679 
 680         #------------
 681 
 682         # Return application name.
 683         self.app_name = wx.GetApp().GetAppName()
 684         # Return bitmaps folder.
 685         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
 686         # Return icons folder.
 687         self.icons_dir = wx.GetApp().GetIconsDir()
 688 
 689         #------------
 690 
 691         # Simplified init method.
 692         self.SetProperties()
 693         self.OnTimerIn(self)
 694         self.CreateCtrls()
 695         self.BindEvents()
 696 
 697         #------------
 698 
 699         self.CenterOnParent(wx.BOTH)
 700         self.GetParent().Enable(False)
 701 
 702         #------------
 703 
 704         self.Show(True)
 705 
 706         #------------
 707 
 708         self.eventLoop = wx.GUIEventLoop()
 709         self.eventLoop.Run()
 710 
 711     #-----------------------------------------------------------------------
 712 
 713     def SetProperties(self):
 714         """
 715         Set the dialog properties (title, icon, transparency...).
 716         """
 717 
 718         frameIcon = wx.Icon(os.path.join(self.icons_dir,
 719                                          "icon_wxWidgets.ico"),
 720                             type=wx.BITMAP_TYPE_ICO)
 721         self.SetIcon(frameIcon)
 722 
 723 
 724     def OnTimerIn(self, evt):
 725         """
 726         Thanks to Pascal Faut.
 727         """
 728 
 729         self.timer1 = wx.Timer(self, -1)
 730         self.timer1.Start(1)
 731         self.Bind(wx.EVT_TIMER, self.AlphaCycle1, self.timer1)
 732 
 733         print("Fade-in was launched.")
 734 
 735 
 736     def OnTimerOut(self, evt):
 737         """
 738         Thanks to Pascal Faut.
 739         """
 740 
 741         self.timer2 = wx.Timer(self, -1)
 742         self.timer2.Start(1)
 743         self.Bind(wx.EVT_TIMER, self.AlphaCycle2, self.timer2)
 744 
 745         print("Fade-out was launched.")
 746 
 747 
 748     def AlphaCycle1(self, *args):
 749         """
 750         Thanks to Pascal Faut.
 751         """
 752 
 753         self.opacity_in += self.deltaN
 754         if self.opacity_in <= 0:
 755             self.deltaN = -self.deltaN
 756             self.opacity_in = 0
 757 
 758         if self.opacity_in >= 255:
 759             self.deltaN = -self.deltaN
 760             self.opacity_in = 255
 761 
 762             self.timer1.Stop()
 763 
 764         self.SetTransparent(self.opacity_in)
 765 
 766         print("Fade in = {}/255".format(self.opacity_in))
 767 
 768 
 769     def AlphaCycle2(self, *args):
 770         """
 771         Thanks to Pascal Faut.
 772         """
 773 
 774         self.opacity_out += self.deltaN
 775         if self.opacity_out >= 255:
 776             self.deltaN = -self.deltaN
 777             self.opacity_out = 255
 778 
 779         if self.opacity_out <= 0:
 780             self.deltaN = -self.deltaN
 781             self.opacity_out = 0
 782 
 783             self.timer2.Stop()
 784 
 785             wx.CallAfter(self.Destroy)
 786 
 787         self.SetTransparent(self.opacity_out)
 788 
 789         print("Fade out = {}/255".format(self.opacity_out))
 790 
 791 
 792     def CreateCtrls(self):
 793         """
 794         Make widgets for my dialog.
 795         """
 796 
 797         # Load a background bitmap.
 798         self.bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
 799                                           "skin_about2.png"),
 800                              type=wx.BITMAP_TYPE_PNG)
 801         mask = wx.Mask(self.bmp, wx.RED)
 802         self.bmp.SetMask(mask)
 803 
 804         #------------
 805 
 806         self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
 807 
 808         #------------
 809 
 810         if wx.Platform == "__WXGTK__":
 811             # wxGTK requires that the window be created before you can
 812             # set its shape, so delay the call to SetWindowShape until
 813             # this event.
 814             self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
 815         else:
 816             # On wxMSW and wxMac the window has already
 817             # been created, so go for it.
 818             self.SetWindowShape()
 819 
 820 
 821     def BindEvents(self):
 822         """
 823         Bind all the events related to my dialog.
 824         """
 825 
 826         # Bind some events to an events handler.
 827         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
 828         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
 829         self.Bind(wx.EVT_RIGHT_UP, self.OnCloseWindow)  # Panel right clic.
 830         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
 831         self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
 832         self.Bind(wx.EVT_MOTION, self.OnMouseMove)
 833         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
 834         self.Bind(wx.EVT_PAINT, self.OnPaint)
 835         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
 836 
 837 
 838     def SetWindowShape(self, event=None):
 839         """
 840         ...
 841         """
 842 
 843         # Use the bitmap's mask to determine the region.
 844         r = wx.Region(self.bmp)
 845         self.hasShape = self.SetShape(r)
 846 
 847 
 848     def OnEraseBackground(self, event):
 849         """
 850         ...
 851         """
 852 
 853         dc = event.GetDC()
 854         if not dc:
 855             dc = wx.ClientDC(self)
 856             rect = self.GetUpdateRegion().GetBox()
 857             dc.SetClippingRect(rect)
 858 
 859 
 860     def OnLeftDown(self, event):
 861         """
 862         ...
 863         """
 864 
 865         self.CaptureMouse()
 866         x, y = self.ClientToScreen(event.GetPosition())
 867         originx, originy = self.GetPosition()
 868         dx = x - originx
 869         dy = y - originy
 870         self.delta = ((dx, dy))
 871 
 872 
 873     def OnLeftUp(self, evt):
 874         """
 875         ...
 876         """
 877 
 878         if self.HasCapture():
 879             self.ReleaseMouse()
 880 
 881 
 882     def OnMouseMove(self, event):
 883         """
 884         ...
 885         """
 886 
 887         if event.Dragging() and event.LeftIsDown():
 888             x, y = self.ClientToScreen(event.GetPosition())
 889             fp = (x - self.delta[0], y - self.delta[1])
 890             self.Move(fp)
 891 
 892 
 893     def OnPaint(self, event):
 894         """
 895         ...
 896         """
 897 
 898         dc = wx.AutoBufferedPaintDCFactory(self)
 899         dc.DrawBitmap(self.bmp, 0, 0, True)
 900 
 901         #------------
 902 
 903         # These are strings.
 904         py_version = sys.version.split()[0]
 905 
 906         str1 = (('<font style="normal" family="default" color="yellow" size="10" weight="bold">'
 907                  'Programming : </font>'
 908                  '<font style="normal" family="default" color="black" size="10" weight="normal">'
 909                  'Python {}</font>').format(py_version))   # Python 3.7.2
 910 
 911         str2 = (('<font style="normal" family="default" color="red" size="10" weight="bold">'
 912                  'GUI toolkit : </font>'
 913                  '<font style="normal" family="default" color="black" size="10" weight="normal">'
 914                  'wxPython {}</font>').format(wx.VERSION_STRING))  # wxPython 4.0.4
 915 
 916         str3 = (('<font style="normal" family="default" color="brown" size="10" weight="bold">'
 917                  'Library : </font>'
 918                  '<font style="normal" family="default" color="black" size="10" weight="normal">'
 919                  '{}</font>').format(wx.GetLibraryVersionInfo().VersionString))   # wxWidgets 3.0.5
 920 
 921         str4 = (('<font style="normal" family="default" color="blue" size="10" weight="bold">'
 922                  'Operating system : </font>'
 923                  '<font style="normal" family="default" color="black" size="10" weight="normal">'
 924                  '{}</font>').format(platform.system()))   # Windows
 925 
 926         str5 = (('<font style="normal" family="default" color="white" size="9" weight="normal">'
 927                  '{}</font>').format(self.app_name))   # Custom Gui 4
 928 
 929         str6 = (('<font style="normal" family="default" color="black" size="8" weight="normal">'
 930                  'Right clic or Esc for Exit</font>'))
 931 
 932         #------------
 933 
 934         # Return image size.
 935         bw, bh = self.bmp.GetWidth(), self.bmp.GetHeight()
 936 
 937         # Draw text.
 938         # Need width to calculate x position of str1.
 939         tw, th = fancytext.GetExtent(str1, dc)
 940         # Centered text.
 941         fancytext.RenderToDC(str1, dc, (bw-tw)/2, 30)
 942 
 943         #------------
 944 
 945         # Need width to calculate x position of str2.
 946         tw, th = fancytext.GetExtent(str2, dc)
 947         # Centered text.
 948         fancytext.RenderToDC(str2, dc, (bw-tw)/2, 50)
 949 
 950         #------------
 951 
 952         # Need width to calculate x position of str3.
 953         tw, th = fancytext.GetExtent(str3, dc)
 954         # Centered text.
 955         fancytext.RenderToDC(str3, dc, (bw-tw)/2, 70)
 956 
 957         #------------
 958 
 959         # Need width to calculate x position of str4.
 960         tw, th = fancytext.GetExtent(str4, dc)
 961         # Centered text.
 962         fancytext.RenderToDC(str4, dc, (bw-tw)/2, 90)
 963 
 964         #------------
 965 
 966         # Need width to calculate x position of str5.
 967         tw, th = fancytext.GetExtent(str5, dc)
 968         # Centered text.
 969         fancytext.RenderToDC(str5, dc, (bw-tw)/2, 130)
 970 
 971         #------------
 972 
 973         # Need width to calculate x position of str6.
 974         tw, th = fancytext.GetExtent(str6, dc)
 975         # Centered text.
 976         fancytext.RenderToDC(str6, dc, (bw-tw)/2, 195)
 977 
 978 
 979     def OnKeyUp(self, event):
 980         """
 981         ...
 982         """
 983 
 984         if event.GetKeyCode() == wx.WXK_ESCAPE:
 985             self.OnCloseWindow(event)
 986 
 987         event.Skip()
 988 
 989 
 990     def OnCloseWindow(self, event):
 991         """
 992         ...
 993         """
 994 
 995         self.GetParent().Enable(True)
 996         self.eventLoop.Exit()
 997         self.Destroy()
 998 
 999 #---------------------------------------------------------------------------
1000 
1001 class MyPopupMenu(wx.Menu):
1002     """
1003     Thanks to Robin Dunn.
1004     """
1005     def __init__(self, parent):
1006         wx.Menu.__init__(self)
1007 
1008         #------------
1009 
1010         # Attributes.
1011         self.parent = parent
1012 
1013         #------------
1014 
1015         # Returns bitmaps folder.
1016         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1017 
1018         #------------
1019 
1020         # Simplified init method.
1021         self.CreatePopupMenu()
1022         self.BindEvents()
1023 
1024     #-----------------------------------------------------------------------
1025 
1026     def CreatePopupMenu(self, event=None):
1027         """
1028         This method is called by the base class when it needs to popup
1029         the menu for the default EVT_RIGHT_DOWN event.  Just create
1030         the menu how you want it and return it from this function,
1031         the base class takes care of the rest.
1032         """
1033 
1034         bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
1035                                      "item_about.png"),
1036                         type=wx.BITMAP_TYPE_PNG)
1037 
1038         item = wx.MenuItem(self, id=wx.ID_ABOUT, text=" About")
1039         item.SetBitmap(bmp)
1040         self.Append(item)
1041         self.AppendSeparator()
1042 
1043         #------------
1044 
1045         bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
1046                                      "item_exit.png"),
1047                         type=wx.BITMAP_TYPE_PNG)
1048 
1049         if True or "__WXMSW__" in wx.PlatformInfo:
1050             font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
1051             font.SetWeight(wx.BOLD)
1052 
1053         item = wx.MenuItem(self, id=wx.ID_EXIT, text=" Exit")
1054         item.SetBitmap(bmp)
1055         item.SetFont(font)
1056         self.Append(item)
1057 
1058         return self
1059 
1060 
1061     def BindEvents(self):
1062         """
1063         Bind some events to an events handler.
1064         """
1065 
1066         # Bind the menu events to an events handler.
1067         self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
1068         self.Bind(wx.EVT_MENU, self.OnClose, id=wx.ID_EXIT)
1069 
1070 
1071     def OnAbout(self, event):
1072         """
1073         ...
1074         """
1075 
1076         self.mainFrame = wx.GetApp().GetTopWindow()
1077         self.mainFrame.OnAbout(self)
1078 
1079         print("About icon was clicked.")
1080 
1081 
1082     def OnClose(self, event):
1083         """
1084         ...
1085         """
1086 
1087         self.mainFrame = wx.GetApp().GetTopWindow()
1088         self.mainFrame.OnCloseWindow(self)
1089 
1090         print("Close icon was clicked.")
1091 
1092 #---------------------------------------------------------------------------
1093 
1094 class MyTitleBarPnl(wx.Panel):
1095     """
1096     Thanks to Cody Precord.
1097     """
1098     def __init__(self, parent, id, size):
1099         style = (wx.NO_BORDER)
1100         super(MyTitleBarPnl, self).__init__(parent,
1101                                             id,
1102                                             size=size,
1103                                             style=style)
1104 
1105         #------------
1106 
1107         # Attributes.
1108         self.parent = parent
1109 
1110         #------------
1111 
1112         # Return application name.
1113         self.app_name = wx.GetApp().GetAppName()
1114         # Return bitmaps folder.
1115         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1116 
1117         #------------
1118 
1119         # Simplified init method.
1120         self.SetProperties()
1121         self.CreateCtrls()
1122         self.BindEvents()
1123 
1124     #-----------------------------------------------------------------------
1125 
1126     def SetProperties(self):
1127         """
1128         ...
1129         """
1130 
1131         self.SetBackgroundColour(wx.Colour(wx.WHITE))
1132 
1133 
1134     def CreateCtrls(self):
1135         """
1136         ...
1137         """
1138 
1139         w, h = self.GetClientSize()
1140         print("MyTitleBarPnl :", self.GetClientSize())
1141 
1142         #------------
1143         #------------
1144 
1145         # Add titleBar.
1146         self.titleBar = MyTitleBar(self,
1147                                    label=self.app_name,
1148                                    size=10)
1149         self.titleBar.SetPosition((0, 0))
1150         self.titleBar.SetSize((w, 31))
1151         self.titleBar.SetLabelColour("black")
1152         self.titleBar.SetToolTip("This is a customized title bar.")
1153 
1154 
1155     def BindEvents(self):
1156         """
1157         Bind some events to an events handler.
1158         """
1159 
1160         self.Bind(wx.EVT_SIZE, self.OnResize)
1161 
1162 
1163     def OnResize(self, event):
1164         """
1165         ...
1166         """
1167 
1168         w, h = self.GetClientSize()
1169         print("MyTitleBarPnl :", self.GetClientSize())
1170 
1171         #------------
1172         #------------
1173 
1174         self.titleBar.SetSize((w, 31))
1175 
1176         #------------
1177 
1178         self.Refresh()
1179 
1180         print("On resize was clicked.")
1181 
1182 #---------------------------------------------------------------------------
1183 
1184 class MyMainPnl(wx.Panel):
1185     """
1186     ...
1187     """
1188     def __init__(self, parent, id, size):
1189         style = (wx.NO_BORDER | wx.TAB_TRAVERSAL)
1190         super(MyMainPnl, self).__init__(parent,
1191                                         id=int(ID_MAIN_PNL),
1192                                         size=size,
1193                                         style=style)
1194 
1195         #------------
1196 
1197         # Attributes.
1198         self.parent = parent
1199 
1200         #------------
1201 
1202         # Return config file.
1203         self.config = wx.GetApp().GetConfig()
1204         # Return bitmaps folder.
1205         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1206         # Return patterns folder.
1207         self.patterns_dir = wx.GetApp().GetPatternsDir()
1208 
1209         #------------
1210 
1211         # Simplified init method.
1212         self.SetProperties()
1213         self.CreateCtrls()
1214         self.BindEvents()
1215         self.DoLayout()
1216 
1217     #-----------------------------------------------------------------------
1218 
1219     def SetProperties(self):
1220         """
1221         ...
1222         """
1223 
1224         if wx.Platform == "__WXMSW__":
1225             self.SetDoubleBuffered(True)
1226 
1227 
1228     def CreateCtrls(self):
1229         """
1230         ...
1231         """
1232 
1233         w, h = self.GetClientSize()
1234         print("MyMainPnl :", self.GetClientSize())
1235 
1236         #------------
1237         #------------
1238 
1239         # Background bitmap.
1240         if SHOW_BACKGROUND:
1241             self.bmp1 = wx.Bitmap(os.path.join(self.patterns_dir,
1242                                                "skin_alu_1.jpg"),
1243                                   type=wx.BITMAP_TYPE_JPEG)
1244             self.backgroundBitmap1 = SBB.MakeDisplaySizeBackgroundBitmap(self.bmp1)
1245 
1246             self.bmp2 = wx.Bitmap(os.path.join(self.patterns_dir,
1247                                                "skin_alu_2.jpg"),
1248                                   type=wx.BITMAP_TYPE_JPEG)
1249             self.backgroundBitmap2 = SBB.MakeDisplaySizeBackgroundBitmap(self.bmp2)
1250 
1251             self.bmp3 = wx.Bitmap(os.path.join(self.patterns_dir,
1252                                                "skin_wood_3.jpg"),
1253                                   type=wx.BITMAP_TYPE_JPEG)
1254             self.backgroundBitmap3 = SBB.MakeDisplaySizeBackgroundBitmap(self.bmp3)
1255 
1256         #------------
1257         #------------
1258 
1259         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
1260         font.SetWeight(wx.BOLD)
1261 
1262         #------------
1263         #------------
1264 
1265         # Create data view control.
1266         self.list = MyListCtrlPnl(self)
1267 
1268         #------------
1269         #------------
1270 
1271         # Thanks to MCOW.
1272         # Button Fullscreen.
1273         self.btn1 = SBB.ShapedBitmapButton(self, ID_BTN_FULLSCREEN,
1274             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
1275                                           "adbRect.png"),
1276                              type=wx.BITMAP_TYPE_PNG),
1277 
1278             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1279                                               "adbRect-pressed.png"),
1280                                  type=wx.BITMAP_TYPE_PNG),
1281 
1282             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1283                                             "adbRect-hover.png"),
1284                                type=wx.BITMAP_TYPE_PNG),
1285 
1286             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1287                                                "adbRect-disabled.png"),
1288                                   type=wx.BITMAP_TYPE_PNG),
1289 
1290             label="Fullscreen",
1291             labelForeColour=wx.WHITE,
1292             labelFont=wx.Font(9,
1293                               wx.FONTFAMILY_DEFAULT,
1294                               wx.FONTSTYLE_NORMAL,
1295                               wx.FONTWEIGHT_BOLD),
1296             style=wx.BORDER_NONE)
1297 
1298         self.btn1.SetFocus() # Necessary for Linux.
1299 
1300         #------------
1301 
1302         # Button About.
1303         self.btn2 = SBB.ShapedBitmapButton(self, ID_BTN_ABOUT,
1304             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
1305                                           "adbRect.png"),
1306                              type=wx.BITMAP_TYPE_PNG),
1307 
1308             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1309                                               "adbRect-pressed.png"),
1310                                  type=wx.BITMAP_TYPE_PNG),
1311 
1312             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1313                                             "adbRect-hover.png"),
1314                                type=wx.BITMAP_TYPE_PNG),
1315 
1316             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1317                                                "adbRect-disabled.png"),
1318                                   type=wx.BITMAP_TYPE_PNG),
1319 
1320             label="About",
1321             labelForeColour=wx.WHITE,
1322             labelFont=wx.Font(9,
1323                               wx.FONTFAMILY_DEFAULT,
1324                               wx.FONTSTYLE_NORMAL,
1325                               wx.FONTWEIGHT_BOLD),
1326             style=wx.BORDER_NONE)
1327 
1328         #------------
1329 
1330         # Button Quit.
1331         self.btn3 = SBB.ShapedBitmapButton(self, ID_BTN_QUIT,
1332             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
1333                                           "adbRect.png"),
1334                              type=wx.BITMAP_TYPE_PNG),
1335 
1336             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1337                                               "adbRect-pressed.png"),
1338                                  type=wx.BITMAP_TYPE_PNG),
1339 
1340             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1341                                             "adbRect-hover.png"),
1342                                type=wx.BITMAP_TYPE_PNG),
1343 
1344             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1345                                                "adbRect-disabled.png"),
1346                                   type=wx.BITMAP_TYPE_PNG),
1347 
1348             label="Quit",
1349             labelForeColour=wx.WHITE,
1350             labelFont=wx.Font(9,
1351                               wx.FONTFAMILY_DEFAULT,
1352                               wx.FONTSTYLE_NORMAL,
1353                               wx.FONTWEIGHT_BOLD),
1354             style=wx.BORDER_NONE)
1355 
1356         #------------
1357         #------------
1358 
1359         self.line = wx.StaticLine(self, -1,
1360                                   pos=(0, 70),
1361                                   size=(-1, -1),
1362                                   style=wx.LI_HORIZONTAL)
1363 
1364         #------------
1365         #------------
1366 
1367         # Create a panel widget for the pattern.
1368         self.test = wx.Panel(self,
1369                              -1,
1370                              pos=(-1, -1),
1371                              size=(131, 20),
1372                              style=wx.BORDER_SUNKEN)
1373         self.test.Enable(False)    # Delete focus.
1374 
1375         #------------
1376         #------------
1377 
1378         # Create a StaticBitmap widget for the test panel.
1379         self.picture = wx.StaticBitmap(self.test)
1380         # Read config file.
1381         self.picture.SetBitmap(wx.Bitmap(os.path.join(self.patterns_dir,
1382                                                       self.config.Read("Image1"))))
1383 
1384         #------------
1385         #------------
1386 
1387         # Create a background image list.
1388         self.images = ['skin_alu_1.jpg',
1389                        'skin_alu_2.jpg',
1390                        'skin_wood_3.jpg']
1391         self.images.sort()
1392 
1393         # Create a choice widget.
1394         self.choice = wx.Choice(self,
1395                                 -1,
1396                                 pos=(-1, -1),
1397                                 size=(131, -1),
1398                                 choices=self.images)
1399 
1400         # Select item 2 in choice list to show.
1401         # self.choice.SetSelection(2)  # skin_wood_3
1402         # Read config file.
1403         self.choice.SetSelection(self.config.ReadInt("Item1"))
1404 
1405         item = self.choice.GetCurrentSelection()
1406         bgImg = self.choice.GetStringSelection()
1407         print("Item : %s , %s" % (item, bgImg))
1408 
1409 
1410     def DoLayout(self):
1411         """
1412         ...
1413         """
1414 
1415         txtSizer = wx.BoxSizer(wx.VERTICAL)
1416 
1417         sizerList = wx.BoxSizer(wx.VERTICAL)
1418         sizerList.Add(self.list, 1,
1419                       wx.LEFT|wx.TOP|wx.BOTTOM|
1420                       wx.EXPAND|wx.ALIGN_TOP, 10)
1421 
1422         sizer = wx.BoxSizer(wx.VERTICAL)
1423         sizer.Add(txtSizer, 0, wx.BOTTOM, 15)
1424         sizer.Add(self.btn1, 1, wx.ALL, 10)
1425         sizer.Add(self.btn2, 1, wx.ALL, 10)
1426         sizer.Add(self.line, 0, wx.EXPAND|wx.ALL, 10)
1427         sizer.Add(self.test, 0, wx.ALL, 10)
1428         sizer.Add(self.choice, 0, wx.ALL, 10)
1429         sizer.Add(self.btn3, 1, wx.ALL, 10)
1430 
1431         mainSizer = wx.BoxSizer(wx.HORIZONTAL)
1432         mainSizer.Add(sizerList, 1,
1433                       wx.LEFT|wx.TOP|wx.BOTTOM|wx.EXPAND, 5)
1434         mainSizer.Add(sizer, 0, wx.ALIGN_BOTTOM|wx.ALL, 5)
1435 
1436         self.SetSizer(mainSizer)
1437         self.Layout()
1438 
1439 
1440     def BindEvents(self):
1441         """
1442         Bind some events to an events handler.
1443         """
1444 
1445         self.Bind(wx.EVT_PAINT, self.OnPaint)
1446         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
1447         self.Bind(wx.EVT_CHOICE, self.OnChoice)
1448 
1449         self.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_MAIN_PNL)
1450         self.btn1.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_BTN_FULLSCREEN)
1451         self.btn2.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_BTN_ABOUT)
1452         self.btn3.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_BTN_QUIT)
1453 
1454         self.btn1.Bind(wx.EVT_BUTTON, self.OnFullScreen)
1455         self.btn2.Bind(wx.EVT_BUTTON, self.OnAbout)
1456         self.btn3.Bind(wx.EVT_BUTTON, self.OnBtnClose)
1457 
1458 
1459     def OnInfo(self, event):
1460         """
1461         ...
1462         """
1463 
1464         event_id = event.GetId()
1465 
1466         if event_id == ID_MAIN_PNL:
1467             self.GetParent().SetStatusText(text="Hello world !")
1468 
1469         elif event_id == ID_BTN_FULLSCREEN:
1470             self.GetParent().SetStatusText(text="Fullscreen")
1471 
1472         elif event_id == ID_BTN_ABOUT:
1473             self.GetParent().SetStatusText(text="About")
1474 
1475         elif event_id == ID_BTN_QUIT:
1476             self.GetParent().SetStatusText(text="Quit the program")
1477 
1478         else:
1479             # Tell the event system to continue
1480             # looking for an event handler, so the
1481             # default handler will get called.
1482             event.Skip()
1483 
1484 
1485     def OnChoice(self, event):
1486         """
1487         ...
1488         """
1489 
1490         item = event.GetSelection()
1491         bgImg = self.choice.GetStringSelection()
1492         print("New item : %s , %s" % (item, bgImg))
1493 
1494         self.picture.SetFocus()
1495 
1496         # Thanks to ZetCode.
1497         # self.picture.SetBitmap(wx.Bitmap('bitmaps/' + self.images[item]))
1498         self.picture.SetBitmap(wx.Bitmap(os.path.join(self.patterns_dir,
1499                                                       self.images[item])))
1500 
1501         frame = self.GetTopLevelParent()
1502         if item == 0:
1503             frame.SetBackgroundColour(wx.Colour("GREY95"))  #a6a6a6
1504             self.config.Write("Color1", "GREY95")  #a6a6a6
1505         elif item == 1:
1506             frame.SetBackgroundColour(wx.Colour("GREY95"))  #c0c0c1
1507             self.config.Write("Color1", "GREY95")  #c0c0c1
1508         elif item == 2:
1509             frame.SetBackgroundColour(wx.Colour("GREY95"))  #9f794c
1510             self.config.Write("Color1", "GREY95")  #9f794c
1511 
1512         # Write config file.
1513         self.config.WriteInt("Item1", self.choice.GetCurrentSelection())
1514         self.config.Write("Image1", self.choice.GetStringSelection())
1515         self.config.Flush()
1516 
1517         self.Refresh()
1518 
1519         print("OnChoice button was clicked.")
1520 
1521 
1522     def OnAbout(self, event):
1523         """
1524         ...
1525         """
1526 
1527         self.GetParent().OnAbout(self)
1528 
1529         print("FullScreen button was clicked.")
1530 
1531 
1532     def OnFullScreen(self, event):
1533         """
1534         ...
1535         """
1536 
1537         self.GetParent().OnFullScreen(self)
1538 
1539         print("FullScreen button was clicked.")
1540 
1541 
1542     def OnBtnClose(self, event):
1543         """
1544         ...
1545         """
1546 
1547         self.GetParent().OnCloseWindow(self)
1548 
1549         print("Close button was clicked.")
1550 
1551 
1552     def TileBackground(self, dc):
1553         """
1554         Tile the background bitmap.
1555         """
1556 
1557         item = self.choice.GetSelection()
1558 
1559         sz = self.GetClientSize()
1560 
1561         if item <=2:
1562             w = self.bmp3.GetWidth()
1563             h = self.bmp3.GetHeight()
1564             x = 0
1565 
1566             while x < sz.width:
1567                 y = 0
1568 
1569                 while y < sz.height:
1570                     if item == 0:
1571                         dc.DrawBitmap(self.bmp1, x, y)
1572                         #parentBgBmp=self.backgroundBitmap1
1573                         self.btn1.SetParentBackgroundBitmap(self.backgroundBitmap1)
1574                         self.btn2.SetParentBackgroundBitmap(self.backgroundBitmap1)
1575                         self.btn3.SetParentBackgroundBitmap(self.backgroundBitmap1)
1576                         y = y + h
1577 
1578                     elif item == 1:
1579                         dc.DrawBitmap(self.bmp2, x, y)
1580                         #parentBgBmp=self.backgroundBitmap2
1581                         self.btn1.SetParentBackgroundBitmap(self.backgroundBitmap2)
1582                         self.btn2.SetParentBackgroundBitmap(self.backgroundBitmap2)
1583                         self.btn3.SetParentBackgroundBitmap(self.backgroundBitmap2)
1584                         y = y + h
1585 
1586                     elif item == 2:
1587                         dc.DrawBitmap(self.bmp3, x, y)
1588                         #parentBgBmp=self.backgroundBitmap3
1589                         self.btn1.SetParentBackgroundBitmap(self.backgroundBitmap3)
1590                         self.btn2.SetParentBackgroundBitmap(self.backgroundBitmap3)
1591                         self.btn3.SetParentBackgroundBitmap(self.backgroundBitmap3)
1592                         y = y + h
1593 
1594                 x = x + w
1595 
1596         w, h = self.GetClientSize()
1597 
1598         dc.SetFont(wx.Font(9, wx.MODERN, wx.NORMAL, wx.BOLD, False, "Tahoma"))
1599         label = "Hello World !"
1600         width, height = self.GetTextExtent(label)
1601         dc.DrawText(label, int((w-width)-75), int((h-height)-270))
1602 
1603 
1604     def OnEraseBackground(self, event):
1605         """
1606         Redraw the background over a "damaged" area.
1607         """
1608 
1609         dc = event.GetDC()
1610 
1611         if not dc:
1612             dc = wx.ClientDC(self)
1613             rect = self.GetUpdateRegion().GetBox()
1614             dc.SetClippingRegion(rect)
1615 
1616         self.TileBackground(dc)
1617 
1618 
1619     def OnPaint(self, event):
1620         """
1621         ...
1622         """
1623 
1624         while True:
1625             try:
1626                 dc = wx.BufferedPaintDC(self)
1627                 self.TileBackground(dc)
1628                 break
1629             except (RuntimeError):
1630                 wx.Exit()
1631 
1632 #---------------------------------------------------------------------------
1633 
1634 class MyFrame(wx.Frame):
1635     """
1636     Thanks to Robin Dunn.
1637     """
1638     def __init__(self):
1639         style = (wx.CLIP_CHILDREN | wx.CLOSE_BOX |
1640                  wx.MINIMIZE_BOX | wx.SYSTEM_MENU |
1641                  wx.BORDER_SIMPLE | wx.NO_FULL_REPAINT_ON_RESIZE|
1642                  wx.STAY_ON_TOP)
1643         super(MyFrame, self).__init__(None,
1644                                       -1,
1645                                       title="",
1646                                       style=style)
1647 
1648         #------------
1649 
1650         wx.SystemOptions.SetOption("msw.remap", "0")
1651 
1652         #------------
1653 
1654         # Attributes.
1655         self.SetTransparent(0)
1656         self.opacity_in = 0
1657         self.opacity_out = 255
1658         self.deltaN = -70
1659         self.delta = wx.Point(0,0)
1660 
1661         #------------
1662 
1663         # Return config file.
1664         self.config = wx.GetApp().GetConfig()
1665         # Return application name.
1666         self.app_name = wx.GetApp().GetAppName()
1667         # Return bitmaps folder.
1668         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1669         # Return icons folder.
1670         self.icons_dir = wx.GetApp().GetIconsDir()
1671 
1672         #------------
1673 
1674         # Colourdb.
1675         wx.lib.colourdb.updateColourDB()
1676 
1677         # Create a colour list from the colourdb database.
1678         self.colour_list = wx.lib.colourdb.getColourList()
1679 
1680         #------------
1681 
1682         # Simplified init method.
1683         self.SetProperties()
1684         self.OnTimerIn(self)
1685         self.CreateMenu()
1686         self.CreateStatusBar()
1687         self.CreateCtrls()
1688         self.BindEvents()
1689         self.DoLayout()
1690 
1691         #------------
1692 
1693         # Thanks to Ray Pasco.
1694         # Initialize to the current state.
1695         self.unrolledFrameClientSize_size = self.GetClientSize()
1696         self.isRolled = False
1697 
1698         #------------
1699 
1700         self.CenterOnScreen(wx.BOTH)
1701 
1702         #------------
1703 
1704         self.Show(True)
1705 
1706     #-----------------------------------------------------------------------
1707 
1708     def SetProperties(self):
1709         """
1710         ...
1711         """
1712 
1713         # Read config file.
1714         self.SetBackgroundColour(self.config.Read("Color1"))
1715         self.SetTitle(self.app_name)
1716         self.SetClientSize((600, 380))
1717         self.SetMinSize((128, 82))
1718 
1719         #------------
1720 
1721         frameIcon = wx.Icon(os.path.join(self.icons_dir,
1722                                          "icon_wxWidgets.ico"),
1723                             type=wx.BITMAP_TYPE_ICO)
1724         self.SetIcon(frameIcon)
1725 
1726 
1727     def OnTimerIn(self, evt):
1728         """
1729         Thanks to Pascal Faut.
1730         """
1731 
1732         self.timer1 = wx.Timer(self, -1)
1733         self.timer1.Start(1)
1734         self.Bind(wx.EVT_TIMER, self.AlphaCycle1, self.timer1)
1735 
1736         print("Fade-in was launched.")
1737 
1738 
1739     def OnTimerOut(self, evt):
1740         """
1741         Thanks to Pascal Faut.
1742         """
1743 
1744         self.timer2 = wx.Timer(self, -1)
1745         self.timer2.Start(1)
1746         self.Bind(wx.EVT_TIMER, self.AlphaCycle2, self.timer2)
1747 
1748         print("Fade-out was launched.")
1749 
1750 
1751     def AlphaCycle1(self, *args):
1752         """
1753         Thanks to Pascal Faut.
1754         """
1755 
1756         self.opacity_in += self.deltaN
1757         if self.opacity_in <= 0:
1758             self.deltaN = -self.deltaN
1759             self.opacity_in = 0
1760 
1761         if self.opacity_in >= 255:
1762             self.deltaN = -self.deltaN
1763             self.opacity_in = 255
1764 
1765             self.timer1.Stop()
1766 
1767         self.SetTransparent(self.opacity_in)
1768 
1769         print("Fade in = {}/255".format(self.opacity_in))
1770 
1771 
1772     def AlphaCycle2(self, *args):
1773         """
1774         Thanks to Pascal Faut.
1775         """
1776 
1777         self.opacity_out += self.deltaN
1778         if self.opacity_out >= 255:
1779             self.deltaN = -self.deltaN
1780             self.opacity_out = 255
1781 
1782         if self.opacity_out <= 0:
1783             self.deltaN = -self.deltaN
1784             self.opacity_out = 0
1785 
1786             self.timer2.Stop()
1787             wx.CallAfter(self.Destroy)
1788             wx.Exit()
1789 
1790         self.SetTransparent(self.opacity_out)
1791 
1792         print("Fade out = {}/255".format(self.opacity_out))
1793 
1794 
1795     def CreateMenu(self):
1796         """
1797         ...
1798         """
1799 
1800         # FlatMenuBar.
1801         self.menuBar = FM.FlatMenuBar(self,
1802                                       wx.ID_ANY,
1803                                       32, 4,
1804                                       options=FM.FM_OPT_IS_LCD)
1805 
1806         # FM.StyleDefault or FM.Style2007
1807         # FM.StyleXP or FM.StyleVista
1808         self.newMyTheme = self.menuBar.GetRendererManager().AddRenderer(MyMenuRenderer())
1809         self.menuBar.GetRendererManager().SetTheme(self.newMyTheme)
1810 
1811         #------------
1812 
1813         # Set an icon to the exit/help menu item.
1814         exitImg = wx.Bitmap(os.path.join(self.bitmaps_dir,
1815                                          "item_exit.png"),
1816                             type=wx.BITMAP_TYPE_PNG)
1817 
1818         helpImg = wx.Bitmap(os.path.join(self.bitmaps_dir,
1819                                          "item_about.png"),
1820                             type=wx.BITMAP_TYPE_PNG)
1821 
1822         #------------
1823         #------------
1824 
1825         # File Menu.
1826         self.file_menu = FM.FlatMenu()
1827 
1828         # Create the menu items.
1829         item = FM.FlatMenuItem(self.file_menu,
1830                                ID_FULLSCREEN,
1831                                "&Fullscreen\tCtrl+F",
1832                                "Fullscreen",
1833                                wx.ITEM_NORMAL,
1834                                None)
1835         item.SetTextColour("black")
1836         self.file_menu.AppendItem(item)
1837         self.file_menu.AppendSeparator()
1838 
1839 
1840         item = FM.FlatMenuItem(self.file_menu,
1841                                wx.ID_EXIT,
1842                                "&Quit\tCtrl+Q",
1843                                "Quit the program",
1844                                wx.ITEM_NORMAL,
1845                                None,
1846                                exitImg)
1847         # Demonstrate how to set custom font
1848         # and text colour to a FlatMenuItem.
1849         item.SetFont(wx.Font(-1, wx.FONTFAMILY_DEFAULT,
1850                              wx.FONTSTYLE_NORMAL,
1851                              wx.FONTWEIGHT_BOLD,
1852                              False, ""))
1853         item.SetTextColour("#d34725")
1854 
1855         self.file_menu.AppendItem(item)
1856 
1857         #------------
1858 
1859         # Add Create background bitmap.
1860         self.file_menu.SetBackgroundBitmap(CreateBackgroundBitmap())
1861 
1862         #------------
1863         #------------
1864 
1865         # Help Menu.
1866         self.help_menu = FM.FlatMenu()
1867 
1868         # Create the menu items.
1869         item = FM.FlatMenuItem(self.help_menu,
1870                                wx.ID_ABOUT,
1871                                "&About\tCtrl+A",
1872                                "About",
1873                                wx.ITEM_NORMAL,
1874                                None,
1875                                helpImg)
1876         item.SetTextColour("black")
1877         self.help_menu.AppendItem(item)
1878         self.help_menu.AppendSeparator()
1879 
1880         item = FM.FlatMenuItem(self.help_menu,
1881                                ID_HELLO,
1882                                "Hello !",
1883                                "Hello !",
1884                                wx.ITEM_NORMAL,
1885                                None)
1886         item.SetTextColour("black")
1887         self.help_menu.AppendItem(item)
1888 
1889         #------------
1890 
1891         # Add Create background bitmap.
1892         self.help_menu.SetBackgroundBitmap(CreateBackgroundBitmap())
1893 
1894         #------------
1895         #------------
1896 
1897         # Menu background color.
1898         self.menuBar.SetBackgroundColour(wx.Colour("GREY95"))
1899 
1900         # Add menu to the menu bar.
1901         self.menuBar.Append(self.file_menu, "&File")
1902         self.menuBar.Append(self.help_menu, "&Help")
1903 
1904 
1905     def CreateStatusBar(self):
1906         """
1907         ...
1908         """
1909 
1910         self.sb = MyStatusBar(self, -1)
1911         self.sb.SetBackgroundColour(wx.Colour(wx.WHITE))
1912         self.sb.SetStatusText("Hello world !")
1913 
1914         self.SetStatusBar(self.sb)
1915 
1916 
1917     def CreateCtrls(self):
1918         """
1919         ...
1920         """
1921 
1922         w, h = self.GetClientSize()
1923         print("MyFrame :", self.GetClientSize())
1924 
1925         #------------
1926         #------------
1927 
1928         self.titleBarPnl = MyTitleBarPnl(self, -1, (w, 31))
1929         self.titleBarPnl.SetPosition((0, 0))
1930         print("self.titleBarPnl :", self.titleBarPnl.GetSize())
1931 
1932         #------------
1933 
1934         # self.line = wx.StaticLine(self, -1,
1935         #                          pos=(0, 70),
1936         #                          size=(-1, -1),
1937         #                          style=wx.LI_HORIZONTAL)
1938 
1939         #------------
1940 
1941         self.mainPnl = MyMainPnl(self, -1, (w, h-24))
1942         self.mainPnl.SetPosition((0, 24))
1943         print("self.mainPnl :", self.mainPnl.GetSize())
1944 
1945 
1946     def BindEvents(self):
1947         """
1948         ...
1949         """
1950 
1951         self.titleBarPnl.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
1952 
1953         self.Bind(wx.EVT_SIZE, self.OnResize)
1954         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
1955         self.Bind(wx.EVT_MOTION, self.OnMouseMove)
1956         self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyUp)
1957         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1958 
1959         self.Bind(wx.EVT_MENU, self.OnFullScreen, id=ID_FULLSCREEN)
1960         self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
1961         self.Bind(wx.EVT_MENU, self.OnCloseWindow, id=wx.ID_EXIT)
1962 
1963 
1964     def DoLayout(self):
1965         """
1966         ...
1967         """
1968 
1969         # MainSizer is the top-level one that manages everything.
1970         mainSizer = wx.BoxSizer(wx.VERTICAL)
1971 
1972         mbSizer = wx.BoxSizer(wx.HORIZONTAL)
1973         mbSizer.Add(self.menuBar, 1, wx.ALL, 0)
1974 
1975         mainSizer.Add(self.titleBarPnl, 1, wx.EXPAND, 0)
1976         # mainSizer.Add(self.line, 0, wx.EXPAND, 0)
1977         mainSizer.Add(mbSizer, 0, wx.EXPAND, 0)
1978         mainSizer.Add(self.mainPnl, 1, wx.EXPAND, 0)
1979 
1980         # Finally, tell the panel to use the sizer for layout.
1981         self.SetSizer(mainSizer)
1982         self.Layout()
1983 
1984 
1985     def OnRoll(self, event) :
1986         """
1987         Thanks to Ray Pasco.
1988         """
1989 
1990         if not bool(self.isRolled) :
1991         # Set the flag to the state we want regardless of whether
1992         # or not it's in currently in the opposite state.
1993            self.RollUnRoll(wantToRoll=True)
1994 
1995         elif self.isRolled :   # UnRoll.
1996            # Set the flag to the state we want regardless of whether
1997            # or not it's in currently in the opposite state.
1998            self.RollUnRoll(wantToRoll=False)
1999 
2000         print("OnRoll :", self.GetClientSize())
2001 
2002 
2003     def RollUnRoll(self, wantToRoll) :
2004         """
2005         Thanks to Ray Pasco.
2006         """
2007 
2008         # Save the current size only if the Frame is not rolled up.
2009         if not bool(self.isRolled) :
2010             self.unrolledFrameClientSize_size = self.GetClientSize()
2011 
2012         if bool(wantToRoll) :   # UnRoll.
2013             # Set size (56).
2014             self.SetClientSize((self.unrolledFrameClientSize_size[0], 55))
2015             # Set to match this new state.
2016             self.isRolled = True
2017 
2018         else :   # Roll
2019             self.SetClientSize(self.unrolledFrameClientSize_size)
2020             # Set to match this new state.
2021             self.isRolled = False
2022 
2023         print("RollUnRoll :", self.GetClientSize())
2024 
2025 
2026     def OnAbout(self, event):
2027         """
2028         ...
2029         """
2030 
2031         self.dialog = MyAboutDlg(self)
2032 
2033 
2034     def OnLeftDown(self, event):
2035         """
2036         ...
2037         """
2038 
2039         self.CaptureMouse()
2040         x, y = self.ClientToScreen(event.GetPosition())
2041         originx, originy = self.GetPosition()
2042         dx = x - originx
2043         dy = y - originy
2044         self.delta = ((dx, dy))
2045 
2046 
2047     def OnLeftUp(self, evt):
2048         """
2049         ...
2050         """
2051 
2052         if self.HasCapture():
2053             self.ReleaseMouse()
2054 
2055 
2056     def OnMouseMove(self, event):
2057         """
2058         ...
2059         """
2060 
2061         if event.Dragging() and event.LeftIsDown():
2062             x, y = self.ClientToScreen(event.GetPosition())
2063             fp = (x - self.delta[0], y - self.delta[1])
2064             self.Move(fp)
2065 
2066 
2067     def OnIconfiy(self, event):
2068         """
2069         ...
2070         """
2071 
2072         self.Iconize()
2073 
2074 
2075     def OnResize(self, event):
2076         """
2077         ...
2078         """
2079 
2080         w, h = self.GetClientSize()
2081         print("self :", self.GetClientSize())
2082 
2083         #------------
2084         #------------
2085 
2086         self.titleBarPnl.SetSize((w, 31))
2087         # self.line.SetSize((w, -1))
2088         self.menuBar.SetSize((w, -1))
2089         self.mainPnl.SetSize((w, h-55))
2090 
2091         #------------
2092 
2093         self.Refresh()
2094 
2095 
2096     def OnFullScreen(self, event):
2097         """
2098         ...
2099         """
2100 
2101         self.ShowFullScreen(not self.IsFullScreen(),
2102                             wx.FULLSCREEN_NOCAPTION)
2103 
2104 
2105     def OnKeyUp(self, event):
2106         """
2107         ...
2108         """
2109 
2110         if event.GetKeyCode() == wx.WXK_ESCAPE:
2111             # Close the frame, no action.
2112             self.OnCloseWindow(event)
2113         event.Skip()
2114 
2115 
2116     def OnBtnClose(self, event):
2117         """
2118         ...
2119         """
2120 
2121         self.Close()
2122 
2123 
2124     def OnCloseWindow(self, event):
2125         """
2126         Quit this application.
2127         """
2128 
2129         # self.Destroy()
2130         self.OnTimerOut(self)
2131 
2132         print("Exit application.")
2133 
2134 #---------------------------------------------------------------------------
2135 
2136 class MyApp(wx.App):
2137     """
2138     Thanks to Andrea Gavana.
2139     """
2140     def OnInit(self):
2141 
2142         #------------
2143 
2144         self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
2145 
2146         #------------
2147 
2148         self.SetAppName("Custom Gui 1")
2149 
2150         #------------
2151 
2152         self.installDir = os.path.split(os.path.abspath(sys.argv[0]))[0]
2153 
2154         #------------
2155 
2156         frame = MyFrame()
2157         self.SetTopWindow(frame)
2158         frame.Show(True)
2159 
2160         return True
2161 
2162     #-----------------------------------------------------------------------
2163 
2164     def GetInstallDir(self):
2165         """
2166         Returns the installation directory for my application.
2167         """
2168 
2169         return self.installDir
2170 
2171 
2172     def GetIconsDir(self):
2173         """
2174         Returns the icons directory for my application.
2175         """
2176 
2177         icons_dir = os.path.join(self.installDir, "icons")
2178         return icons_dir
2179 
2180 
2181     def GetBitmapsDir(self):
2182         """
2183         Returns the bitmaps directory for my application.
2184         """
2185 
2186         bitmaps_dir = os.path.join(self.installDir, "bitmaps")
2187         return bitmaps_dir
2188 
2189 
2190     def GetPatternsDir(self):
2191         """
2192         Returns the patterns directory for my application.
2193         """
2194 
2195         patterns_dir = os.path.join(self.installDir, "patterns")
2196         return patterns_dir
2197 
2198 
2199     def GetConfig(self):
2200         """
2201         Returns the config file for my application.
2202         """
2203 
2204         config = wx.FileConfig(appName="Custom Gui",
2205                                localFilename=os.path.join(self.installDir,
2206                                                           "options"))
2207         return config
2208 
2209 #---------------------------------------------------------------------------
2210 
2211 def main():
2212     app = MyApp(False)
2213     app.MainLoop()
2214 
2215 #---------------------------------------------------------------------------
2216 
2217 if __name__ == "__main__" :
2218     main()


Second possibility

img_sample_two.png

   1 # sample_two.py
   2 
   3 import sys
   4 import os
   5 import platform
   6 import wx
   7 import wx.lib.fancytext as fancytext
   8 import wx.lib.agw.flatmenu as FM
   9 from   wx.lib.agw.artmanager import ArtManager, RendererBase, DCSaver
  10 from   wx.lib.agw.fmresources import ControlFocus, ControlPressed
  11 import wx.lib.mixins.listctrl as listmix
  12 import wx.dataview as dv
  13 import wx.lib.colourdb
  14 import rectshapedbitmapbutton as SBB
  15 import rectshapedbitmapbuttonTwo as SBBTwo
  16 import data
  17 
  18 musicdata = sorted(data.musicdata.items())
  19 musicdata = [[str(k)] + list(v) for k,v in musicdata]
  20 
  21 # def SwitchRGBtoBGR
  22 # def CreateBackgroundBitmap
  23 # class MyMenuRenderer
  24 # class MyListCtrl
  25 # class MyListCtrlPnl
  26 # class MyStatusBar
  27 # class MyTitleBar
  28 # class MyAboutDlg
  29 # class MyPopupMenu
  30 # class MyTitleBarPnl
  31 # class ImageBackground
  32 # class MyMainPnl
  33 # class MyFrame
  34 # class MyApp
  35 
  36 SHOW_BACKGROUND = 1
  37 
  38 ID_MAIN_PNL = wx.NewIdRef()
  39 ID_FULLSCREEN = wx.NewIdRef()
  40 ID_BTN_FULLSCREEN = wx.NewIdRef()
  41 ID_BTN_ABOUT = wx.NewIdRef()
  42 ID_BTN_QUIT = wx.NewIdRef()
  43 ID_HELLO = wx.NewIdRef()
  44 
  45 #---------------------------------------------------------------------------
  46 
  47 def SwitchRGBtoBGR(colour):
  48     """
  49     ...
  50     """
  51 
  52     return wx.Colour(colour.Blue(), colour.Green(), colour.Red())
  53 
  54 #---------------------------------------------------------------------------
  55 
  56 def CreateBackgroundBitmap():
  57     """
  58     ...
  59     """
  60 
  61     mem_dc = wx.MemoryDC()
  62     bmp = wx.Bitmap(121, 300)
  63     mem_dc.SelectObject(bmp)
  64 
  65     mem_dc.Clear()
  66 
  67     # Colour the menu face with background colour.
  68     mem_dc.SetPen(wx.Pen("#a0a0a0", 0))
  69     mem_dc.SetBrush(wx.Brush("grey"))
  70     mem_dc.DrawRectangle(0, 15, 121, 300)
  71     mem_dc.DrawLine(0, 0, 300, 0)
  72 
  73     mem_dc.SelectObject(wx.NullBitmap)
  74     return bmp
  75 
  76 #---------------------------------------------------------------------------
  77 
  78 class MyMenuRenderer(FM.FMRenderer):
  79     """
  80     Thanks to Andrea Gavana.
  81     A custom renderer class for FlatMenu.
  82     """
  83     def __init__(self):
  84         FM.FMRenderer.__init__(self)
  85 
  86     #-----------------------------------------------------------------------
  87 
  88     def DrawMenuButton(self, dc, rect, state):
  89         """
  90         Draws the highlight on a FlatMenu.
  91         """
  92 
  93         self.DrawButton(dc, rect, state)
  94 
  95 
  96     def DrawMenuBarButton(self, dc, rect, state):
  97         """
  98         Draws the highlight on a FlatMenuBar.
  99         """
 100 
 101         self.DrawButton(dc, rect, state)
 102 
 103 
 104     def DrawButton(self, dc, rect, state, colour=None):
 105         """
 106         ...
 107         """
 108 
 109         if state == ControlFocus:
 110             penColour = SwitchRGBtoBGR(ArtManager.Get().FrameColour())
 111             brushColour = SwitchRGBtoBGR(ArtManager.Get().BackgroundColour())
 112         elif state == ControlPressed:
 113             penColour = SwitchRGBtoBGR(ArtManager.Get().FrameColour())
 114             brushColour = SwitchRGBtoBGR(ArtManager.Get().HighlightBackgroundColour())
 115         else:   # ControlNormal, ControlDisabled, default.
 116             penColour = SwitchRGBtoBGR(ArtManager.Get().FrameColour())
 117             brushColour = SwitchRGBtoBGR(ArtManager.Get().BackgroundColour())
 118 
 119         # Draw the button borders.
 120         dc = wx.GCDC(dc)
 121         dc.SetPen(wx.Pen(penColour))
 122         dc.SetBrush(wx.Brush(brushColour))
 123         dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height-3, 6)
 124 
 125 
 126     def DrawMenuBarBackground(self, dc, rect):
 127         """
 128         ...
 129         """
 130 
 131         # For office style, we simple draw a rectangle
 132         # with a gradient colouring.
 133         vertical = ArtManager.Get().GetMBVerticalGradient()
 134 
 135         dcsaver = DCSaver(dc)
 136 
 137         # Fill with gradient.
 138         startColour = self.menuBarFaceColour
 139         endColour   = ArtManager.Get().LightColour(startColour, 0)
 140 
 141         dc.SetPen(wx.Pen(endColour))
 142         dc.SetBrush(wx.Brush(endColour))
 143         dc.DrawRectangle(rect)
 144 
 145 
 146     def DrawToolBarBg(self, dc, rect):
 147         """
 148         ...
 149         """
 150 
 151         if not ArtManager.Get().GetRaiseToolbar():
 152             return
 153 
 154         # Fill with gradient.
 155         startColour = self.menuBarFaceColour()
 156         dc.SetPen(wx.Pen(startColour))
 157         dc.SetBrush(wx.Brush(startColour))
 158         dc.DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight())
 159 
 160 #---------------------------------------------------------------------------
 161 
 162 class MyListCtrlPnl(wx.Panel):
 163     """
 164     Thanks to Robin Dunn.
 165     """
 166     def __init__(self, parent):
 167         wx.Panel.__init__(self, parent, -1)
 168 
 169         # Create the listctrl.
 170         self.dvlc = dv.DataViewListCtrl(self,
 171                                         style=wx.BORDER_SIMPLE|
 172                                               dv.DV_ROW_LINES|
 173                                               dv.DV_HORIZ_RULES|
 174                                               dv.DV_VERT_RULES)
 175 
 176         # Give it some columns.
 177         # The ID col we'll customize a bit :
 178         self.dvlc.AppendTextColumn("Id", width=40)
 179         self.dvlc.AppendTextColumn("Artist", width=170)
 180         self.dvlc.AppendTextColumn("Title", width=260)
 181         self.dvlc.AppendTextColumn("Genre", width=80)
 182 
 183         # Load the data. Each item (row) is added as a sequence
 184         # of values whose order matches the columns.
 185         for itemvalues in musicdata:
 186             self.dvlc.AppendItem(itemvalues)
 187 
 188         self.dvlc.SetBackgroundColour("#c9f72b")
 189         self.dvlc.SetForegroundColour("black")
 190 
 191         # Set the layout so the listctrl fills the panel.
 192         self.Sizer = wx.BoxSizer()
 193         self.Sizer.Add(self.dvlc, 1, wx.EXPAND)
 194 
 195 #---------------------------------------------------------------------------
 196 
 197 class MyStatusBar(wx.StatusBar) :
 198     """
 199     Thanks to ???.
 200     Simple custom colorized StatusBar.
 201     """
 202     def __init__(self, parent, id) :
 203         wx.StatusBar.__init__(self, parent, id)
 204 
 205         #------------
 206 
 207         # Return config file.
 208         self.config = wx.GetApp().GetConfig()
 209 
 210         #------------
 211 
 212         # Simplified init method.
 213         self.SetProperties()
 214         self.BindEvents()
 215 
 216     #-----------------------------------------------------------------------
 217 
 218     def SetProperties(self):
 219         """
 220         ...
 221         """
 222 
 223         # Read config file.
 224         self.SetBackgroundColour(wx.Colour(self.config.Read("Color2")))
 225 
 226 
 227     def BindEvents(self):
 228         """
 229         Bind some events to an events handler.
 230         """
 231 
 232         self.Bind(wx.EVT_PAINT, self.OnPaint)
 233 
 234 
 235     def OnPaint(self, event) :
 236         """
 237         ...
 238         """
 239 
 240         dc = wx.BufferedPaintDC(self)
 241         self.Draw(dc)
 242 
 243 
 244     def Draw(self, dc) :
 245         """
 246         ...