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