Пример #1
0
 def set_filename(self, fn):
     print fn, "selected for opening"
     #success = False
     try:
         if not os.path.exists(fn):
             raise ValueError("File doesn't exist")
         self._et = EventTable(fn)
         if len(self._et.keys()) == 0:
             print self._et.keys()
             raise ValueError("EventTable empty!")
         self._fn = fn
     except ValueError, e:
         print "Error opening EventTable", e
         self._et = None
         self._fn = None
         return False
Пример #2
0
 def add(self, fn):
     iter = self.tree.append(None)
     self.tree.set(iter, 0, os.path.split(fn)[1])
     self.tree.set(iter, 1, 0)
     self.tree.set_sort_column_id(0, gtk.SORT_ASCENDING)
     self.etDict[os.path.split(fn)[1]] = EventTable(fn)
     print self.etDict
     for k in self.etDict.keys():
         print "Keys: ", self.etDict[k].keys()
Пример #3
0
    def __init__(self, label=""):
        gtk.Frame.__init__(self, label)
        self.vbox = gtk.VBox()
        self.tb_box = gtk.HBox()
        self.add(self.vbox)
        self.vbox.pack_start(self.tb_box, expand=False)

        self.tb = gtk.Toolbar()
        self.tooltips = gtk.Tooltips()
        self.tb.set_style(gtk.TOOLBAR_ICONS)
        self.add_toolbutton_from_stock(gtk.STOCK_OPEN, 'Load',
                                       'Load an EventTable from a file',
                                       'Private', self.load_et)
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE, 'Save',
            'Save the EventTable back to the original file', 'Private',
            self.save_et, False)
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE_AS, 'Save to',
            'Save the EventTable to a file, choose new file', 'Private',
            self.save_et, True)
        self.tb.insert(gtk.SeparatorToolItem(), -1)
        self.add_toolbutton_eegpy("add_trigger_type", "Add type",
                                  "Add a new trigger type", 'Private',
                                  self.cb_add_trigger_type, None)
        self.add_toolbutton_eegpy("add_trigger", "Add trigger",
                                  "Add a new trigger", 'Private',
                                  self.cb_add_trigger, None)
        self.tb_box.pack_start(self.tb, expand=True)
        self.lb_fn = gtk.Label("New EventTable...")
        self.lb_fn.set_max_width_chars(50)
        self.lb_fn.set_justify(gtk.JUSTIFY_RIGHT)
        self.tb_box.pack_end(self.lb_fn, expand=False)
        #HBox für _keylist/triggerlist
        self.pane_kl = gtk.HPaned()
        self.vbox.pack_end(self.pane_kl)
        self.setup_trees()
        self._et = EventTable()
Пример #4
0
 def set_filename(self, fn):
     print fn, "selected for opening"
     # success = False
     try:
         if not os.path.exists(fn):
             raise ValueError("File doesn't exist")
         self._et = EventTable(fn)
         if len(self._et.keys()) == 0:
             print self._et.keys()
             raise ValueError("EventTable empty!")
         self._fn = fn
     except ValueError, e:
         print "Error opening EventTable", e
         self._et = None
         self._fn = None
         return False
Пример #5
0
def simple_erp_like_data(t_max=5000, Fs=2., peek_width=300):
    model = NRoessler(3)
    data = model.integrate(np.arange(0, t_max, 1. / Fs))
    events = EventTable({
        "before peeks":
        np.arange(500, t_max * Fs - 1000, 1000),
        "on peeks":
        np.arange(500 + peek_width / 2, t_max * Fs - 1000, 1000)
    })

    peek_data = np.hanning(peek_width)

    for e in events["before peeks"]:
        data[e:e + peek_width, 0] += peek_data * 20
        data[e:e + peek_width, 3] += peek_data * 6
        data[e:e + peek_width, 6] += peek_data * -14
    return data[:, 0::3], events
