From 50bbb468b7d491f267fcfec2c1f4510ee89e5ff0 Mon Sep 17 00:00:00 2001 From: LSaldyt Date: Wed, 25 Oct 2017 20:06:10 -0700 Subject: [PATCH] Separates style --- copycat/gui/entry.py | 6 +++--- copycat/gui/gui.py | 3 +++ copycat/gui/style.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 copycat/gui/style.py diff --git a/copycat/gui/entry.py b/copycat/gui/entry.py index a8e9d53..7b4a17c 100644 --- a/copycat/gui/entry.py +++ b/copycat/gui/entry.py @@ -8,19 +8,19 @@ class Entry(GridFrame): def __init__(self, parent, *args, **kwargs): GridFrame.__init__(self, parent, *args, **kwargs) self.aLabel = ttk.Label(self, text='Initial:') - self.a = ttk.Entry(self) + self.a = ttk.Entry(self, style='EntryStyle.TEntry') self.add(self.aLabel, 0, 0) self.add(self.a, 0, 1) self.bLabel = ttk.Label(self, text='Final:') - self.b = ttk.Entry(self) + self.b = ttk.Entry(self, style='EntryStyle.TEntry') self.add(self.bLabel, 1, 0) self.add(self.b, 1, 1) self.cLabel = ttk.Label(self, text='Next:') - self.c = ttk.Entry(self) + self.c = ttk.Entry(self, style='EntryStyle.TEntry') self.add(self.cLabel, 2, 0) self.add(self.c, 2, 1) diff --git a/copycat/gui/gui.py b/copycat/gui/gui.py index 8508175..b4f2bdf 100755 --- a/copycat/gui/gui.py +++ b/copycat/gui/gui.py @@ -13,6 +13,7 @@ from .status import Status, StatusFrame from .gridframe import GridFrame from .primary import Primary from .list import List +from .style import configure_style from .plot import plot_imbedded @@ -86,6 +87,8 @@ class GUI(object): self.app = MainApplication(self.root) self.app.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W) + configure_style(ttk.Style()) + self.lastUpdated = time.time() self.updateInterval = updateInterval diff --git a/copycat/gui/style.py b/copycat/gui/style.py new file mode 100644 index 0000000..a8bca07 --- /dev/null +++ b/copycat/gui/style.py @@ -0,0 +1,33 @@ +style_dict = dict(foreground='white', + background='black') + +map_options = dict( + foreground=[('disabled', 'black'), + ('pressed', 'white'), + ('active', 'white')], + background=[('disabled', 'black'), + ('pressed', '!focus', 'black'), + ('active', 'black')], + highlightcolor=[('focus', 'black'), + ('!focus', 'black')]) + +def configure_style(style): + style.configure('TButton', **style_dict) + style.map('TButton', **map_options) + style.configure('TLabel', **style_dict) + #style.configure('TEntry', **style_dict) + #style.map('TEntry', **map_options) + + # A hack to change entry style + style.element_create("plain.field", "from", "clam") + style.layout("EntryStyle.TEntry", + [('Entry.plain.field', {'children': [( + 'Entry.background', {'children': [( + 'Entry.padding', {'children': [( + 'Entry.textarea', {'sticky': 'nswe'})], + 'sticky': 'nswe'})], 'sticky': 'nswe'})], + 'border':'2', 'sticky': 'nswe'})]) + style.configure("EntryStyle.TEntry", + background="black", + foreground="white", + fieldbackground="black")