Create a customized frame - Part 3 (Phoenix)

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


Demonstrating (only Windows) :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

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


Frame without resize border and 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 rndshapedbitmapbutton 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("#a19f94"))
  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         self.dvlc.SetBackgroundColour("gray50")
 185         self.dvlc.SetForegroundColour("gray10")
 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(wx.BLACK)
 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.NO_BORDER)
 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 += 4
 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 config file.
 500         self.config = wx.GetApp().GetConfig()
 501         # Return application name.
 502         self.app_name = wx.GetApp().GetAppName()
 503         # Return bitmaps folder.
 504         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
 505         # Return icons folder.
 506         self.icons_dir = wx.GetApp().GetIconsDir()
 507 
 508         #------------
 509 
 510         # Simplified init method.
 511         self.SetProperties()
 512         self.OnTimerIn(self)
 513         self.CreateCtrls()
 514         self.BindEvents()
 515 
 516         #------------
 517 
 518         self.CenterOnParent(wx.BOTH)
 519         self.GetParent().Enable(False)
 520 
 521         #------------
 522 
 523         self.Show(True)
 524 
 525         #------------
 526 
 527         self.eventLoop = wx.GUIEventLoop()
 528         self.eventLoop.Run()
 529 
 530     #-----------------------------------------------------------------------
 531 
 532     def SetProperties(self):
 533         """
 534         Set the dialog properties (title, icon, transparency...).
 535         """
 536 
 537         frameIcon = wx.Icon(os.path.join(self.icons_dir,
 538                                          "icon_wxWidgets.ico"),
 539                             type=wx.BITMAP_TYPE_ICO)
 540         self.SetIcon(frameIcon)
 541 
 542 
 543     def OnTimerIn(self, evt):
 544         """
 545         Thanks to Pascal Faut.
 546         """
 547 
 548         self.timer1 = wx.Timer(self, -1)
 549         self.timer1.Start(1)
 550         self.Bind(wx.EVT_TIMER, self.AlphaCycle1, self.timer1)
 551 
 552         print("Fade-in was launched.")
 553 
 554 
 555     def OnTimerOut(self, evt):
 556         """
 557         Thanks to Pascal Faut.
 558         """
 559 
 560         self.timer2 = wx.Timer(self, -1)
 561         self.timer2.Start(1)
 562         self.Bind(wx.EVT_TIMER, self.AlphaCycle2, self.timer2)
 563 
 564         print("Fade-out was launched.")
 565 
 566 
 567     def AlphaCycle1(self, *args):
 568         """
 569         Thanks to Pascal Faut.
 570         """
 571 
 572         self.opacity_in += self.deltaN
 573         if self.opacity_in <= 0:
 574             self.deltaN = -self.deltaN
 575             self.opacity_in = 0
 576 
 577         if self.opacity_in >= 255:
 578             self.deltaN = -self.deltaN
 579             self.opacity_in = 255
 580 
 581             self.timer1.Stop()
 582 
 583         self.SetTransparent(self.opacity_in)
 584 
 585         print("Fade in = {}/255".format(self.opacity_in))
 586 
 587 
 588     def AlphaCycle2(self, *args):
 589         """
 590         Thanks to Pascal Faut.
 591         """
 592 
 593         self.opacity_out += self.deltaN
 594         if self.opacity_out >= 255:
 595             self.deltaN = -self.deltaN
 596             self.opacity_out = 255
 597 
 598         if self.opacity_out <= 0:
 599             self.deltaN = -self.deltaN
 600             self.opacity_out = 0
 601 
 602             self.timer2.Stop()
 603 
 604             wx.CallAfter(self.Destroy)
 605 
 606         self.SetTransparent(self.opacity_out)
 607 
 608         print("Fade out = {}/255".format(self.opacity_out))
 609 
 610 
 611     def CreateCtrls(self):
 612         """
 613         Make widgets for my dialog.
 614         """
 615 
 616         # Load a background bitmap.
 617         self.bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
 618                                           "skin_about_3.png"),
 619                              type=wx.BITMAP_TYPE_PNG)
 620         mask = wx.Mask(self.bmp, wx.RED)
 621         self.bmp.SetMask(mask)
 622 
 623         #------------
 624 
 625         self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
 626 
 627         #------------
 628 
 629         if wx.Platform == "__WXGTK__":
 630             # wxGTK requires that the window be created before you can
 631             # set its shape, so delay the call to SetWindowShape until
 632             # this event.
 633             self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
 634         else:
 635             # On wxMSW and wxMac the window has already
 636             # been created, so go for it.
 637             self.SetWindowShape()
 638 
 639 
 640     def BindEvents(self):
 641         """
 642         Bind all the events related to my dialog.
 643         """
 644 
 645         # Bind some events to an events handler.
 646         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
 647         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
 648         self.Bind(wx.EVT_RIGHT_UP, self.OnCloseWindow)  # Panel right clic.
 649         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
 650         self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
 651         self.Bind(wx.EVT_MOTION, self.OnMouseMove)
 652         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
 653         self.Bind(wx.EVT_PAINT, self.OnPaint)
 654         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
 655 
 656 
 657     def SetWindowShape(self, event=None):
 658         """
 659         ...
 660         """
 661 
 662         # Use the bitmap's mask to determine the region.
 663         r = wx.Region(self.bmp)
 664         self.hasShape = self.SetShape(r)
 665 
 666 
 667     def OnEraseBackground(self, event):
 668         """
 669         ...
 670         """
 671 
 672         dc = event.GetDC()
 673         if not dc:
 674             dc = wx.ClientDC(self)
 675             rect = self.GetUpdateRegion().GetBox()
 676             dc.SetClippingRect(rect)
 677 
 678 
 679     def OnLeftDown(self, event):
 680         """
 681         ...
 682         """
 683 
 684         self.CaptureMouse()
 685         x, y = self.ClientToScreen(event.GetPosition())
 686         originx, originy = self.GetPosition()
 687         dx = x - originx
 688         dy = y - originy
 689         self.delta = ((dx, dy))
 690 
 691 
 692     def OnLeftUp(self, evt):
 693         """
 694         ...
 695         """
 696 
 697         if self.HasCapture():
 698             self.ReleaseMouse()
 699 
 700 
 701     def OnMouseMove(self, event):
 702         """
 703         ...
 704         """
 705 
 706         if event.Dragging() and event.LeftIsDown():
 707             x, y = self.ClientToScreen(event.GetPosition())
 708             fp = (x - self.delta[0], y - self.delta[1])
 709             self.Move(fp)
 710 
 711 
 712     def OnPaint(self, event):
 713         """
 714         ...
 715         """
 716 
 717         dc = wx.AutoBufferedPaintDCFactory(self)
 718         dc.SetBackground(wx.Brush("BLACK"))
 719         dc.Clear()
 720 
 721         #------------
 722 
 723         # These are strings.
 724         py_version = sys.version.split()[0]
 725 
 726         str1 = (('<font style="normal" family="default" color="yellow" size="10" weight="bold">'
 727                  'Programming : </font>'
 728                  '<font style="normal" family="default" color="white" size="10" weight="normal">'
 729                  'Python {}</font>').format(py_version))   # Python 3.7.2
 730 
 731         str2 = (('<font style="normal" family="default" color="orange" size="10" weight="bold">'
 732                  'GUI toolkit : </font>'
 733                  '<font style="normal" family="default" color="white" size="10" weight="normal">'
 734                  'wxPython {}</font>').format(wx.VERSION_STRING))  # wxPython 4.0.4
 735 
 736         str3 = (('<font style="normal" family="default" color="brown" size="10" weight="bold">'
 737                  'Library : </font>'
 738                  '<font style="normal" family="default" color="white" size="10" weight="normal">'
 739                  '{}</font>').format(wx.GetLibraryVersionInfo().VersionString))   # wxWidgets 3.0.5
 740 
 741         str4 = (('<font style="normal" family="default" color="cyan" size="10" weight="bold">'
 742                  'Operating system : </font>'
 743                  '<font style="normal" family="default" color="white" size="10" weight="normal">'
 744                  '{}</font>').format(platform.system()))   # Windows
 745 
 746         str5 = (('<font style="normal" family="default" color="white" size="9" weight="normal">'
 747                  '{}</font>').format(self.app_name))   # Custom Gui
 748 
 749         str6 = (('<font style="normal" family="default" color="black" size="8" weight="normal">'
 750                  'Right clic or Esc for Exit</font>'))
 751 
 752         #------------
 753 
 754         # Get the working size we can draw in.
 755         bw, bh = self.GetSize()
 756 
 757         # Use the GCDC to draw the text.
 758         # Draw the about borders.
 759         dc.SetPen(wx.Pen(wx.Colour(200, 200, 200), 20))
 760         # Read config file.
 761         dc.SetBrush(wx.Brush(self.config.Read("Color1")))
 762         # or
 763         # dc.SetBrush(wx.Brush(wx.TRANSPARENT_BRUSH))
 764         dc.DrawRectangle(0, 0, bw, bh)
 765 
 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, 190)
 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 
 830 #---------------------------------------------------------------------------
 831 
 832 class MyPopupMenu(wx.Menu):
 833     """
 834     Thanks to Robin Dunn.
 835     """
 836     def __init__(self, parent):
 837         wx.Menu.__init__(self)
 838 
 839         #------------
 840 
 841         # Attributes.
 842         self.parent = parent
 843 
 844         #------------
 845 
 846         # Returns bitmaps folder.
 847         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
 848 
 849         #------------
 850 
 851         # Simplified init method.
 852         self.CreatePopupMenu()
 853         self.BindEvents()
 854 
 855     #-----------------------------------------------------------------------
 856 
 857     def CreatePopupMenu(self, event=None):
 858         """
 859         This method is called by the base class when it needs to popup
 860         the menu for the default EVT_RIGHT_DOWN event.  Just create
 861         the menu how you want it and return it from this function,
 862         the base class takes care of the rest.
 863         """
 864 
 865         bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
 866                                      "item_about.png"),
 867                         type=wx.BITMAP_TYPE_PNG)
 868 
 869         item = wx.MenuItem(self, id=wx.ID_ABOUT, text=" About")
 870         item.SetBitmap(bmp)
 871         self.Append(item)
 872         self.AppendSeparator()
 873 
 874         #------------
 875 
 876         bmp = wx.Bitmap(os.path.join(self.bitmaps_dir,
 877                                      "item_exit.png"),
 878                         type=wx.BITMAP_TYPE_PNG)
 879 
 880         if True or "__WXMSW__" in wx.PlatformInfo:
 881             font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
 882             font.SetWeight(wx.BOLD)
 883 
 884         item = wx.MenuItem(self, id=wx.ID_EXIT, text=" Exit")
 885         item.SetBitmap(bmp)
 886         item.SetFont(font)
 887         self.Append(item)
 888 
 889         return self
 890 
 891 
 892     def BindEvents(self):
 893         """
 894         Bind some events to an events handler.
 895         """
 896 
 897         # Bind the menu events to an events handler.
 898         self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
 899         self.Bind(wx.EVT_MENU, self.OnClose, id=wx.ID_EXIT)
 900 
 901 
 902     def OnAbout(self, event):
 903         """
 904         ...
 905         """
 906 
 907         self.mainFrame = wx.GetApp().GetTopWindow()
 908         self.mainFrame.OnAbout(self)
 909 
 910         print("About icon was clicked.")
 911 
 912 
 913     def OnClose(self, event):
 914         """
 915         ...
 916         """
 917 
 918         self.mainFrame = wx.GetApp().GetTopWindow()
 919         self.mainFrame.OnCloseWindow(self)
 920 
 921         print("Close icon was clicked.")
 922 
 923 #---------------------------------------------------------------------------
 924 
 925 class MyWindow(wx.Control):
 926     """
 927     Thanks to Cody Precord.
 928     """
 929     def __init__(self, parent, label,
 930                  foreground, background,
 931                  normal, pressed=None):
 932         style = (wx.BORDER_NONE)
 933         super(MyWindow, self).__init__(parent,
 934                                        -1,
 935                                        style=style)
 936 
 937         #------------
 938 
 939         # Attributes.
 940         self.label = label
 941         self.foreground = foreground
 942         self.background = background
 943 
 944         if wx.Platform == "__WXGTK__":
 945             self.color = "#9e9d9d"
 946 
 947         else:
 948             self.color = "#b1b1b0"
 949 
 950         self.normal = normal
 951         self.pressed = pressed
 952 
 953         self._clicked = False
 954 
 955         #------------
 956 
 957         self.region = wx.Region(normal, wx.Colour(0, 0, 0, 0))
 958 
 959         #------------
 960 
 961         # Simplified init method.
 962         self.SetProperties(label, foreground, background)
 963         self.BindEvents()
 964 
 965     #-----------------------------------------------------------------------
 966 
 967     def SetProperties(self, label, foreground, background):
 968         """
 969         ...
 970         """
 971 
 972         self.label = label
 973         self.foreground = foreground
 974         self.background = background
 975         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
 976 
 977 
 978     def BindEvents(self):
 979         """
 980         Bind some events to an events handler.
 981         """
 982 
 983         self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
 984         self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
 985         self.Bind(wx.EVT_PAINT, self.OnPaint)
 986         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
 987         self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDclick)
 988         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
 989         self.Bind(wx.EVT_MOTION, self.OnMotion)
 990         self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
 991         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
 992 
 993 
 994     def SetLabel(self, label):
 995         """
 996         ...
 997         """
 998 
 999         self.label = label