Пример #6
0
    def __init__(self, label=""):
        gtk.Frame.__init__(self, label)
        self.vbox = gtk.VBox()
        self.tb_box = gtk.HBox()
        self.add(self.vbox)
        self.vbox.pack_start(self.tb_box, expand=False)

        self.tb = gtk.Toolbar()
        self.tooltips = gtk.Tooltips()
        self.tb.set_style(gtk.TOOLBAR_ICONS)
        self.add_toolbutton_from_stock(
            gtk.STOCK_OPEN, "Load", "Load an EventTable from a file", "Private", self.load_et
        )
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE, "Save", "Save the EventTable back to the original file", "Private", self.save_et, False
        )
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE_AS,
            "Save to",
            "Save the EventTable to a file, choose new file",
            "Private",
            self.save_et,
            True,
        )
        self.tb.insert(gtk.SeparatorToolItem(), -1)
        self.add_toolbutton_eegpy(
            "add_trigger_type", "Add type", "Add a new trigger type", "Private", self.cb_add_trigger_type, None
        )
        self.add_toolbutton_eegpy(
            "add_trigger", "Add trigger", "Add a new trigger", "Private", self.cb_add_trigger, None
        )
        self.tb_box.pack_start(self.tb, expand=True)
        self.lb_fn = gtk.Label("New EventTable...")
        self.lb_fn.set_max_width_chars(50)
        self.lb_fn.set_justify(gtk.JUSTIFY_RIGHT)
        self.tb_box.pack_end(self.lb_fn, expand=False)
        # HBox für _keylist/triggerlist
        self.pane_kl = gtk.HPaned()
        self.vbox.pack_end(self.pane_kl)
        self.setup_trees()
        self._et = EventTable()
