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