1000         self.Refresh()
1001 
1002 
1003     def DoGetBestSize(self):
1004         """
1005         ...
1006         """
1007 
1008         return self.normal.GetSize()
1009 
1010 
1011     def GetLabel(self):
1012         """
1013         ...
1014         """
1015 
1016         return self.label
1017 
1018 
1019     def GetLabelColor(self):
1020         """
1021         ...
1022         """
1023 
1024         return self.foreground
1025 
1026 
1027     def Enable(self, *args, **kwargs):
1028         """
1029         ...
1030         """
1031 
1032         super(MyWindow, self).Enable(*args, **kwargs)
1033         self.Refresh()
1034 
1035 
1036     def Disable(self, *args, **kwargs):
1037         """
1038         ...
1039         """
1040 
1041         super(MyWindow, self).Disable(*args, **kwargs)
1042         self.Refresh()
1043 
1044 
1045     def PostEvent(self):
1046         """
1047         ...
1048         """
1049 
1050         event = wx.CommandEvent()
1051         event.SetEventObject(self)
1052         event.SetEventType(wx.EVT_BUTTON.typeId)
1053         wx.PostEvent(self, event)
1054 
1055 
1056     def OnSize(self, event):
1057         """
1058         ...
1059         """
1060 
1061         event.Skip()
1062         self.Refresh()
1063 
1064 
1065     def GetBackground(self):
1066         """
1067         ...
1068         """
1069 
1070         return self.background
1071 
1072 
1073     def OnPaint(self, event):
1074         """
1075         ...
1076         """
1077 
1078         dc = wx.BufferedPaintDC(self)
1079         dc.Clear()
1080         gcdc = wx.GCDC(dc)
1081 
1082         # Set the background color.
1083         if wx.Platform == "__WXGTK__":
1084             gcdc.SetBackground(wx.Brush("grey55"))
1085         else:
1086             gcdc.SetBackground(wx.Brush(self.background))
1087 
1088         gcdc.Clear()
1089 
1090         # Get the working rectangle we can draw in.
1091         rect = self.GetClientRect()
1092 
1093         # Font size and style.
1094         fontSize = self.GetFont().GetPointSize()
1095 
1096         if wx.Platform == "__WXGTK__":
1097             boldFont = wx.Font(fontSize-1, wx.DEFAULT,
1098                                wx.NORMAL, wx.NORMAL, False, "")
1099         else:
1100             boldFont = wx.Font(fontSize+2, wx.DEFAULT,
1101                                wx.NORMAL, wx.BOLD, False, "")
1102 
1103         if wx.Platform == "__WXMSW__":
1104             pen = wx.Pen(self.color, 1, wx.SOLID)
1105 
1106         else:
1107             pen = wx.Pen(self.color, 1, wx.SOLID)
1108 
1109         gcdc.SetPen(pen)
1110 
1111         x, y = self.GetSize()
1112         # x, y , width, height, radius
1113         gcdc.DrawRoundedRectangle (0, 0, 71, 25, 3)
1114 
1115         bitmap = self.normal
1116 
1117         w, h = bitmap.GetWidth(), bitmap.GetHeight()
1118 
1119         if self.clicked:
1120             bitmap = self.pressed or bitmap
1121         if not self.IsEnabled():
1122             bitmap = self.normal or bitmap
1123 
1124         # Draw a bitmap with an alpha channel.
1125         # image, x, y, transparency.
1126         dc.DrawBitmap(bitmap, 0, 0, True)
1127 
1128         if wx.Platform == "__WXGTK__":
1129             # Add the Caption.
1130             # White text - Shadow.
1131             rect = wx.Rect(rect.x, rect.y+3,
1132                            rect.width, 22)
1133 
1134         else:
1135             rect = wx.Rect(rect.x, rect.y+3,
1136                            rect.width, 20)
1137 
1138         dc.SetFont(boldFont)
1139         dc.SetTextForeground(wx.WHITE)
1140         dc.DrawLabel(self.label, rect, wx.ALIGN_CENTER)
1141 
1142         if wx.Platform == "__WXGTK__":
1143             # Add the Caption.
1144             # Black text.
1145             rect = wx.Rect(rect.x, rect.y,
1146                            rect.width, 21)
1147 
1148         else:
1149             rect = wx.Rect(rect.x, rect.y,
1150                            rect.width, 19)
1151 
1152         gcdc.SetFont(boldFont)
1153         # Get the text color.
1154         dc.SetTextForeground(self.foreground)
1155         dc.DrawLabel(self.label, rect, wx.ALIGN_CENTER)
1156 
1157 
1158     def SetClicked(self, clicked):
1159         """
1160         ...
1161         """
1162 
1163         if clicked != self._clicked:
1164             self._clicked = clicked
1165             self.Refresh()
1166 
1167 
1168     def GetClicked(self):
1169         """
1170         ...
1171         """
1172 
1173         return self._clicked
1174 
1175 
1176     clicked = property(GetClicked, SetClicked)
1177     def OnLeftDown(self, event):
1178         """
1179         ...
1180         """
1181 
1182         x, y = event.GetPosition()
1183         if self.region.Contains(x, y):
1184             self.clicked = True
1185             self.SetFocus()
1186 
1187 
1188     def OnLeftDclick(self, event):
1189         """
1190         ...
1191         """
1192 
1193         self.OnLeftDown(event)
1194 
1195 
1196     def OnLeftUp(self, event):
1197         """
1198         ...
1199         """
1200 
1201         if self.clicked:
1202             x, y = event.GetPosition()
1203             if self.region.Contains(x, y):
1204                 self.PostEvent()
1205         self.clicked = False
1206 
1207 
1208     def OnMotion(self, event):
1209         """
1210         ...
1211         """
1212 
1213         if self.clicked:
1214             x, y = event.GetPosition()
1215             if not self.region.Contains(x, y):
1216                 self.clicked = False
1217 
1218 
1219     def OnLeave(self, event):
1220         """
1221         ...
1222         """
1223 
1224         self.clicked = False
1225 
1226 
1227     def OnSetFocus(self, event):
1228         """
1229         ...
1230         """
1231 
1232         self.color = "white"
1233         self.Refresh()
1234 
1235 
1236     def OnKillFocus(self, event):
1237         """
1238         ...
1239         """
1240 
1241         if wx.Platform == "__WXGTK__":
1242             self.color = "#9e9d9d"
1243 
1244         else:
1245             self.color = "#b1b1b0"
1246 
1247         self.Refresh()
1248 
1249 
1250     def OnKeyUp(self, event):
1251         """
1252         ...
1253         """
1254 
1255         if event.GetKeyCode() == wx.WXK_SPACE:
1256             self.PostEvent()
1257             return
1258 
1259         elif event.GetKeyCode() == wx.WXK_ESCAPE:
1260             self.GetTopLevelParent().OnCloseWindow(True)
1261 
1262         event.Skip()
1263 
1264 #---------------------------------------------------------------------------
1265 
1266 class MyButtonBox(wx.Panel):
1267     """
1268     Thanks to Cody Precord.
1269     """
1270     def __init__(self, parent, caption):
1271         style = (wx.NO_BORDER | wx.TAB_TRAVERSAL)
1272         super(MyButtonBox, self).__init__(parent,
1273                                           style=style)
1274 
1275         #------------
1276 
1277         # Attributes.
1278         self._caption = caption
1279 
1280         #------------
1281 
1282         # Simplified init method.
1283         self.DoLayout()
1284 
1285     #-----------------------------------------------------------------------
1286 
1287     def DoLayout(self):
1288         """
1289         ...
1290         """
1291 
1292         self._csizer = wx.BoxSizer(wx.VERTICAL)
1293         msizer = wx.BoxSizer(wx.HORIZONTAL)
1294         msizer.Add(self._csizer, 0 )
1295         self.SetSizer(msizer)
1296 
1297 
1298     def DoGetBestSize(self):
1299         """
1300         ...
1301         """
1302 
1303         size = super(MyButtonBox, self).DoGetBestSize()
1304 
1305         # Compensate for wide caption labels.
1306         tw = self.GetTextExtent(self._caption)[0]
1307         size.SetWidth(max(size.width, size.height))
1308         return size
1309 
1310 
1311     def AddItem(self, item):
1312         """
1313         Add a window or sizer item to the MyButtonBox.
1314         """
1315 
1316         self._csizer.Add(item, 0 )
1317 
1318 #---------------------------------------------------------------------------
1319 
1320 class MyTitleBarPnl(wx.Panel):
1321     """
1322     Thanks to Cody Precord.
1323     """
1324     def __init__(self, parent, id, size):
1325         style = (wx.NO_BORDER)
1326         super(MyTitleBarPnl, self).__init__(parent,
1327                                             id,
1328                                             size=size,
1329                                             style=style)
1330 
1331         #------------
1332 
1333         # Attributes.
1334         self.parent = parent
1335 
1336         #------------
1337 
1338         # Return config file.
1339         self.config = wx.GetApp().GetConfig()
1340         # Return application name.
1341         self.app_name = wx.GetApp().GetAppName()
1342         # Return bitmaps folder.
1343         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1344 
1345         #------------
1346 
1347         # Simplified init method.
1348         self.SetProperties()
1349         self.CreateCtrls()
1350         self.BindEvents()
1351 
1352     #-----------------------------------------------------------------------
1353 
1354     def SetProperties(self):
1355         """
1356         ...
1357         """
1358 
1359         # Read config file.
1360         self.SetBackgroundColour(wx.Colour(self.config.Read("Color1")))
1361 
1362 
1363     def CreateCtrls(self):
1364         """
1365         ...
1366         """
1367 
1368         w, h = self.GetClientSize()
1369         print("MyTitleBarPnl :", self.GetClientSize())
1370 
1371         #------------
1372         #------------
1373 
1374         # Add titleBar.
1375         self.titleBar = MyTitleBar(self,
1376                                    label=self.app_name,
1377                                    size=10)
1378         self.titleBar.SetPosition((0, 0))
1379         self.titleBar.SetSize((w, 31))
1380         self.titleBar.SetLabelColour("white")
1381         self.titleBar.SetToolTip("This is a customized title bar.")
1382 
1383         #------------
1384         #------------
1385 
1386         # Gloss Buttons box (titleBar).
1387         self.box3 = MyButtonBox(self.titleBar, "")   # Button Exit.
1388         self.box4 = MyButtonBox(self.titleBar, "")   # Button Maximize.
1389         self.box5 = MyButtonBox(self.titleBar, "")   # Button Reduce.
1390         self.box6 = MyButtonBox(self.titleBar, "")   # Button Roll.
1391 
1392         # Gloss Buttons bitmap.
1393         bmpa = wx.Bitmap(os.path.join(self.bitmaps_dir,
1394                                       "btn_gloss_exit_normal_5.png"),
1395                          type=wx.BITMAP_TYPE_PNG)
1396 
1397         bmpb = wx.Bitmap(os.path.join(self.bitmaps_dir,
1398                                       "btn_gloss_exit_selected_5.png"),
1399                          type=wx.BITMAP_TYPE_PNG)
1400 
1401         bmpc = wx.Bitmap(os.path.join(self.bitmaps_dir,
1402                                       "btn_gloss_maximize_normal_5.png"),
1403                          type=wx.BITMAP_TYPE_PNG)
1404 
1405         bmpd = wx.Bitmap(os.path.join(self.bitmaps_dir,
1406                                       "btn_gloss_maximize_selected_5.png"),
1407                          type=wx.BITMAP_TYPE_PNG)
1408 
1409         bmpe = wx.Bitmap(os.path.join(self.bitmaps_dir,
1410                                       "btn_gloss_reduce_normal_5.png"),
1411                          type=wx.BITMAP_TYPE_PNG)
1412 
1413         bmpf = wx.Bitmap(os.path.join(self.bitmaps_dir,
1414                                       "btn_gloss_reduce_selected_5.png"),
1415                          type=wx.BITMAP_TYPE_PNG)
1416 
1417         bmpg = wx.Bitmap(os.path.join(self.bitmaps_dir,
1418                                       "btn_gloss_roll_normal_5.png"),
1419                          type=wx.BITMAP_TYPE_PNG)
1420 
1421         bmph = wx.Bitmap(os.path.join(self.bitmaps_dir,
1422                                       "btn_gloss_roll_selected_5.png"),
1423                          type=wx.BITMAP_TYPE_PNG)
1424 
1425         self.btn3 = MyWindow(self.box3, "", "black", "#9e9d9d", bmpa, bmpb)
1426         self.btn3.SetToolTip("This is a customized gloss button.")
1427 
1428         self.btn4 = MyWindow(self.box4, "", "black", "#9e9d9d", bmpc, bmpd)
1429         self.btn4.SetToolTip("This is a customized gloss button.")
1430 
1431         self.btn5 = MyWindow(self.box5, "", "black", "#9e9d9d", bmpe, bmpf)
1432         self.btn5.SetToolTip("This is a customized gloss button.")
1433 
1434         self.btn6 = MyWindow(self.box6, "", "black", "#9e9d9d", bmpg, bmph)
1435         self.btn6.SetToolTip("This is a customized gloss button.")
1436 
1437         self.box3.AddItem(self.btn3)
1438         self.box4.AddItem(self.btn4)
1439         self.box5.AddItem(self.btn5)
1440         self.box6.AddItem(self.btn6)
1441 
1442         #------------
1443         #------------
1444 
1445         w, h = self.GetSize()
1446 
1447         #------------
1448 
1449         self.box3.SetSize((25, 19))
1450         x1, y1 = self.box3.GetSize()
1451         self.box3.SetPosition((x1-18, h-6-y1))
1452 
1453         #------------
1454 
1455         self.box4.SetSize((25, 19))
1456         self.box4.SetPosition(((x1*2)-18, h-6-y1))
1457 
1458         #------------
1459 
1460         self.box5.SetSize((25, 19))
1461         self.box5.SetPosition(((x1*3)-18, h-6-y1))
1462 
1463         #------------
1464 
1465         self.box6.SetSize((25, 19))
1466         self.box6.SetPosition(((x1*4)-18, h-6-y1))
1467 
1468 
1469     def BindEvents(self):
1470         """
1471         Bind some events to an events handler.
1472         """
1473 
1474         self.btn3.Bind(wx.EVT_BUTTON, self.OnBtnClose)
1475         self.btn4.Bind(wx.EVT_BUTTON, self.OnFullScreen)
1476         self.btn5.Bind(wx.EVT_BUTTON, self.OnIconfiy)
1477         self.btn6.Bind(wx.EVT_BUTTON, self.OnRoll)
1478 
1479         self.Bind(wx.EVT_SIZE, self.OnResize)
1480 
1481 
1482     def OnResize(self, event):
1483         """
1484         ...
1485         """
1486 
1487         w, h = self.GetClientSize()
1488         print("MyTitleBarPnl :", self.GetClientSize())
1489 
1490         #------------
1491         #------------
1492 
1493         self.titleBar.SetSize((w, 24))
1494 
1495         #------------
1496 
1497         x1, y1 = self.box3.GetSize()
1498 
1499         self.box3.SetPosition((x1-18, h-6-y1))
1500         self.box4.SetPosition(((x1*2)-18, h-6-y1))
1501         self.box5.SetPosition(((x1*3)-18, h-6-y1))
1502         self.box6.SetPosition(((x1*4)-18, h-6-y1))
1503 
1504         #------------
1505 
1506         self.Refresh()
1507 
1508         print("On resize was clicked.")
1509 
1510 
1511     def OnRoll(self, event):
1512         """
1513         ...
1514         """
1515 
1516         self.GetParent().OnRoll(True)
1517 
1518         print("Roll/unRoll button was clicked.")
1519 
1520 
1521     def OnIconfiy(self, event):
1522         """
1523         ...
1524         """
1525 
1526         self.GetParent().OnIconfiy(self)
1527 
1528         print("Iconfiy button was clicked.")
1529 
1530 
1531     def OnFullScreen(self, event):
1532         """
1533         ...
1534         """
1535 
1536         self.GetParent().OnFullScreen(self)
1537 
1538         print("FullScreen button was clicked.")
1539 
1540 
1541     def OnBtnClose(self, event):
1542         """
1543         ...
1544         """
1545 
1546         self.GetParent().OnCloseWindow(self)
1547 
1548         print("Close button was clicked.")
1549 
1550 #---------------------------------------------------------------------------
1551 
1552 class MyMainPnl(wx.Panel):
1553     """
1554     ...
1555     """
1556     def __init__(self, parent, id, size):
1557         style = (wx.NO_BORDER | wx.TAB_TRAVERSAL)
1558         super(MyMainPnl, self).__init__(parent,
1559                                         id=int(ID_MAIN_PNL),
1560                                         size=size,
1561                                         style=style)
1562 
1563         #------------
1564 
1565         # Attributes.
1566         self.parent = parent
1567 
1568         #------------
1569 
1570         # Return config file.
1571         self.config = wx.GetApp().GetConfig()
1572         # Return bitmaps folder.
1573         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1574 
1575         #------------
1576 
1577         # Colourdb.
1578         wx.lib.colourdb.updateColourDB()
1579 
1580         # Create a colour list from the colourdb database.
1581         self.colour_list = wx.lib.colourdb.getColourList()
1582 
1583         #------------
1584 
1585         # Simplified init method.
1586         self.SetProperties()
1587         self.CreateCtrls()
1588         self.DoLayout()
1589         self.BindEvents()
1590 
1591     #-----------------------------------------------------------------------
1592 
1593     def SetProperties(self):
1594         """
1595         ...
1596         """
1597 
1598         if wx.Platform == "__WXMSW__":
1599             self.SetDoubleBuffered(True)
1600 
1601         # Read config file.
1602         self.SetBackgroundColour(self.config.Read("Color1"))
1603 
1604 
1605     def CreateCtrls(self):
1606         """
1607         ...
1608         """
1609 
1610         w, h = self.GetClientSize()
1611         print("MyMainPnl :", self.GetClientSize())
1612 
1613         #------------
1614 
1615         font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
1616         font.SetWeight(wx.BOLD)
1617 
1618         #------------
1619         #------------
1620 
1621         # Create data list control.
1622         self.list = MyListCtrlPnl(self)
1623 
1624         #------------
1625         #------------
1626 
1627         self.txt = wx.StaticText(self,
1628                                  -1,
1629                                  label="Hello World !")
1630         self.txt.SetForegroundColour("white")
1631         self.txt.SetFont(font)
1632 
1633         #------------
1634         #------------
1635 
1636         # Thanks to MCOW.
1637         # Buttons.
1638         self.btn1 = SBB.ShapedBitmapButton(self, ID_BTN_FULLSCREEN,
1639             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
1640                                           "adbRnd.png"),
1641                              type=wx.BITMAP_TYPE_PNG),
1642 
1643             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1644                                               "adbRnd-pressed.png"),
1645                                  type=wx.BITMAP_TYPE_PNG),
1646 
1647             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1648                                             "adbRnd-hover.png"),
1649                                type=wx.BITMAP_TYPE_PNG),
1650 
1651             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1652                                                "adbRnd-disabled.png"),
1653                                   type=wx.BITMAP_TYPE_PNG),
1654 
1655             label="Fullscreen",
1656             labelForeColour=wx.WHITE,
1657             labelPosition=(35, 8),
1658             labelFont=wx.Font(9,
1659                               wx.FONTFAMILY_DEFAULT,
1660                               wx.FONTSTYLE_NORMAL,
1661                               wx.FONTWEIGHT_BOLD),
1662             style=wx.BORDER_NONE)
1663 
1664         self.btn1.SetFocus() # Necessary for Linux.
1665 
1666         #------------
1667 
1668         self.btn2 = SBB.ShapedBitmapButton(self, ID_BTN_ABOUT,
1669             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
1670                                           "adbRnd.png"),
1671                              type=wx.BITMAP_TYPE_PNG),
1672 
1673             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1674                                               "adbRnd-pressed.png"),
1675                                  type=wx.BITMAP_TYPE_PNG),
1676 
1677             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1678                                             "adbRnd-hover.png"),
1679                                type=wx.BITMAP_TYPE_PNG),
1680 
1681             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1682                                                "adbRnd-disabled.png"),
1683                                   type=wx.BITMAP_TYPE_PNG),
1684 
1685             label="About",
1686             labelForeColour=wx.WHITE,
1687             labelPosition=(50, 8),
1688             labelFont=wx.Font(9,
1689                               wx.FONTFAMILY_DEFAULT,
1690                               wx.FONTSTYLE_NORMAL,
1691                               wx.FONTWEIGHT_BOLD),
1692             style=wx.BORDER_NONE)
1693 
1694         #------------
1695 
1696         self.btn3 = SBB.ShapedBitmapButton(self, ID_BTN_QUIT,
1697             bitmap=wx.Bitmap(os.path.join(self.bitmaps_dir,
1698                                           "adbRnd.png"),
1699                              type=wx.BITMAP_TYPE_PNG),
1700 
1701             pressedBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1702                                               "adbRnd-pressed.png"),
1703                                  type=wx.BITMAP_TYPE_PNG),
1704 
1705             hoverBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1706                                             "adbRnd-hover.png"),
1707                                type=wx.BITMAP_TYPE_PNG),
1708 
1709             disabledBmp=wx.Bitmap(os.path.join(self.bitmaps_dir,
1710                                                "adbRnd-disabled.png"),
1711                                   type=wx.BITMAP_TYPE_PNG),
1712 
1713             label="Quit",
1714             labelForeColour=wx.WHITE,
1715             labelPosition=(50, 8),
1716             labelFont=wx.Font(9,
1717                               wx.FONTFAMILY_DEFAULT,
1718                               wx.FONTSTYLE_NORMAL,
1719                               wx.FONTWEIGHT_BOLD),
1720             style=wx.BORDER_NONE)
1721 
1722         #------------
1723         #------------
1724 
1725         self.line = wx.StaticLine(self, -1,
1726                                   pos=(0, 70),
1727                                   size=(-1, -1),
1728                                   style=wx.LI_HORIZONTAL)
1729 
1730         #------------
1731         #------------
1732 
1733         # Create a choice widget.
1734         self.choice = wx.Choice(self,
1735                                 -1,
1736                                 pos=(-1, -1),
1737                                 size=(131, -1),
1738                                 choices=self.colour_list,
1739                                 style=wx.CB_SORT)
1740 
1741         # Select item 141 in choice list to show.
1742         # self.choice.SetSelection(141)  # CORNSILK4
1743         # Read config file.
1744         self.choice.SetSelection(self.config.ReadInt("Item1"))
1745 
1746         item = self.choice.GetCurrentSelection()
1747         bgcolour = self.choice.GetStringSelection()
1748         print("Item : %s , %s" % (item, bgcolour))
1749 
1750 
1751     def DoLayout(self):
1752         """
1753         ...
1754         """
1755 
1756         txtSizer = wx.BoxSizer(wx.VERTICAL)
1757         txtSizer.Add(self.txt, 0, wx.LEFT, 13)
1758 
1759         sizerList = wx.BoxSizer(wx.VERTICAL)
1760         sizerList.Add(self.list, 1,
1761                       wx.LEFT|wx.TOP|wx.BOTTOM|
1762                       wx.EXPAND|wx.ALIGN_TOP, 10)
1763 
1764         sizer = wx.BoxSizer(wx.VERTICAL)
1765         sizer.Add(txtSizer, 0, wx.BOTTOM, 0)
1766         sizer.Add(self.btn1, 1, wx.ALL, 10)
1767         sizer.Add(self.btn2, 1, wx.ALL, 10)
1768         sizer.Add(self.line, 0, wx.EXPAND|wx.ALL, 10)
1769         sizer.Add(self.choice, 0, wx.ALL, 10)
1770         sizer.Add(self.btn3, 1, wx.ALL, 10)
1771 
1772         mainSizer = wx.BoxSizer(wx.HORIZONTAL)
1773         mainSizer.Add(sizerList, 1,
1774                       wx.LEFT|wx.TOP|wx.BOTTOM|wx.EXPAND, 5)
1775         mainSizer.Add(sizer, 0, wx.ALIGN_BOTTOM|wx.ALL, 5)
1776 
1777         self.SetSizer(mainSizer)
1778         self.Layout()
1779 
1780 
1781     def BindEvents(self):
1782         """
1783         Bind some events to an events handler.
1784         """
1785 
1786         self.choice.Bind(wx.EVT_CHOICE, self.OnChoice)
1787 
1788         self.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_MAIN_PNL)
1789         self.btn1.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_BTN_FULLSCREEN)
1790         self.btn2.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_BTN_ABOUT)
1791         self.btn3.Bind(wx.EVT_ENTER_WINDOW, self.OnInfo, id=ID_BTN_QUIT)
1792 
1793         self.btn1.Bind(wx.EVT_BUTTON, self.OnFullScreen)
1794         self.btn2.Bind(wx.EVT_BUTTON, self.OnAbout)
1795         self.btn3.Bind(wx.EVT_BUTTON, self.OnBtnClose)
1796 
1797 
1798     def OnInfo(self, event):
1799         """
1800         ...
1801         """
1802 
1803         event_id = event.GetId()
1804 
1805         if event_id == ID_MAIN_PNL:
1806             self.GetParent().SetStatusText(text="Hello world !")
1807 
1808         elif event_id == ID_BTN_FULLSCREEN:
1809             self.GetParent().SetStatusText(text="Fullscreen")
1810 
1811         elif event_id == ID_BTN_ABOUT:
1812             self.GetParent().SetStatusText(text="About")
1813 
1814         elif event_id == ID_BTN_QUIT:
1815             self.GetParent().SetStatusText(text="Quit the program")
1816 
1817         else:
1818             # Tell the event system to continue
1819             # looking for an event handler, so the
1820             # default handler will get called.
1821             event.Skip()
1822 
1823 
1824     def OnChoice(self, event):
1825         """
1826         ...
1827         """
1828 
1829         item = event.GetSelection()
1830         bgcolour = self.choice.GetStringSelection()
1831         print("New item : %s , %s" % (item, bgcolour))
1832 
1833         # Change colour of the panel to the selected colour...
1834         self.SetBackgroundColour(bgcolour)
1835 
1836         # Write config file.
1837         self.config.WriteInt("Item1", self.choice.GetCurrentSelection())
1838         self.config.Write("Color1", self.choice.GetStringSelection())
1839         self.config.Flush()
1840 
1841         self.Refresh()
1842 
1843         print("OnChoice button was clicked.")
1844 
1845 
1846     def OnAbout(self, event):
1847         """
1848         ...
1849         """
1850 
1851         self.GetParent().OnAbout(self)
1852 
1853         print("FullScreen button was clicked.")
1854 
1855 
1856     def OnFullScreen(self, event):
1857         """
1858         ...
1859         """
1860 
1861         self.GetParent().OnFullScreen(self)
1862 
1863         print("FullScreen button was clicked.")
1864 
1865 
1866     def OnBtnClose(self, event):
1867         """
1868         ...
1869         """
1870 
1871         self.GetParent().OnCloseWindow(self)
1872 
1873         print("Close button was clicked.")
1874 
1875 #---------------------------------------------------------------------------
1876 
1877 class MyFrame(wx.Frame):
1878     """
1879     Thanks to Robin Dunn.
1880     """
1881     def __init__(self):
1882         style = (wx.CLIP_CHILDREN | wx.CLOSE_BOX |
1883                  wx.MINIMIZE_BOX | wx.SYSTEM_MENU |
1884                  wx.BORDER_SIMPLE | wx.NO_FULL_REPAINT_ON_RESIZE|
1885                  wx.STAY_ON_TOP)
1886         super(MyFrame, self).__init__(None,
1887                                       -1,
1888                                       title="",
1889                                       style=style)
1890 
1891         #------------
1892 
1893         wx.SystemOptions.SetOption("msw.remap", "0")
1894 
1895         #------------
1896 
1897         # Attributes.
1898         self.SetTransparent(0)
1899         self.opacity_in = 0
1900         self.opacity_out = 255
1901         self.deltaN = -70
1902         self.delta = wx.Point(0,0)
1903 
1904         #------------
1905 
1906         # Return config file.
1907         self.config = wx.GetApp().GetConfig()
1908         # Return application name.
1909         self.app_name = wx.GetApp().GetAppName()
1910         # Return bitmaps folder.
1911         self.bitmaps_dir = wx.GetApp().GetBitmapsDir()
1912         # Return icons folder.
1913         self.icons_dir = wx.GetApp().GetIconsDir()
1914 
1915         #------------
1916 
1917         # Colourdb.
1918         wx.lib.colourdb.updateColourDB()
1919 
1920         # Create a colour list from the colourdb database.
1921         self.colour_list = wx.lib.colourdb.getColourList()
1922 
1923         #------------
1924 
1925         # Simplified init method.
1926         self.SetProperties()
1927         self.OnTimerIn(self)
1928         self.CreateMenu()
1929         self.CreateStatusBar()
1930         self.CreateCtrls()
1931         self.BindEvents()
1932         self.DoLayout()
1933 
1934         #------------
1935 
1936         # Thanks to Ray Pasco.
1937         # Initialize to the current state.
1938         self.unrolledFrameClientSize_size = self.GetClientSize()
1939         self.isRolled = False
1940 
1941         #------------
1942 
1943         self.CenterOnScreen(wx.BOTH)
1944 
1945         #------------
1946 
1947         self.Show(True)
1948 
1949     #-----------------------------------------------------------------------
1950 
1951     def SetProperties(self):
1952         """
1953         ...
1954         """
1955 
1956         self.SetTitle(self.app_name)
1957         self.SetClientSize((600, 380))
1958         self.SetMinSize((340, 83))
1959 
1960         # Read config file.
1961         self.SetBackgroundColour(self.config.Read("Color1"))
1962 
1963         #------------
1964 
1965         frameIcon = wx.Icon(os.path.join(self.icons_dir,
1966                                          "icon_wxWidgets.ico"),
1967                             type=wx.BITMAP_TYPE_ICO)
1968         self.SetIcon(frameIcon)
1969 
1970 
1971     def OnTimerIn(self, evt):
1972         """
1973         Thanks to Pascal Faut.
1974         """
1975 
1976         self.timer1 = wx.Timer(self, -1)
1977         self.timer1.Start(1)
1978         self.Bind(wx.EVT_TIMER, self.AlphaCycle1, self.timer1)
1979 
1980         print("Fade-in was launched.")
1981 
1982 
1983     def OnTimerOut(self, evt):
1984         """
1985         Thanks to Pascal Faut.
1986         """
1987 
1988         self.timer2 = wx.Timer(self, -1)
1989         self.timer2.Start(1)
1990         self.Bind(wx.EVT_TIMER, self.AlphaCycle2, self.timer2)
1991 
1992         print("Fade-out was launched.")
1993 
1994 
1995     def AlphaCycle1(self, *args):
1996         """
1997         Thanks to Pascal Faut.
1998         """
1999 
2000         self.opacity_in += self.deltaN
2001         if self.opacity_in <= 0:
2002             self.deltaN = -self.deltaN
2003             self.opacity_in = 0
2004 
2005         if self.opacity_in >= 255:
2006             self.deltaN = -self.deltaN
2007             self.opacity_in = 255
2008 
2009             self.timer1.Stop()
2010 
2011         self.SetTransparent(self.opacity_in)
2012 
2013         print("Fade in = {}/255".format(self.opacity_in))
2014 
2015 
2016     def AlphaCycle2(self, *args):
2017         """
2018         Thanks to Pascal Faut.
2019         """
2020 
2021         self.opacity_out += self.deltaN
2022         if self.opacity_out >= 255:
2023             self.deltaN = -self.deltaN
2024             self.opacity_out = 255
2025 
2026         if self.opacity_out <= 0:
2027             self.deltaN = -self.deltaN
2028             self.opacity_out = 0
2029 
2030             self.timer2.Stop()
2031             wx.CallAfter(self.Destroy)
2032             wx.Exit()
2033 
2034         self.SetTransparent(self.opacity_out)
2035 
2036         print("Fade out = {}/255".format(self.opacity_out))
2037 
2038 
2039     def CreateMenu(self):
2040         """
2041         ...
2042         """
2043 
2044         # FlatMenuBar.
2045         self.menuBar = FM.FlatMenuBar(self,
2046                                       wx.ID_ANY,
2047                                       32, 4,
2048                                       options=FM.FM_OPT_IS_LCD)
2049 
2050         # FM.StyleDefault or FM.Style2007
2051         # FM.StyleXP or FM.StyleVista
2052         self.newMyTheme = self.menuBar.GetRendererManager().AddRenderer(MyMenuRenderer())
2053         self.menuBar.GetRendererManager().SetTheme(self.newMyTheme)
2054 
2055         #------------
2056 
2057         # Set an icon to the exit/help menu item.
2058         exitImg = wx.Bitmap(os.path.join(self.bitmaps_dir,
2059                                          "item_exit.png"),
2060                             type=wx.BITMAP_TYPE_PNG)
2061 
2062         helpImg = wx.Bitmap(os.path.join(self.bitmaps_dir,
2063                                          "item_about.png"),
2064                             type=wx.BITMAP_TYPE_PNG)
2065 
2066         #------------
2067         #------------
2068 
2069         # File Menu.
2070         self.file_menu = FM.FlatMenu()
2071 
2072         # Create the menu items.
2073         item = FM.FlatMenuItem(self.file_menu,
2074                                ID_FULLSCREEN,
2075                                "&Fullscreen\tCtrl+F",
2076                                "Fullscreen",
2077                                wx.ITEM_NORMAL,
2078                                None)
2079         item.SetTextColour("black")
2080         self.file_menu.AppendItem(item)
2081         self.file_menu.AppendSeparator()
2082 
2083 
2084         item = FM.FlatMenuItem(self.file_menu,
2085                                wx.ID_EXIT,
2086                                "&Quit\tCtrl+Q",
2087                                "Quit the program",
2088                                wx.ITEM_NORMAL,
2089                                None,
2090                                exitImg)
2091         # Demonstrate how to set custom font
2092         # and text colour to a FlatMenuItem.
2093         item.SetFont(wx.Font(-1, wx.FONTFAMILY_DEFAULT,
2094                              wx.FONTSTYLE_NORMAL,
2095                              wx.FONTWEIGHT_BOLD,
2096                              False, ""))
2097         item.SetTextColour("#d34725")
2098 
2099         self.file_menu.AppendItem(item)
2100 
2101         #------------
2102 
2103         # Add Create background bitmap.
2104         self.file_menu.SetBackgroundBitmap(CreateBackgroundBitmap())
2105 
2106         #------------
2107         #------------
2108 
2109         # Help Menu.
2110         self.help_menu = FM.FlatMenu()
2111 
2112         # Create the menu items.
2113         item = FM.FlatMenuItem(self.help_menu,
2114                                wx.ID_ABOUT,
2115                                "&About\tCtrl+A",
2116                                "About",
2117                                wx.ITEM_NORMAL,
2118                                None,
2119                                helpImg)
2120         item.SetTextColour("black")
2121         self.help_menu.AppendItem(item)
2122         self.help_menu.AppendSeparator()
2123 
2124         item = FM.FlatMenuItem(self.help_menu,
2125                                ID_HELLO,
2126                                "Hello !",
2127                                "Hello !",
2128                                wx.ITEM_NORMAL,
2129                                None)
2130         item.SetTextColour("black")
2131         self.help_menu.AppendItem(item)
2132 
2133         #------------
2134 
2135         # Add Create background bitmap.
2136         self.help_menu.SetBackgroundBitmap(CreateBackgroundBitmap())
2137 
2138         #------------
2139         #------------
2140 
2141         # Menu background color.
2142         # Read config file.
2143         self.menuBar.SetBackgroundColour(wx.Colour(self.config.Read("Color1")))
2144 
2145         # Add menu to the menu bar.
2146         self.menuBar.Append(self.file_menu, "&File")
2147         self.menuBar.Append(self.help_menu, "&Help")
2148 
2149 
2150     def CreateStatusBar(self):
2151         """
2152         ...
2153         """
2154 
2155         self.sb = MyStatusBar(self, -1)
2156         # Read config file.
2157         self.sb.SetBackgroundColour(wx.Colour(self.config.Read("Color1")))
2158         self.sb.SetStatusText("Hello world !")
2159 
2160         self.SetStatusBar(self.sb)
2161 
2162 
2163     def CreateCtrls(self):
2164         """
2165         ...
2166         """
2167 
2168         w, h = self.GetClientSize()
2169         print("MyFrame :", self.GetClientSize())
2170 
2171         #------------
2172         #------------
2173 
2174         self.titleBarPnl = MyTitleBarPnl(self, -1, (w, 31))
2175         self.titleBarPnl.SetPosition((0, 0))
2176         print("self.titleBarPnl :", self.titleBarPnl.GetSize())
2177 
2178         #------------
2179 
2180         self.mainPnl = MyMainPnl(self, -1, (w, h-31))
2181         self.mainPnl.SetPosition((0, 31))
2182         print("self.mainPnl :", self.mainPnl.GetSize())
2183 
2184 
2185     def BindEvents(self):
2186         """
2187         ...
2188         """
2189 
2190         self.titleBarPnl.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
2191 
2192         self.Bind(wx.EVT_SIZE, self.OnResize)
2193         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
2194         self.Bind(wx.EVT_MOTION, self.OnMouseMove)
2195         self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyUp)
2196         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
2197 
2198         self.Bind(wx.EVT_MENU, self.OnFullScreen, id=ID_FULLSCREEN)
2199         self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)
2200         self.Bind(wx.EVT_MENU, self.OnCloseWindow, id=wx.ID_EXIT)
2201 
2202 
2203     def DoLayout(self):
2204         """
2205         ...
2206         """
2207 
2208         # MainSizer is the top-level one that manages everything.
2209         mainSizer = wx.BoxSizer(wx.VERTICAL)
2210 
2211         mbSizer = wx.BoxSizer(wx.HORIZONTAL)
2212         mbSizer.Add(self.menuBar, 1, wx.ALL, 0)
2213 
2214         mainSizer.Add(self.titleBarPnl, 1, wx.EXPAND, 0)
2215         mainSizer.Add(mbSizer, 0, wx.EXPAND, 0)
2216         mainSizer.Add(self.mainPnl, 1, wx.EXPAND, 0)
2217 
2218         # Finally, tell the panel to use the sizer for layout.
2219         self.SetSizer(mainSizer)
2220         self.Layout()
2221 
2222 
2223     def OnRoll(self, event) :
2224         """
2225         Thanks to Ray Pasco.
2226         """
2227 
2228         if not bool(self.isRolled) :
2229         # Set the flag to the state we want regardless of whether
2230         # or not it's in currently in the opposite state.
2231            self.RollUnRoll(wantToRoll=True)
2232 
2233         elif self.isRolled :   # UnRoll.
2234            # Set the flag to the state we want regardless of whether
2235            # or not it's in currently in the opposite state.
2236            self.RollUnRoll(wantToRoll=False)
2237 
2238         print("OnRoll :", self.GetClientSize())
2239 
2240 
2241     def RollUnRoll(self, wantToRoll) :
2242         """
2243         Thanks to Ray Pasco.
2244         """
2245 
2246         # Save the current size only if the Frame is not rolled up.
2247         if not bool(self.isRolled) :
2248             self.unrolledFrameClientSize_size = self.GetClientSize()
2249 
2250         if bool(wantToRoll) :   # UnRoll.
2251             # Set size (52).
2252             self.SetClientSize((self.unrolledFrameClientSize_size[0], 52))
2253             # Set to match this new state.
2254             self.isRolled = True
2255 
2256         else :   # Roll
2257             self.SetClientSize(self.unrolledFrameClientSize_size)
2258             # Set to match this new state.
2259             self.isRolled = False
2260 
2261         print("RollUnRoll :", self.GetClientSize())
2262 
2263 
2264     def OnAbout(self, event):
2265         """
2266         ...
2267         """
2268 
2269         self.dialog = MyAboutDlg(self)
2270 
2271 
2272     def OnLeftDown(self, event):
2273         """
2274         ...
2275         """
2276 
2277         self.CaptureMouse()
2278         x, y = self.ClientToScreen(event.GetPosition())
2279         originx, originy = self.GetPosition()
2280         dx = x - originx
2281         dy = y - originy
2282         self.delta = ((dx, dy))
2283 
2284 
2285     def OnLeftUp(self, evt):
2286         """
2287         ...
2288         """
2289 
2290         if self.HasCapture():
2291             self.ReleaseMouse()
2292 
2293 
2294     def OnMouseMove(self, event):
2295         """
2296         ...
2297         """
2298 
2299         if event.Dragging() and event.LeftIsDown():
2300             x, y = self.ClientToScreen(event.GetPosition())
2301             fp = (x - self.delta[0], y - self.delta[1])
2302             self.Move(fp)
2303 
2304 
2305     def OnIconfiy(self, event):
2306         """
2307         ...
2308         """
2309 
2310         self.Iconize()
2311 
2312 
2313     def OnResize(self, event):
2314         """
2315         ...
2316         """
2317 
2318         w, h = self.GetClientSize()
2319         print("self :", self.GetClientSize())
2320 
2321         #------------
2322         #------------
2323 
2324         self.titleBarPnl.SetSize((w, 31))
2325         self.menuBar.SetSize((w, -1))
2326         self.mainPnl.SetSize((w, h-54))
2327 
2328         #------------
2329 
2330         self.Refresh()
2331 
2332 
2333     def OnFullScreen(self, event):
2334         """
2335         ...
2336         """
2337 
2338         self.ShowFullScreen(not self.IsFullScreen(),
2339                             wx.BORDER_SIMPLE)
2340 
2341 
2342     def OnKeyUp(self, event):
2343         """
2344         ...
2345         """
2346 
2347         if event.GetKeyCode() == wx.WXK_ESCAPE:
2348             # Close the frame, no action.
2349             self.OnCloseWindow(event)
2350         event.Skip()
2351 
2352 
2353     def OnBtnClose(self, event):
2354         """
2355         ...
2356         """
2357 
2358         self.Close()
2359 
2360 
2361     def OnCloseWindow(self, event):
2362         """
2363         Quit this application.
2364         """
2365 
2366         # self.Destroy()
2367         self.OnTimerOut(self)
2368 
2369         print("Exit application.")
2370 
2371 #---------------------------------------------------------------------------
2372 
2373 class MyApp(wx.App):
2374     """
2375     Thanks to Andrea Gavana.
2376     """
2377     def OnInit(self):
2378 
2379         #------------
2380 
2381         self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
2382 
2383         #------------
2384 
2385         self.SetAppName("Custom Gui 1")
2386 
2387         #------------
2388 
2389         self.installDir = os.path.split(os.path.abspath(sys.argv[0]))[0]
2390 
2391         #------------
2392 
2393         frame = MyFrame()
2394         self.SetTopWindow(frame)
2395         frame.Show(True)
2396         return True
2397 
2398     #-----------------------------------------------------------------------
2399 
2400     def GetInstallDir(self):
2401         """
2402         Returns the installation directory for my application.
2403         """
2404 
2405         return self.installDir
2406 
2407 
2408     def GetIconsDir(self):
2409         """
2410         Returns the icons directory for my application.
2411         """
2412 
2413         icons_dir = os.path.join(self.installDir, "icons")
2414         return icons_dir
2415 
2416 
2417     def GetBitmapsDir(self):
2418         """
2419         Returns the bitmaps directory for my application.
2420         """
2421 
2422         bitmaps_dir = os.path.join(self.installDir, "bitmaps")
2423         return bitmaps_dir
2424 
2425 
2426     def GetConfig(self):
2427         """
2428         Returns the config file for my application.
2429         """
2430 
2431         config = wx.FileConfig(appName="Custom Gui",
2432                                localFilename=os.path.join(self.installDir,
2433                                                           "options"))
2434         return config
2435 
2436 #---------------------------------------------------------------------------
2437 
2438 def main():
2439     app = MyApp(False)
2440     app.MainLoop()
2441 
2442 #---------------------------------------------------------------------------
2443 
2444 if __name__ == "__main__" :
2445     main()


Second example

img_sample_two.png