Пример #7
0
class EventManager(gtk.Frame):
    _et = None
    _fn = None
    _keylist = None

    def __init__(self, label=""):
        gtk.Frame.__init__(self, label)
        self.vbox = gtk.VBox()
        self.tb_box = gtk.HBox()
        self.add(self.vbox)
        self.vbox.pack_start(self.tb_box, expand=False)

        self.tb = gtk.Toolbar()
        self.tooltips = gtk.Tooltips()
        self.tb.set_style(gtk.TOOLBAR_ICONS)
        self.add_toolbutton_from_stock(
            gtk.STOCK_OPEN, "Load", "Load an EventTable from a file", "Private", self.load_et
        )
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE, "Save", "Save the EventTable back to the original file", "Private", self.save_et, False
        )
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE_AS,
            "Save to",
            "Save the EventTable to a file, choose new file",
            "Private",
            self.save_et,
            True,
        )
        self.tb.insert(gtk.SeparatorToolItem(), -1)
        self.add_toolbutton_eegpy(
            "add_trigger_type", "Add type", "Add a new trigger type", "Private", self.cb_add_trigger_type, None
        )
        self.add_toolbutton_eegpy(
            "add_trigger", "Add trigger", "Add a new trigger", "Private", self.cb_add_trigger, None
        )
        self.tb_box.pack_start(self.tb, expand=True)
        self.lb_fn = gtk.Label("New EventTable...")
        self.lb_fn.set_max_width_chars(50)
        self.lb_fn.set_justify(gtk.JUSTIFY_RIGHT)
        self.tb_box.pack_end(self.lb_fn, expand=False)
        # HBox für _keylist/triggerlist
        self.pane_kl = gtk.HPaned()
        self.vbox.pack_end(self.pane_kl)
        self.setup_trees()
        self._et = EventTable()

    def setup_trees(self):
        # First: Keys
        self.tvsw_keys = gtk.ScrolledWindow()
        self.tvsw_keys.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.tree_keys = gtk.TreeStore(gobject.TYPE_STRING)
        # self.treeS = gtk.TreeModelSort(self.tree)
        self.tv_keys = gtk.TreeView(self.tree_keys)
        self.tv_keys.get_selection().connect("changed", self.key_selected)
        # self.tv_keys.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        # renderer = gtk.CellRendererText()
        # self.col1 = gtk.TreeViewColumn("File ...", renderer,text=0)
        self.tv_keys.append_column(gtk.TreeViewColumn("Key", gtk.CellRendererText(), text=0))
        # self.tv_keys.show()
        self.tvsw_keys.add(self.tv_keys)
        self.pane_kl.add1(self.tvsw_keys)
        # Second: Triggers
        self.tvsw_tr = gtk.ScrolledWindow()
        self.tvsw_tr.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.tree_tr = gtk.TreeStore(gobject.TYPE_INT)
        # self.treeS = gtk.TreeModelSort(self.tree)
        self.tv_tr = gtk.TreeView(self.tree_tr)
        self.tv_tr.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        # renderer = gtk.CellRendererText()
        # self.col1 = gtk.TreeViewColumn("File ...", renderer,text=0)
        self.tv_tr.append_column(gtk.TreeViewColumn("Timepoint", gtk.CellRendererText(), text=0))
        # self.tv_keys.show()
        # Setting up drag'n'drop
        self.tv_tr.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK, [("INT", 0, 0)], gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE
        )
        self.tv_tr.enable_model_drag_dest([("INT", 0, 0)], gtk.gdk.ACTION_DEFAULT)

        self.tv_tr.connect("drag_data_get", self.tr_drag_get)
        self.tv_tr.connect("drag_data_received", self.tr_drag_received)
        self.tv_keys.connect("key_press_event", self.cb_key_pressed)
        self.tv_tr.connect("key_press_event", self.cb_key_pressed)

        self.tvsw_tr.add(self.tv_tr)
        self.pane_kl.add2(self.tvsw_tr)

    def add_toolbutton_eegpy(self, icon_name, text, tip_text, tip_private, clicked_function, clicked_param1=None):
        iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
        iconw = eegpy.ui.icon.image_from_eegpy_stock(icon_name)

        toolitem = gtk.ToolButton(iconw, text)
        # toolitem = gtk.ToolButton(iconw)
        toolitem.set_icon_widget(iconw)
        toolitem.show_all()
        toolitem.set_tooltip(self.tooltips, tip_text, tip_private)
        toolitem.connect("clicked", clicked_function, clicked_param1)
        # toolitem.connect("scroll_event", clicked_function)
        self.tb.insert(toolitem, -1)

    def add_toolbutton_from_stock(self, icon_name, text, tip_text, tip_private, clicked_function, clicked_param1=None):
        iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
        iconw = gtk.Image()
        iconw.set_from_stock(icon_name, iconSize)

        toolitem = gtk.ToolButton(iconw, text)
        # toolitem = gtk.ToolButton(iconw)
        toolitem.set_icon_widget(iconw)
        toolitem.show_all()
        toolitem.set_tooltip(self.tooltips, tip_text, tip_private)
        toolitem.connect("clicked", clicked_function, clicked_param1)
        # toolitem.connect("scroll_event", clicked_function)
        self.tb.insert(toolitem, -1)

    def load_et(self, event, data):
        dialog = gtk.FileChooserDialog(
            "Open EventTable from file..",
            None,
            gtk.FILE_CHOOSER_ACTION_OPEN,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK),
        )
        dialog.set_default_response(gtk.RESPONSE_OK)

        filter = gtk.FileFilter()
        filter.set_name("eegpy EventTable or similar")
        filter.add_pattern("*.evt")
        filter.add_pattern("*.vmrk")
        dialog.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        dialog.add_filter(filter)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            self.set_filename(dialog.get_filename())
            # print dialog.get_filename(), 'selected'
        elif response == gtk.RESPONSE_CANCEL:
            print "Closed, no files selected"
        dialog.destroy()

    def save_et(self, event, do_save_as=True):
        if do_save_as == False:
            self._et.save(self._fn)
        else:
            dialog = gtk.FileChooserDialog(
                "Save EventTable to file...",
                None,
                gtk.FILE_CHOOSER_ACTION_SAVE,
                (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK),
            )
            dialog.set_default_response(gtk.RESPONSE_OK)

            filter = gtk.FileFilter()
            filter.set_name("eegpy EventTable")
            filter.add_pattern("*.evt")
            dialog.add_filter(filter)

            filter = gtk.FileFilter()
            filter.set_name("All files")
            filter.add_pattern("*")
            dialog.add_filter(filter)

            response = dialog.run()
            if response == gtk.RESPONSE_OK:
                fn = dialog.get_filename()
                print fn, "selected"
                dialog.destroy()
                self._fn = fn
                # Now save...
                self._et.save(self._fn)
                lbtext = ""
                if len(fn) > 40:
                    lbtext = "..." + fn[-37:]
                self.lb_fn.set_text(lbtext)
                # fh.close()
            else:  # response == gtk.RESPONSE_CANCEL:
                dialog.destroy()
                print "Closed, no files selected"
            pass

    def set_filename(self, fn):
        print fn, "selected for opening"
        # success = False
        try:
            if not os.path.exists(fn):
                raise ValueError("File doesn't exist")
            self._et = EventTable(fn)
            if len(self._et.keys()) == 0:
                print self._et.keys()
                raise ValueError("EventTable empty!")
            self._fn = fn
        except ValueError, e:
            print "Error opening EventTable", e
            self._et = None
            self._fn = None
            return False
        lbtext = ""
        if len(fn) > 40:
            lbtext = "..." + fn[-37:]
        self.lb_fn.set_text(lbtext)
        self.setup_keylist()
