diff --git a/configtool.py b/configtool.py index f9bef25..ccb5c36 100755 --- a/configtool.py +++ b/configtool.py @@ -21,6 +21,7 @@ import inspect cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe()))[0])) +from configtool.decoration import Decoration from configtool.settings import Settings, SettingsDlg from configtool.printerpanel import PrinterPanel from configtool.boardpanel import BoardPanel @@ -45,7 +46,10 @@ class ConfigFrame(wx.Frame): wx.Frame.__init__(self, None, -1, "Teacup Configtool", size = (880, 550)) self.Bind(wx.EVT_CLOSE, self.onClose) + self.deco = Decoration() + panel = wx.Panel(self, -1) + panel.Bind(wx.EVT_PAINT, self.deco.onPaintBackground) self.settings = Settings(self, cmd_folder) self.settings.font = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, diff --git a/configtool/background.png b/configtool/background.png new file mode 100644 index 0000000..bc15d52 Binary files /dev/null and b/configtool/background.png differ diff --git a/configtool/boardpanel.py b/configtool/boardpanel.py index 3457672..8277fd8 100644 --- a/configtool/boardpanel.py +++ b/configtool/boardpanel.py @@ -4,6 +4,7 @@ import wx import re from sys import platform +from configtool.decoration import Decoration from configtool.data import (defineValueFormat, defineBoolFormat, defineHeaterFormat, reCommDefBL, reCommDefBoolBL, reHelpTextStart, reHelpTextEnd, @@ -30,6 +31,7 @@ class BoardPanel(wx.Panel): self.settings = settings self.protFileLoaded = False + self.deco = Decoration() self.configFile = None self.cfgValues = {} @@ -39,6 +41,7 @@ class BoardPanel(wx.Panel): self.candThermPins = [] self.dir = os.path.join(self.settings.folder, "config") + self.Bind(wx.EVT_PAINT, self.deco.onPaintBackground) sz = wx.BoxSizer(wx.HORIZONTAL) self.nb = wx.Notebook(self, wx.ID_ANY, size = (21, 21), diff --git a/configtool/decoration.py b/configtool/decoration.py new file mode 100644 index 0000000..ec500b9 --- /dev/null +++ b/configtool/decoration.py @@ -0,0 +1,64 @@ + +import wx +import os.path + + +class Decoration(object): + def __new__(type, *args): + # Make it a Singleton. + if not '_the_instance' in type.__dict__: + type._the_instance = object.__new__(type) + + return type._the_instance + + def __init__(self): + if not '_ready' in dir(self): + self._ready = True + # It's a Singleton. Initialisations go in here. + self.backPic = None + self.backPicOffset = (0, -25) + + if not self.backPic: + backPicPath = os.path.join("configtool", "background.png") + if os.path.exists(backPicPath): + backPic = wx.Bitmap(backPicPath) + if backPic.IsOk(): + self.backPic = backPic + else: + print "Background picture %s damaged." % backPicPath + else: + print "Background picture %s doesn't exist." % backPicPath + + # On wxFrames, bind this to wx.EVT_ERASE_BACKGROUND + # On wxPanels, bind this to wx.EVT_PAINT + def onPaintBackground(self, evt): + client = evt.GetEventObject() + topLevel = client.GetTopLevelParent() + + try: + dc = evt.GetDC() + except: + dc = wx.PaintDC(client) + + if dc: + # Now draw the background picture with pseudo-transparency. This is, + # each background is drawn with the same picture, without transparency, + # and offsetted just right to have all backgrounds in the same position + # relative to the *toplevel* window, not relative to the current + # subwindow as usual. + + # Align bottom right. + offX, offY = topLevel.GetClientSize() - self.backPic.GetSize() + \ + self.backPicOffset + + if client != topLevel: + # Note: trying to figure this additional offset via various + # .GetScreenPosition() or .GetPosition() or whatever is hopeless. + # Of many many tries only this worked on Linux. + offX, offY = \ + client.ScreenToClient(topLevel.ClientToScreen((offX, offY))) + + if self.backPic: + dc.DrawBitmap(self.backPic, offX, offY) + + evt.Skip() diff --git a/configtool/page.py b/configtool/page.py index 1fd8d31..293b236 100644 --- a/configtool/page.py +++ b/configtool/page.py @@ -1,6 +1,7 @@ import wx +from configtool.decoration import Decoration from configtool.data import reInteger, reFloat, offsetChLabel, offsetTcLabel @@ -14,8 +15,10 @@ class Page: self.radioButtons = {} self.radioButtonBoxes = {} self.choices = {} + self.deco = Decoration() self.font = font + self.Bind(wx.EVT_PAINT, self.deco.onPaintBackground) def enableAll(self, flag = True): for c in self.textControls.keys(): diff --git a/configtool/printerpanel.py b/configtool/printerpanel.py index abccb49..4b0670f 100644 --- a/configtool/printerpanel.py +++ b/configtool/printerpanel.py @@ -4,6 +4,7 @@ import wx import re from sys import platform +from configtool.decoration import Decoration from configtool.data import (defineValueFormat, defineBoolFormat, reCommDefBL, reCommDefBoolBL, reHelpTextStart, reHelpTextEnd, reDefine, reDefineBL, reDefQS, reDefQSm, @@ -19,6 +20,7 @@ class PrinterPanel(wx.Panel): wx.Panel.__init__(self, nb, wx.ID_ANY) self.parent = parent + self.deco = Decoration() self.configFile = None self.protFileLoaded = False @@ -28,6 +30,7 @@ class PrinterPanel(wx.Panel): self.heaters = [] self.dir = os.path.join(self.settings.folder, "config") + self.Bind(wx.EVT_PAINT, self.deco.onPaintBackground) sz = wx.BoxSizer(wx.HORIZONTAL) self.nb = wx.Notebook(self, wx.ID_ANY, size = (21, 21),