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