Пример #8
0
class EventManager(gtk.Frame):
    _et = None
    _fn = None
    _keylist = None

    def __init__(self, label=""):
        gtk.Frame.__init__(self, label)
        self.vbox = gtk.VBox()
        self.tb_box = gtk.HBox()
        self.add(self.vbox)
        self.vbox.pack_start(self.tb_box, expand=False)

        self.tb = gtk.Toolbar()
        self.tooltips = gtk.Tooltips()
        self.tb.set_style(gtk.TOOLBAR_ICONS)
        self.add_toolbutton_from_stock(gtk.STOCK_OPEN, 'Load',
                                       'Load an EventTable from a file',
                                       'Private', self.load_et)
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE, 'Save',
            'Save the EventTable back to the original file', 'Private',
            self.save_et, False)
        self.add_toolbutton_from_stock(
            gtk.STOCK_SAVE_AS, 'Save to',
            'Save the EventTable to a file, choose new file', 'Private',
            self.save_et, True)
        self.tb.insert(gtk.SeparatorToolItem(), -1)
        self.add_toolbutton_eegpy("add_trigger_type", "Add type",
                                  "Add a new trigger type", 'Private',
                                  self.cb_add_trigger_type, None)
        self.add_toolbutton_eegpy("add_trigger", "Add trigger",
                                  "Add a new trigger", 'Private',
                                  self.cb_add_trigger, None)
        self.tb_box.pack_start(self.tb, expand=True)
        self.lb_fn = gtk.Label("New EventTable...")
        self.lb_fn.set_max_width_chars(50)
        self.lb_fn.set_justify(gtk.JUSTIFY_RIGHT)
        self.tb_box.pack_end(self.lb_fn, expand=False)
        #HBox für _keylist/triggerlist
        self.pane_kl = gtk.HPaned()
        self.vbox.pack_end(self.pane_kl)
        self.setup_trees()
        self._et = EventTable()

    def setup_trees(self):
        #First: Keys
        self.tvsw_keys = gtk.ScrolledWindow()
        self.tvsw_keys.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.tree_keys = gtk.TreeStore(gobject.TYPE_STRING)
        #self.treeS = gtk.TreeModelSort(self.tree)
        self.tv_keys = gtk.TreeView(self.tree_keys)
        self.tv_keys.get_selection().connect("changed", self.key_selected)
        #self.tv_keys.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        #renderer = gtk.CellRendererText()
        #self.col1 = gtk.TreeViewColumn("File ...", renderer,text=0)
        self.tv_keys.append_column(
            gtk.TreeViewColumn("Key", gtk.CellRendererText(), text=0))
        #self.tv_keys.show()
        self.tvsw_keys.add(self.tv_keys)
        self.pane_kl.add1(self.tvsw_keys)
        #Second: Triggers
        self.tvsw_tr = gtk.ScrolledWindow()
        self.tvsw_tr.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.tree_tr = gtk.TreeStore(gobject.TYPE_INT)
        #self.treeS = gtk.TreeModelSort(self.tree)
        self.tv_tr = gtk.TreeView(self.tree_tr)
        self.tv_tr.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        #renderer = gtk.CellRendererText()
        #self.col1 = gtk.TreeViewColumn("File ...", renderer,text=0)
        self.tv_tr.append_column(
            gtk.TreeViewColumn("Timepoint", gtk.CellRendererText(), text=0))
        #self.tv_keys.show()
        #Setting up drag'n'drop
        self.tv_tr.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK, [('INT', 0, 0)],
            gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE)
        self.tv_tr.enable_model_drag_dest([('INT', 0, 0)],
                                          gtk.gdk.ACTION_DEFAULT)

        self.tv_tr.connect("drag_data_get", self.tr_drag_get)
        self.tv_tr.connect("drag_data_received", self.tr_drag_received)
        self.tv_keys.connect("key_press_event", self.cb_key_pressed)
        self.tv_tr.connect("key_press_event", self.cb_key_pressed)

        self.tvsw_tr.add(self.tv_tr)
        self.pane_kl.add2(self.tvsw_tr)

    def add_toolbutton_eegpy(self,
                             icon_name,
                             text,
                             tip_text,
                             tip_private,
                             clicked_function,
                             clicked_param1=None):
        iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
        iconw = eegpy.ui.icon.image_from_eegpy_stock(icon_name)

        toolitem = gtk.ToolButton(iconw, text)
        #toolitem = gtk.ToolButton(iconw)
        toolitem.set_icon_widget(iconw)
        toolitem.show_all()
        toolitem.set_tooltip(self.tooltips, tip_text, tip_private)
        toolitem.connect("clicked", clicked_function, clicked_param1)
        #toolitem.connect("scroll_event", clicked_function)
        self.tb.insert(toolitem, -1)

    def add_toolbutton_from_stock(self,
                                  icon_name,
                                  text,
                                  tip_text,
                                  tip_private,
                                  clicked_function,
                                  clicked_param1=None):
        iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
        iconw = gtk.Image()
        iconw.set_from_stock(icon_name, iconSize)

        toolitem = gtk.ToolButton(iconw, text)
        #toolitem = gtk.ToolButton(iconw)
        toolitem.set_icon_widget(iconw)
        toolitem.show_all()
        toolitem.set_tooltip(self.tooltips, tip_text, tip_private)
        toolitem.connect("clicked", clicked_function, clicked_param1)
        #toolitem.connect("scroll_event", clicked_function)
        self.tb.insert(toolitem, -1)

    def load_et(self, event, data):
        dialog = gtk.FileChooserDialog("Open EventTable from file..", None,
                                       gtk.FILE_CHOOSER_ACTION_OPEN,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        dialog.set_default_response(gtk.RESPONSE_OK)

        filter = gtk.FileFilter()
        filter.set_name("eegpy EventTable or similar")
        filter.add_pattern("*.evt")
        filter.add_pattern("*.vmrk")
        dialog.add_filter(filter)

        filter = gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        dialog.add_filter(filter)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            self.set_filename(dialog.get_filename())
            #print dialog.get_filename(), 'selected'
        elif response == gtk.RESPONSE_CANCEL:
            print 'Closed, no files selected'
        dialog.destroy()

    def save_et(self, event, do_save_as=True):
        if do_save_as == False:
            self._et.save(self._fn)
        else:
            dialog = gtk.FileChooserDialog(
                "Save EventTable to file...", None,
                gtk.FILE_CHOOSER_ACTION_SAVE,
                (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE,
                 gtk.RESPONSE_OK))
            dialog.set_default_response(gtk.RESPONSE_OK)

            filter = gtk.FileFilter()
            filter.set_name("eegpy EventTable")
            filter.add_pattern("*.evt")
            dialog.add_filter(filter)

            filter = gtk.FileFilter()
            filter.set_name("All files")
            filter.add_pattern("*")
            dialog.add_filter(filter)

            response = dialog.run()
            if response == gtk.RESPONSE_OK:
                fn = dialog.get_filename()
                print fn, 'selected'
                dialog.destroy()
                self._fn = fn
                #Now save...
                self._et.save(self._fn)
                lbtext = ""
                if len(fn) > 40:
                    lbtext = "..." + fn[-37:]
                self.lb_fn.set_text(lbtext)
                #fh.close()
            else:  # response == gtk.RESPONSE_CANCEL:
                dialog.destroy()
                print 'Closed, no files selected'
            pass

    def set_filename(self, fn):
        print fn, "selected for opening"
        #success = False
        try:
            if not os.path.exists(fn):
                raise ValueError("File doesn't exist")
            self._et = EventTable(fn)
            if len(self._et.keys()) == 0:
                print self._et.keys()
                raise ValueError("EventTable empty!")
            self._fn = fn
        except ValueError, e:
            print "Error opening EventTable", e
            self._et = None
            self._fn = None
            return False
        lbtext = ""
        if len(fn) > 40:
            lbtext = "..." + fn[-37:]
        self.lb_fn.set_text(lbtext)
        self.setup_keylist()