Configtool: give the thing a nice background picture.

This is pure dessert topping, no functinal change. Well, eye candy
is important for acceptance. :-)
This commit is contained in:
Markus Hitter 2015-05-24 16:43:53 +02:00
parent 104ed2f503
commit be16c98e59
6 changed files with 77 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import inspect
cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(
inspect.currentframe()))[0])) inspect.currentframe()))[0]))
from configtool.decoration import Decoration
from configtool.settings import Settings, SettingsDlg from configtool.settings import Settings, SettingsDlg
from configtool.printerpanel import PrinterPanel from configtool.printerpanel import PrinterPanel
from configtool.boardpanel import BoardPanel from configtool.boardpanel import BoardPanel
@ -45,7 +46,10 @@ class ConfigFrame(wx.Frame):
wx.Frame.__init__(self, None, -1, "Teacup Configtool", size = (880, 550)) wx.Frame.__init__(self, None, -1, "Teacup Configtool", size = (880, 550))
self.Bind(wx.EVT_CLOSE, self.onClose) self.Bind(wx.EVT_CLOSE, self.onClose)
self.deco = Decoration()
panel = wx.Panel(self, -1) panel = wx.Panel(self, -1)
panel.Bind(wx.EVT_PAINT, self.deco.onPaintBackground)
self.settings = Settings(self, cmd_folder) self.settings = Settings(self, cmd_folder)
self.settings.font = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, self.settings.font = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,

BIN
configtool/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -4,6 +4,7 @@ import wx
import re import re
from sys import platform from sys import platform
from configtool.decoration import Decoration
from configtool.data import (defineValueFormat, from configtool.data import (defineValueFormat,
defineBoolFormat, defineHeaterFormat, reCommDefBL, defineBoolFormat, defineHeaterFormat, reCommDefBL,
reCommDefBoolBL, reHelpTextStart, reHelpTextEnd, reCommDefBoolBL, reHelpTextStart, reHelpTextEnd,
@ -30,6 +31,7 @@ class BoardPanel(wx.Panel):
self.settings = settings self.settings = settings
self.protFileLoaded = False self.protFileLoaded = False
self.deco = Decoration()
self.configFile = None self.configFile = None
self.cfgValues = {} self.cfgValues = {}
@ -39,6 +41,7 @@ class BoardPanel(wx.Panel):
self.candThermPins = [] self.candThermPins = []
self.dir = os.path.join(self.settings.folder, "config") self.dir = os.path.join(self.settings.folder, "config")
self.Bind(wx.EVT_PAINT, self.deco.onPaintBackground)
sz = wx.BoxSizer(wx.HORIZONTAL) sz = wx.BoxSizer(wx.HORIZONTAL)
self.nb = wx.Notebook(self, wx.ID_ANY, size = (21, 21), self.nb = wx.Notebook(self, wx.ID_ANY, size = (21, 21),

64
configtool/decoration.py Normal file
View File

@ -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()

View File

@ -1,6 +1,7 @@
import wx import wx
from configtool.decoration import Decoration
from configtool.data import reInteger, reFloat, offsetChLabel, offsetTcLabel from configtool.data import reInteger, reFloat, offsetChLabel, offsetTcLabel
@ -14,8 +15,10 @@ class Page:
self.radioButtons = {} self.radioButtons = {}
self.radioButtonBoxes = {} self.radioButtonBoxes = {}
self.choices = {} self.choices = {}
self.deco = Decoration()
self.font = font self.font = font
self.Bind(wx.EVT_PAINT, self.deco.onPaintBackground)
def enableAll(self, flag = True): def enableAll(self, flag = True):
for c in self.textControls.keys(): for c in self.textControls.keys():

View File

@ -4,6 +4,7 @@ import wx
import re import re
from sys import platform from sys import platform
from configtool.decoration import Decoration
from configtool.data import (defineValueFormat, defineBoolFormat, reCommDefBL, from configtool.data import (defineValueFormat, defineBoolFormat, reCommDefBL,
reCommDefBoolBL, reHelpTextStart, reHelpTextEnd, reCommDefBoolBL, reHelpTextStart, reHelpTextEnd,
reDefine, reDefineBL, reDefQS, reDefQSm, reDefine, reDefineBL, reDefQS, reDefQSm,
@ -19,6 +20,7 @@ class PrinterPanel(wx.Panel):
wx.Panel.__init__(self, nb, wx.ID_ANY) wx.Panel.__init__(self, nb, wx.ID_ANY)
self.parent = parent self.parent = parent
self.deco = Decoration()
self.configFile = None self.configFile = None
self.protFileLoaded = False self.protFileLoaded = False
@ -28,6 +30,7 @@ class PrinterPanel(wx.Panel):
self.heaters = [] self.heaters = []
self.dir = os.path.join(self.settings.folder, "config") self.dir = os.path.join(self.settings.folder, "config")
self.Bind(wx.EVT_PAINT, self.deco.onPaintBackground)
sz = wx.BoxSizer(wx.HORIZONTAL) sz = wx.BoxSizer(wx.HORIZONTAL)
self.nb = wx.Notebook(self, wx.ID_ANY, size = (21, 21), self.nb = wx.Notebook(self, wx.ID_ANY, size = (21, 21),