def construct_preview(self, filename):
        if filename is None:
            return gtk.Label()           
        
        view = gtk.TextView()
        buffer = view.get_buffer()
        view.set_editable(False)
        view.show()
        
        tag_main = buffer.create_tag(family="Courier")
        tag_linenr = buffer.create_tag(family="Courier", weight=pango.WEIGHT_HEAVY)

        # fill preview buffer with at most 100 lines
        try:
            fd = open(filename, 'r')
        except IOError:
            raise RuntimeError("Could not open file %s for preview!" % filename)

        iter = buffer.get_start_iter()        
        try:
            for j in range(1,100):
                line = fd.readline()
                if len(line) == 0:
                    break
                buffer.insert_with_tags(iter, u"%3d\t" % j, tag_linenr)
                try:
                    buffer.insert_with_tags(iter, unicode(line), tag_main)
                except UnicodeDecodeError:
                    buffer.insert_with_tags(iter, u"<unreadable line>\n", tag_main)
        finally:
            fd.close()

        return uihelper.new_section("Preview", uihelper.add_scrollbars(view))
    def __init__(self, dataset, parent=None):
        gtk.Dialog.__init__(self, "Metadata", parent,
                            gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                             gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.set_size_request(480,320)
        
        pb = PropertyBrowser(dataset)
        pb.expand_all()
        self.vbox.add(add_scrollbars(pb))

        self.show_all()
Пример #3
0
    def set_plot(self, plot):
        # TODO: remove old plot
        # TODO: connect to plot's title    

        if plot is not None:
            backend = self.project.request_backend('matplotlib', plot=plot)

            #backend.canvas.set_size_request(800, 600)
            sw = uihelper.add_scrollbars(backend.canvas, viewport=True)
            sw.show()
            self.vbox.pack_start(sw)
        else:
            backend = None
           
        # disconnect old stuff
        if self.backend is not None and self.backend != backend:
            self.backend.disconnect()

        for signal in self._signals:
            Signals.disconnect(signal)
        self._signals = []
        
        if self.cursor is not None:
            self.cursor.finish()

        # connect new backend
        self.plot = plot
        self.backend = backend


        if backend is not None:
            self._signals.extend(
                [Signals.connect(plot, "plot-changed", (lambda sender: backend.draw())),
                 Signals.connect(plot, "closed", (lambda sender: Signals.emit(self, 'closed')))]
                )
            try:
                backend.draw()
            except:
                #gtkutils.info_msg("Nothing to plot.")
                raise            

            # Cursor
            self.cursor = mpl_selector.Cursor(self.backend.figure)
            Signals.connect(self.cursor, "move",
                            (lambda sender,x,y: self.set_coords(x,y)))
            self.cursor.init()
Пример #4
0
    def set_plot(self, plot):
        # TODO: remove old plot
        # TODO: connect to plot's title    

        if plot is not None:
            backend = self.project.request_backend('matplotlib', plot=plot)

            #backend.canvas.set_size_request(800, 600)
            sw = uihelper.add_scrollbars(backend.canvas, viewport=True)
            sw.show()
            self.vbox.pack_start(sw)
        else:
            backend = None
           
        # disconnect old stuff
        if self.backend is not None and self.backend != backend:
            self.backend.disconnect()

        for cb in self.cblist:
            cb.disconnect()
        self.cblist = []
        
        if self.cursor is not None:
            self.cursor.finish()

        # connect new backend
        self.plot = plot
        self.backend = backend


        if backend is not None:
            self.cblist += [
                plot.sig_connect("changed", (lambda sender: backend.draw())),
                plot.sig_connect("closed", (lambda sender: self.destroy())),
                backend.sig_connect("closed", (lambda sender: self.destroy()))
                ]
            
            try:
                backend.draw()
            except:
                raise            

            # Cursor
            self.cursor = mpl_selector.Cursor(self.backend.figure)
            self.cursor.sig_connect("move", (lambda sender,x,y: self.set_coords(x,y)))
            self.cursor.init()
Пример #5
0
    def __init__(self, app, project, dataset=None):
        gtk.Window.__init__(self)
	self.set_size_request(280,320)
        self.set_transient_for(app.window)
        self.app = app
        
        self._signals = []

        self.uimanager = self._construct_uimanager()
        self.menubar = self._construct_menubar()
        self.toolbar = self._construct_toolbar()
        self.popup = self.uimanager.get_widget('/popup_column')
        self.popup_info = None # needed for popup
        self.statusbar = self._construct_statusbar()

        self.tableview = self._construct_tableview()
        sw = uihelper.add_scrollbars(self.tableview)
        sw.show()
        
        
        hpaned = gtk.HPaned()
        hpaned.pack1( sw )
#        hpaned.pack2( self._construct_metadata_widget() )
        hpaned.show()
        self.hpaned = hpaned
        
        vbox = gtk.VBox()

        vbox.pack_start( self.menubar, expand=False, fill=True )
        vbox.pack_start( self.toolbar, expand=False, fill=True )
        vbox.pack_start( self.hpaned, expand=True, fill=True )
        vbox.pack_start( self.statusbar, expand=False, fill=True )

        vbox.show()
        self.add(vbox)

        self.project = project  # immutable
        self._dataset = None
        self.dataset = dataset

        Signals.connect(self.project, "close", (lambda sender: self.destroy()))
        Signals.connect(self.dataset, "closed", (lambda sender: self.destroy()))

        self.tableview.emit('cursor_changed')                
    def __init__(self, filenames):

        gtk.Dialog.__init__(self, "Import Wizard", None,
                            gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                            gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        self.set_size_request(480,320)
        
        self.treeview = self.construct_treeview()        
        self.populate_preview(filenames[0])

        sw = uihelper.add_scrollbars(self.treeview)
        self.treeview.show()

        self.vbox.pack_end(sw, True, True)
        sw.show()

        self.importer = ImporterRegistry.new_instance('ASCII')

        frame = gtk.Frame()


        def redisplay(sender, event, treeview):
            treeview.queue_draw()
            
        pw_skip, box_skip = propwidgets.construct_pw_in_box(self.importer, 'skip')
        pw_skip.widget.connect('focus-out-event', redisplay, self.treeview)
        self.pw_skip = pw_skip        
        box_skip.show()

        
        pw_designations, box_designations = propwidgets.construct_pw_in_box(self.importer, 'designations')
        #pw_designations.connect('
        box_designations.show()

        hbox = gtk.HBox()
        hbox.pack_start(box_skip)
        hbox.pack_start(box_designations)
        hbox.show()
        
        frame.add(hbox)

        self.vbox.pack_start(frame, False, True)
        frame.show()
Пример #7
0
    def __init__(self, app, dataset, colnr):
        self.app = app
        self.dataset = dataset
        self.colnr = colnr
        
        gtk.Window.__init__(self)
        self.set_title("Cool Column Calculator")
        self.set_size_request(width=-1, height=200)

        vbox = gtk.VBox()

        self.label = gtk.Label("col(%d) = " % self.colnr)
        self.label.show()
        
        self.textview = gtk.TextView()
        self.textview.show()
        self.scrolled_window = uihelper.add_scrollbars(self.textview)
        self.scrolled_window.show()

        btn1 = gtk.Button(stock=gtk.STOCK_APPLY)
        btn1.connect('clicked', (lambda sender: self.evaluate()))
        btn1.show()

        btn2 = gtk.Button(stock=gtk.STOCK_CLOSE)
        btn2.connect('clicked', (lambda sender: self.destroy()))
        btn2.show()
        
        self.btnbox = gtk.HButtonBox()
        self.btnbox.pack_end(btn2)
        self.btnbox.pack_end(btn1)
        self.btnbox.show()

        vbox.pack_start(self.label, False)
        vbox.pack_start(self.scrolled_window, True, True)
        vbox.pack_end(self.btnbox, False)
        self.add(vbox)
        vbox.show()
    def _cb_import_dataset(self, action):
        pj = self._check_project()
        
        # allow user to choose files for import
        chooser = gtk.FileChooserDialog(
            title="Import Dataset from file",
            action=gtk.FILE_CHOOSER_ACTION_OPEN,
            buttons=(gtk.STOCK_CANCEL,
                     gtk.RESPONSE_CANCEL,
                     gtk.STOCK_OPEN,
                     gtk.RESPONSE_OK))
        chooser.set_default_response(gtk.RESPONSE_OK)
        chooser.set_current_folder(const.internal_path(const.PATH_DATA))
        chooser.set_select_multiple(True)

        filter_keys = {} # used for reference later on
        
        # add 'All Files' filter
        blurb_all_files = "All Files"
        filter = gtk.FileFilter()
        filter.set_name(blurb_all_files)
        filter.add_pattern("*")
        chooser.add_filter(filter)
        chooser.set_filter(filter)
        filter_keys[blurb_all_files] = 'auto' # default if nothing else specified
        
        # create file filters
        for (key, importer) in ImporterRegistry.iteritems():
            extensions = ';'.join(map(lambda ext: '*.'+ext, importer.extensions))
            blurb = "%s (%s)" % (importer.blurb, extensions)

            filter = gtk.FileFilter()
            filter.set_name(blurb)
            for ext in importer.extensions:
                filter.add_pattern("*."+ext.lower())
                filter.add_pattern("*."+ext.upper())
            chooser.add_filter(filter)

            filter_keys[blurb] = key

        # add shortcut folder to example path, if such exists
        shortcut_folder = const.internal_path(const.PATH_EXAMPLE)
        if os.path.exists(shortcut_folder):
            chooser.add_shortcut_folder(shortcut_folder)

        #
        # prepare extra widget
        #
        
        # The custom widget `combobox` lets the user choose,
        # which Importer is to be used.
        
        # model: key, blurb
        model = gtk.ListStore(str, str)
        # add 'Same as Filter' as first choice, then add all importers
        model.append( (None, "Auto") )
        for key, importer in ImporterRegistry.iteritems():
            model.append( (key, importer.blurb) )

        combobox = gtk.ComboBox(model)
        cell = gtk.CellRendererText()
        combobox.pack_start(cell, True)
        combobox.add_attribute(cell, 'text', 1)
        combobox.set_active(0)
        combobox.show()

        label = gtk.Label("Importer")
        label.show()
            
        hbox = gtk.HBox()       
        hbox.pack_end(combobox,False)
        hbox.pack_end(label,False)
        hbox.show()        

        # The progress bar display which file is currently being imported.
        pbar = gtk.ProgressBar()
        
        vbox = gtk.VBox()
        vbox.pack_start(hbox,False)
        vbox.pack_start(pbar,False)
        vbox.show()
        
        chooser.set_extra_widget(vbox)


        #
        # run dialog
        #
        
        try:
            response = chooser.run()
            if response == gtk.RESPONSE_OK:
                filenames = chooser.get_filenames()
                if len(filenames) == 0:
                    return
                
                importer_key = model[combobox.get_active()][0]
                if importer_key is None: # auto
                    f = chooser.get_filter()
                    importer_key = filter_keys[f.get_name()]
                    if importer_key is 'auto':
                        matches = importer_from_filename(filenames[0])
                        if len(matches) > 0:
                            importer_key = matches[0]
                        else:
                            importer_key = 'ASCII'
            else:
                return

            # TODO
            #chooser.set_active(False)
            pbar.show()
            
            # request import options
            importer = ImporterRegistry[importer_key]()

            try:
                dialog = OptionsDialog(importer, parent=self.window)
            except NoOptionsError:
                pass
            else:
                # If there are any options, construct a
                # preview widget to help the user.
                view = gtk.TextView()
                buffer = view.get_buffer()
                view.set_editable(False)
                view.show()

                tag_main = buffer.create_tag(family="Courier")
                tag_linenr = buffer.create_tag(family="Courier", weight=pango.WEIGHT_HEAVY)

                # fill preview buffer with at most 100 lines
                preview_file = filenames[0]
                try:
                    fd = open(preview_file, 'r')
                except IOError:
                    raise RuntimeError("Could not open file %s for preview!" % preview_file)

                iter = buffer.get_start_iter()        
                try:
                    for j in range(100):
                        line = fd.readline()
                        if len(line) == 0:
                            break
                        buffer.insert_with_tags(iter, u"%3d\t" % j, tag_linenr)
                        try:
                            buffer.insert_with_tags(iter, unicode(line), tag_main)
                        except UnicodeDecodeError:
                            buffer.insert_with_tags(iter, u"<unreadable line>\n", tag_main)
                finally:
                    fd.close()

                preview_widget = uihelper.add_scrollbars(view)
                preview_widget.show()

                dialog.vbox.add(preview_widget)
                dialog.set_size_request(480,320)

                try:
                    result = dialog.run()
                    if result == gtk.RESPONSE_ACCEPT:
                        dialog.check_out
                    else:
                        return
                finally:
                    dialog.destroy()


            def set_text(queue):
                while True:
                    try:
                        text, fraction = queue.get()
                        if text == -1:
                            pbar.hide()
                        elif text is not None:
                            pbar.set_text(text)                                        
                        if fraction is not None:
                            pbar.set_fraction(fraction)
                    except QueueEmpty:
                        pass
                    yield None

            queue = Queue()
            thread_progress = GIdleThread(set_text(queue))
            thread_progress.start()

            thread_import = GIdleThread(self.import_datasets(pj, filenames, importer), queue)
            thread_import.start()
            thread_import.wait()

        finally:
            chooser.destroy()
Пример #9
0
    def __init__(self, objects):
        gtk.Window.__init__(self)
        self.set_modal(True)
        self.set_size_request(480,320)
        
        ProgressList.__init__(self, objects)

        vbox = gtk.VBox()

        # set up progressbar
        bar = gtk.ProgressBar()
        bar.set_fraction(0.0)
        bar.show()
        
        # set up listview with a model := (filename, status)
        model = gtk.ListStore(str, str)
        listview = gtk.TreeView(model)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn("filename", cell)
        column.set_cell_data_func(cell, self.render_filename)
        listview.append_column(column)
        column = gtk.TreeViewColumn('Status', cell, text=1)
        listview.append_column(column)
        listview.show()

        sw = uihelper.add_scrollbars(listview)
        sw.show()

        # the scrolled window (sw) with the listview is put into an expander widget
        expander = gtk.Expander("Details")
        expander.set_expanded(False)
        expander.add(sw)
        #expander.connect("notify::expanded", lambda e,p: self.check_resize())
        expander.show()

        # set up button box
        btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        btn_cancel.show()

        btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        btn_ok.show()
        
        btnbox = gtk.HButtonBox()
        btnbox.add(btn_cancel)
        btnbox.add(btn_ok)        
        btnbox.set_layout(gtk.BUTTONBOX_END)
        btnbox.show()

        # initially, btn_ok is disables.
        btn_cancel.connect("clicked", (lambda sender: self.abort()))

        btn_ok.connect("clicked", (lambda sender: self.destroy()))
        btn_ok.set_sensitive(False)        

        # stack everything into a vbox.
        #vbox.pack_start(listview, False, True, padding=5)
        vbox.pack_start(bar, False, True, padding=5)
        vbox.pack_start(expander, True, True, padding=5)
        vbox.pack_start(sw, True, True, padding=5)
        vbox.pack_end(btnbox,False,True, padding=5)
        vbox.show()
                
        self.add(vbox)
        self.show()

        # fill model with string names
        for object in self.objects:
            model.append( (object,"") )
        self.iter = None

        while gtk.events_pending():
            gtk.main_iteration()

        # save some variables for further reference
        self.model = model
        self.bar = bar
        self.btn_cancel = btn_cancel
        self.btn_ok = btn_ok
        self.expander = expander
Пример #10
0
    def __init__(self):
        ConfigurationPage.__init__(self)
    
        # We create copies of all templates and put these into the
        # treeview.  This allows the user to reject the modifications
        # (RESPONSE_REJECT).  If however he wishes to use the
        # modifications (RESPONSE_ACCEPT), then we simply need to
        # replace the current templates with these temporary ones.

        # check in
        self.model = gtk.ListStore(str, object) # key, object
        model = self.model # TBR

        #
        # create gui
        #
        # columns should be created in the order given by COLUMN_xxx
        # definitions above.
        tv = gtk.TreeView(model)
        tv.set_headers_visible(True)
        
        cell = gtk.CellRendererText()        
        column = gtk.TreeViewColumn("Key", cell)
        column.set_attributes(cell, text=self.MODEL_KEY)
        column.set_resizable(True)        
        tv.append_column(column)

        def render_blurb(column, cell, model, iter):
            object = model.get_value(iter, self.MODEL_OBJECT)
            blurb = object.blurb or ""
            if object.is_internal:
                blurb += " (immutable)"            
            cell.set_property('text', blurb)
        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Description", cell)        
        column.set_cell_data_func(cell, render_blurb)
        column.set_resizable(True)
        tv.append_column(column)

        self.treeview = tv

        sw = uihelper.add_scrollbars(tv)

        tv.connect("row-activated", (lambda a,b,c: self.on_edit_item(a,c)))
                    
        buttons=[(gtk.STOCK_EDIT, self.on_edit_item),
                 ('sloppy-rename', self.on_rename_item),
                 (gtk.STOCK_ADD, self.on_add_item),
                 (gtk.STOCK_COPY, self.on_copy_item),
                 (gtk.STOCK_DELETE, self.on_delete_item)]

        btnbox = uihelper.construct_buttonbox(buttons,
                                              horizontal=False,
                                              layout=gtk.BUTTONBOX_START)
        btnbox.set_spacing(uihelper.SECTION_SPACING)
        btnbox.set_border_width(uihelper.SECTION_SPACING)

        sw.set_border_width(uihelper.SECTION_SPACING)


        hbox = gtk.HBox()
        hbox.pack_start(sw,True,True)
        hbox.pack_start(btnbox,False,True)
        
        self.pack_start(hbox,True,True)
        self.show_all()
Пример #11
0
    def __init__(self, root='', maxrecords=100, ignore_delete_event=True):
        
        gtk.Window.__init__(self)
        self.set_size_request(width=600, height=400)

        # maximum number of records
        # Can be changed during runtime.
        self.maxrecords = maxrecords

        #
        # construct GUI
        #
        actions = [('SaveAs', gtk.STOCK_SAVE_AS, 'Save Log Messages as...',
                    None, 'Save Log Messages in a file.', 'cb_save_as'),]
                 
        ui = \
        """
        <ui>
          <toolbar name='Toolbar'>
            <toolitem action='SaveAs'/>
          </toolbar>
        </ui>
        """
        self.uimanager = self._construct_uimanager(actions, ui)

        self.toolbar = self._construct_toolbar()
        self.toolbar.show()
        
        self.tv, self.model = self._construct_treeview()
        self.tv.show()

        self.sw = uihelper.add_scrollbars(self.tv)
        self.sw.show()

        vbox = gtk.VBox()
        vbox.pack_start(self.toolbar, expand=False, fill=True)
        vbox.pack_start(self.sw, expand=True, fill=True)
        vbox.show()

        self.add(vbox)


        #
        # add logging handler
        #
        handler = CustomHandler(self)
        l = logging.getLogger(root)
        l.addHandler(handler)
#         def _cb_destroy_event(widget, event, log, hdlr):
#             print "HANDLER"
#             log.removeHandler(hdlr)
#             print "Handler removed"
#         self.connect('destroy_event', _cb_destroy_event, l, handler)
            
            


        # If ignore_delete_event is set, we will add a handler
        # to skip delete-events, i.e. if the user clicks on the
        # close button of his window, the window will only be hidden.
        if ignore_delete_event is True:
            def _cb_delete_event(widget, *args):
                self.hide()
                return True # don't continue deletion
            self.connect('delete_event', _cb_delete_event)