How to create a customized frame - Part 2 (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 colored panel :

First example

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


Second example

img_sample_two.png

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

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