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


Third example

img_sample_three.png

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


Download source

source.zip


Additional Information

Link :

https://hasenj.wordpress.com/2009/04/14/making-a-fancy-window-in-wxpython/

https://stackoverflow.com/questions/17479254/panel-doesnt-fully-refresh-when-using-a-custom-background-in-wxpython

https://stackoverflow.com/questions/12087140/custom-window-frame-and-window-appearance-with-wxpython

https://github.com/Metallicow/MCOW

https://github.com/Eseeme/wxpython-custom-button

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Robin Dunn, Cody Precord, Andrea Gavana, Metallicow, Mike Driscoll, Ray Pasco, Pascal Faut., Vegaseat (DaniWeb), Jan Bodnar (ZetCode), Alain Delgrange, Daniel Ramos, ActiveState, the wxPython community...

Thanks also to all known contributors or anonymous that I forgot.

And finally, congratulations to the many forums and blogs for all the available examples and the help which is the strength of wxPython. ;)


About this page

Date (d/m/y) Person (bot) Comments :

10/10/18 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a customized frame - Part 4 (Phoenix) (last edited 2020-12-13 18:17:16 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.