From fb5dee2166956630f9846355427cb6653775d798 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 2 Feb 2014 00:35:37 +0000 Subject: [PATCH] Add settings --- vis/config.py | 35 +++++++++- vis/main.py | 2 +- vis/settings.cfg | 9 +++ vis/visual.py | 23 ++++++- vis/visual.ui | 172 ++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 228 insertions(+), 13 deletions(-) create mode 100644 vis/settings.cfg diff --git a/vis/config.py b/vis/config.py index 652ad64..b40d09b 100644 --- a/vis/config.py +++ b/vis/config.py @@ -1,3 +1,36 @@ +from ConfigParser import ConfigParser + class Config: + # Attributes + filename = "settings.cfg" + + defaults = { + 'baudrate': '9600', + 'stopbits': '1', + 'databits': '8', + 'username': '', + 'password': '', + 'apikey': '', + } + + # Constructor def __init__(self): - pass + self.parser = ConfigParser(defaults=self.defaults) + self.parser.add_section('serial') + self.parser.add_section('xively') + self.load() + + # Methods + def load(self): + self.parser.read(self.filename) + + self.baudrate = self.parser.getint('serial', 'baudrate') + self.stopbits = self.parser.getint('serial', 'stopbits') + self.databits = self.parser.getint('serial', 'databits') + + self.username = self.parser.get('xively', 'username') + self.password = self.parser.get('xively', 'password') + self.apikey = self.parser.get('xively', 'apikey') + + def save(self): + self.parser.write(self.filename) diff --git a/vis/main.py b/vis/main.py index 605bc30..897a4f7 100755 --- a/vis/main.py +++ b/vis/main.py @@ -10,7 +10,7 @@ class Main: self.config = Config(); self.xively = Xively(); self.serial = Serial(); - self.visual = Visual(); + self.visual = Visual(self.config); def main(self): self.visual.run() diff --git a/vis/settings.cfg b/vis/settings.cfg new file mode 100644 index 0000000..2ce5b07 --- /dev/null +++ b/vis/settings.cfg @@ -0,0 +1,9 @@ +[serial] +buadrate = 9600 +stopbits = 1 +databits = 8 + +[xively] +username = andy +password = open sesame +apikey = magic diff --git a/vis/visual.py b/vis/visual.py index 0d3550e..aed73ae 100644 --- a/vis/visual.py +++ b/vis/visual.py @@ -4,12 +4,13 @@ import pygtk import gtk class Visual: - def __init__(self): + def __init__(self, config): self.builder = gtk.Builder() self.builder.add_from_file('visual.ui') self.builder.connect_signals(self) self.window = self.builder.get_object("window") self.settings = self.builder.get_object("settings") + self.config = config # Signal handlers def on_hide(self, win, *args): @@ -40,6 +41,26 @@ class Visual: gtk.main_quit() # Methods + def load_config(self): + # Serial settings + baud = self.builder.get_object("baudrate") + stopb = self.builder.get_object("stopbits") + datab = self.builder.get_object("databits") + baud.set_value(self.config.baudrate) + stopb.set_value(self.config.stopbits) + datab.set_value(self.config.databits) + + # Xively settings + user = self.builder.get_object("username") + pwd = self.builder.get_object("password") + api = self.builder.get_object("apikey") + user.set_text(self.config.username) + pwd.set_text(self.config.password) + api.set_text(self.config.apikey) + + # TODO - send changes back to config + def run(self): + self.load_config() self.window.show() gtk.main() diff --git a/vis/visual.ui b/vis/visual.ui index 0ac54bf..6b6209f 100644 --- a/vis/visual.ui +++ b/vis/visual.ui @@ -2,6 +2,11 @@ + + Xively + gtk-connect + + 100 1 @@ -14,6 +19,17 @@ 1 10 + + 1.7976931348623157e+308 + 1 + 10 + + + 6 + 8 + 1 + 10 + 100 1 @@ -26,22 +42,23 @@ 1 10 - - - Serial - gtk-connect - - Settings gtk-preferences - - Xively + + + Serial gtk-connect + + 1 + 2 + 1 + 10 + False 5 @@ -82,6 +99,140 @@ 0 + + + True + False + 0 + none + + + True + False + 12 + + + True + False + 3 + 2 + 20 + + + True + False + 0 + Baud rate + + + GTK_FILL + GTK_FILL + + + + + True + False + 0 + Stop bits + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + False + 0 + Data bits + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + True + ● + False + False + True + True + baud_adj + + + 1 + 2 + GTK_FILL + + + + + True + True + ● + False + False + True + True + stopb_adj + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + True + True + ● + False + False + True + True + datab_adj + + + 1 + 2 + 2 + 3 + GTK_FILL + + + + + + + + + True + False + Serial Settings + + + + + + + + False + True + 1 + + True @@ -145,6 +296,7 @@ True True ● + True False False True @@ -210,9 +362,9 @@ - True + False True - 1 + 2 -- 2.43.2