filename = "settings.cfg"
defaults = {
- 'baudrate': '/dev/ttyACM0',
- 'baudrate': '9600',
- 'parity': 'N',
- 'databits': '8',
- 'stopbits': '1',
- 'username': '<username>',
- 'password': '<password>',
- 'apikey': '<apikey>',
+ 'serial': {
+ 'device': '/dev/ttyACM0',
+ 'baudrate': '9600',
+ 'parity': 'N',
+ 'databits': '8',
+ 'stopbits': '1',
+ },
+ 'xively': {
+ 'feedid': '<feedid>',
+ 'apikey': '<apikey>',
+ 'maxrate': '6',
+ }
}
# Constructor
def __init__(self):
- self.parser = ConfigParser(defaults=self.defaults)
+ self.parser = ConfigParser()
self.parser.add_section('serial')
self.parser.add_section('xively')
self.load()
# Methods
def load(self):
- self.parser.read(self.filename)
+ def get(sect, name):
+ if self.parser.has_option(sect, name):
+ return self.parser.get(sect, name)
+ else:
+ return self.defaults[sect][name]
- self.device = self.parser.get('serial', 'device')
- self.baudrate = self.parser.getint('serial', 'baudrate')
- self.parity = self.parser.get('serial', 'parity')
- self.databits = self.parser.getint('serial', 'databits')
- self.stopbits = self.parser.getint('serial', 'stopbits')
+ self.parser.read(self.filename)
- self.username = self.parser.get('xively', 'username')
- self.password = self.parser.get('xively', 'password')
- self.apikey = self.parser.get('xively', 'apikey')
+ self.device = get('serial', 'device')
+ self.baudrate = int(get('serial', 'baudrate'))
+ self.parity = get('serial', 'parity')
+ self.databits = int(get('serial', 'databits'))
+ self.stopbits = int(get('serial', 'stopbits'))
+
+ self.feedid = get('xively', 'feedid')
+ self.apikey = get('xively', 'apikey')
+ self.maxrate = int(get('xively', 'maxrate'))
def save(self):
- self.parser.write(self.filename)
+ self.parser.set('serial', 'device', self.device)
+ self.parser.set('serial', 'baudrate', str(int(self.baudrate)))
+ self.parser.set('serial', 'parity', self.parity)
+ self.parser.set('serial', 'databits', str(int(self.databits)))
+ self.parser.set('serial', 'stopbits', str(int(self.stopbits)))
+
+ self.parser.set('xively', 'feedid', self.feedid)
+ self.parser.set('xively', 'apikey', self.apikey)
+ self.parser.set('xively', 'maxrate', str(int(self.maxrate)))
+
+ with open(self.filename, 'w') as fd:
+ self.parser.write(fd)
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
+ <object class="GtkToggleAction" id="serial_con">
+ <property name="label" translatable="yes">Serial</property>
+ <property name="stock_id">gtk-connect</property>
+ <signal name="activate" handler="on_serial" swapped="no"/>
+ </object>
+ <object class="GtkAction" id="settings_act">
+ <property name="label" translatable="yes">Settings</property>
+ <property name="stock_id">gtk-preferences</property>
+ <signal name="activate" handler="on_show" swapped="no"/>
+ </object>
<object class="GtkAdjustment" id="a2d_adj">
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
- <object class="GtkTextBuffer" id="serial_buf"/>
- <object class="GtkToggleAction" id="serial_con">
- <property name="label" translatable="yes">Serial</property>
- <property name="stock_id">gtk-connect</property>
- <signal name="activate" handler="on_serial" swapped="no"/>
- </object>
- <object class="GtkAction" id="settings_act">
- <property name="label" translatable="yes">Settings</property>
- <property name="stock_id">gtk-preferences</property>
- <signal name="activate" handler="on_show" swapped="no"/>
- </object>
- <object class="GtkToggleAction" id="xively_con">
- <property name="label" translatable="yes">Xively</property>
- <property name="stock_id">gtk-connect</property>
- <signal name="activate" handler="on_xively" swapped="no"/>
+ <object class="GtkAdjustment" id="rate_adj">
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
</object>
+ <object class="GtkTextBuffer" id="serial_buf"/>
<object class="GtkDialog" id="settings">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="adjustment">baud_adj</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="adjustment">stopb_adj</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="adjustment">datab_adj</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="n_columns">2</property>
<property name="column_spacing">20</property>
<child>
- <object class="GtkLabel" id="user_lbl">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Username</property>
- </object>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="pass_lbl">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Password</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="api_lbl">
+ <object class="GtkLabel" id="feed_llb">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">API Key</property>
+ <property name="ypad">8</property>
+ <property name="label" translatable="yes">Feed ID</property>
</object>
<packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkEntry" id="username">
+ <object class="GtkEntry" id="feedid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
</packing>
</child>
<child>
- <object class="GtkEntry" id="password">
+ <object class="GtkEntry" id="apikey">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
</packing>
</child>
<child>
- <object class="GtkEntry" id="apikey">
+ <object class="GtkLabel" id="api_lbl">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">API Key</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="rate_lbl">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Max Rate</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="maxrate">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
- <property name="invisible_char_set">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
+ <property name="adjustment">rate_adj</property>
+ <signal name="changed" handler="on_config" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkToggleAction" id="xively_con">
+ <property name="label" translatable="yes">Xively</property>
+ <property name="stock_id">gtk-connect</property>
+ <signal name="activate" handler="on_xively" swapped="no"/>
+ </object>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<signal name="destroy" handler="on_destroy" swapped="no"/>
</object>
</child>
</object>
+ <object class="GtkSizeGroup" id="settings_lbls">
+ <widgets>
+ <widget name="feed_llb"/>
+ <widget name="api_lbl"/>
+ <widget name="rate_lbl"/>
+ <widget name="device_lbl"/>
+ </widgets>
+ </object>
</interface>