diff --git a/dstat_interface/experiments/experiment_template.py b/dstat_interface/experiments/experiment_template.py index 33ece7d7fc401af85d281c640ffc898e06fa768c..88c5a39aaf858a8ea98085aac1d996db58d6f4a6 100755 --- a/dstat_interface/experiments/experiment_template.py +++ b/dstat_interface/experiments/experiment_template.py @@ -27,7 +27,7 @@ from math import ceil try: import gi gi.require_version('Gtk', '3.0') - from gi.repository import Gtk + from gi.repository import Gtk, GObject except ImportError: print "ERR: GTK not available" sys.exit(1) diff --git a/dstat_interface/interface/exp_int.py b/dstat_interface/interface/exp_int.py index 3e1cb6790db67a248aaf391be83c32b4acab03d7..83ebfac7460b5d458d849f156de49ea728fa2aec 100755 --- a/dstat_interface/interface/exp_int.py +++ b/dstat_interface/interface/exp_int.py @@ -38,14 +38,21 @@ import __main__ from errors import InputError, VarError logger = logging.getLogger("dstat.interface.exp_int") -class ExpInterface(object): +class ExpInterface(GObject.Object): """Generic experiment interface class. Should be subclassed to implement experiment interfaces by populating self.entry. Override class attributes to set id and experiment class to run. """ + __gsignals__ = { + b'run_utility': (GObject.SIGNAL_RUN_FIRST, None, ()), + b'done_utility': (GObject.SIGNAL_RUN_FIRST, None, ()) + } + id = None experiment = None + def __init__(self, glade_path): + super(ExpInterface, self).__init__() self.builder = Gtk.Builder() self.builder.add_from_file(glade_path) self.builder.connect_signals(self) @@ -86,7 +93,11 @@ class ExpInterface(object): def get_window(self): return self.builder.get_object('scrolledwindow1') - + def on_run_utility(self, data=None): + self.emit('run_utility') + def on_done_utility(self, data=None): + self.emit('done_utility') + class Chronoamp(ExpInterface): """Experiment class for chronoamperometry. Extends ExpInterface class to support treeview neeeded for CA. @@ -176,9 +187,10 @@ class Chronoamp(ExpInterface): class EIS(ExpInterface): """Experiment class for EIS.""" id = 'eis' + experiment = exp.EISExp def __init__(self): - experiment = exp.EISExp """Adds entry listings to superclass's self.entry dict""" + super(ExpInterface, self).__init__() # initialize GObject self.name = "Impedance Spectroscopy" self.entry = {} # to be used only for str parameters diff --git a/dstat_interface/interface/exp_window.py b/dstat_interface/interface/exp_window.py index 8e7c0a3ec24f07bcdc02e5b557ab259b6e385499..413d43a2e8d00a8004ffc7bf0ac432448c3dad68 100755 --- a/dstat_interface/interface/exp_window.py +++ b/dstat_interface/interface/exp_window.py @@ -21,12 +21,25 @@ import inspect import logging from collections import OrderedDict +try: + import gi + gi.require_version('Gtk', '3.0') + from gi.repository import Gtk, GObject +except ImportError: + print "ERR: GTK not available" + sys.exit(1) + import interface.exp_int as exp logger = logging.getLogger("dstat.interface.exp_window") -class Experiments: +class Experiments(GObject.Object): + __gsignals__ = { + 'run_utility': (GObject.SIGNAL_RUN_FIRST, None, ()), + 'done_utility': (GObject.SIGNAL_RUN_FIRST, None, ()) + } def __init__(self, builder): + super(Experiments,self).__init__() self.builder = builder self.builder.connect_signals(self) @@ -39,12 +52,13 @@ class Experiments: } self.classes = OrderedDict(sorted(classes.items())) - #fill exp_section exp_section = self.builder.get_object('exp_section_box') self.containers = {} for key, c in self.classes.items(): + c.connect('run_utility', self.on_run_utility) + c.connect('done_utility', self.on_done_utility) self.containers[key] = c.get_window() for key in self.containers: @@ -61,6 +75,12 @@ class Experiments: for c in self.classes.values(): self.expcombobox.append(id=c.id, text=c.name) + def on_run_utility(self, data=None): + self.emit('run_utility') + + def on_done_utility(self, data=None): + self.emit('done_utility') + def on_expcombobox_changed(self, data=None): """Change the experiment window when experiment box changed.""" self.set_exp(self.expcombobox.get_active_id()) diff --git a/dstat_interface/main.py b/dstat_interface/main.py index b0d5cb4fcfb7be78e9f08875e34cd84ef30ad9eb..f1a082ffd1b5aa7cf0235291379fb9fe01a08c46 100755 --- a/dstat_interface/main.py +++ b/dstat_interface/main.py @@ -98,6 +98,9 @@ class Main(object): self.message_context_id = self.statusbar.get_context_id("message") self.exp_window = exp_window.Experiments(self.builder) + self.exp_window.connect('run_utility', self.stop_ocp) + self.exp_window.connect('done_utility', self.start_ocp) + self.analysis_opt_window = analysis.AnalysisOptions(self.builder) # Setup Autosave @@ -280,7 +283,7 @@ class Main(object): self.adc_pot.ui['short_true'].set_sensitive(False) self.on_serial_connect_clicked() - def start_ocp(self): + def start_ocp(self, data=None): """Start OCP measurements.""" if state.dstat_version[0] >= 1 and state.dstat_version[1] >= 2: @@ -304,7 +307,7 @@ class Main(object): logger.info("OCP measurements not supported on v1.1 boards.") return - def stop_ocp(self): + def stop_ocp(self, data=None): """Stop OCP measurements.""" if state.dstat_version[0] >= 1 and state.dstat_version[1] >= 2: