def main():

    gtkutils.register_all_png_icons(const.internal_path(const.PATH_ICONS), 'sloppy-')

    filename = const.internal_path(const.PATH_EXAMPLE, 'example.spj')
    app = GtkApplication(filename)
    gtk.main()
    def _cb_export_dataset(self, widget):           
        """
        Export the selected Dataset to a file.
        Currently, only the csv format is supported.
        TODO: Support for arbitrary export filters.

        @attention: This needs to be written from scratch!
        """
        pj = self._check_project()
        objects = self.window.treeview.get_selected_objects()
        if len(objects) == 0:
            return
        object = objects[0]

        if not isinstance(object,Dataset):
            return

        # allow user to choose a filename
        chooser = gtk.FileChooserDialog(
            title="Export Dataset %s" % object.get_option('label'),
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
            buttons=(gtk.STOCK_CANCEL,
                     gtk.RESPONSE_CANCEL,
                     gtk.STOCK_SAVE,
                     gtk.RESPONSE_OK))
        chooser.set_default_response(gtk.RESPONSE_OK)
        chooser.set_current_folder(const.internal_path(const.PATH_EXAMPLE))
        chooser.set_select_multiple(False)

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

        filter = gtk.FileFilter()
        filter.set_name("Data Files")
        filter.add_pattern("*.dat")
        chooser.add_filter(filter)
        chooser.set_filter(filter) # default filter

        shortcut_folder = const.internal_path(const.PATH_EXAMPLE)
        if os.path.exists(shortcut_folder):
            chooser.add_shortcut_folder(shortcut_folder)

        response = chooser.run()
        if response == gtk.RESPONSE_OK:
            filename = chooser.get_filename()
        else:
            filename = None
        chooser.destroy()

        # export file, using the filter 'f'
        filename = os.path.abspath(filename)
        logger.debug("Exporting file %s as csv..." % filename )
        f = FilterRegistry.new_instance('comma separated values')
        f.export_to_file(filename, object)
def main():

    gtkutils.register_all_png_icons(const.internal_path(const.PATH_ICONS), 'sloppy-')

    try:
        filename = const.internal_path(const.PATH_EXAMPLE)
        filename = os.path.join(filename, 'example.spj')
        spj = load_project(filename)
    except IOError, msg:
	logger.error("IOError! Sample Project could not be loaded: %s" % msg )
        spj = None        
    def load_project(self, filename=None):
        """
        Open a FileChooserDialog and let the user pick a new project
        to be loaded. The old project is replaced.
        """

        if filename is None:
            # TODO
            # maybe we could have application.load_project
            # just request the file name and we simply
            # create a method for this dialog.
            
            # create chooser object 
            chooser = gtk.FileChooserDialog(
                title="Open project",
                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_EXAMPLE) )
            chooser.set_select_multiple(False)

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

            filter = gtk.FileFilter()
            filter.set_name("Sloppyplot Project files")
            filter.add_pattern("*.spj")
            filter.add_pattern("*.SPJ")
            chooser.add_filter(filter)
            chooser.set_filter(filter) # default filter

            shortcut_folder = const.internal_path(const.PATH_EXAMPLE)
            if os.path.exists(shortcut_folder):
                chooser.add_shortcut_folder( shortcut_folder )

            response = chooser.run()
            if response == gtk.RESPONSE_OK:
                filename = chooser.get_filename()
            else:
                filename = None
            chooser.destroy()


        if filename is not None:
            Application.load_project(self, filename)
    def save_project_as(self, filename = None):
        """ Save project under another filename. """
        pj = self._check_project()

        if not filename:
            # allow user to choose a filename
            chooser = gtk.FileChooserDialog(
                title="Save Project As",
                action=gtk.FILE_CHOOSER_ACTION_SAVE,
                buttons=(gtk.STOCK_CANCEL,
                         gtk.RESPONSE_CANCEL,
                         gtk.STOCK_SAVE,
                         gtk.RESPONSE_OK))
            chooser.set_default_response(gtk.RESPONSE_OK)
            chooser.set_current_folder( const.internal_path(const.PATH_EXAMPLE) )
            chooser.set_select_multiple(False)
            chooser.set_filename(pj.filename or "unnamed.spj")

            filter = gtk.FileFilter()
            filter.set_name("All files")
            filter.add_pattern("*")
            chooser.add_filter(filter)
            chooser.set_filter(filter) # default filter

            shortcut_folder = const.internal_path(const.PATH_EXAMPLE)
            if os.path.exists(shortcut_folder):
                chooser.add_shortcut_folder(shortcut_folder)

            response = chooser.run()
            try:
                if response == gtk.RESPONSE_OK:
                    filename = chooser.get_filename()                    
                else:
                    raise error.UserCancel
            finally:
                chooser.destroy()

            # add extension if not yet there
            if filename.lower().endswith('.spj') is False:
                filename = filename + ".spj"

        self._project.filename = filename
        self.window.set_title(basename(self._project.filename))
        save_project(self._project)
        self._project.journal.clear()

        self.recent_files.append(os.path.abspath(filename))
        Signals.emit(self, 'update-recent-files')
 def _cb_load_test_project(self,widget):
     try:
         filename = const.internal_path(const.PATH_EXAMPLE+'/example.spj')
         spj = self.load_project(filename)
     except IOError:
         # TODO: Message Box
         return None
     self.set_project(spj)
def test():
    const.set_path(Sloppy.__path__[0])
    filename = const.internal_path(const.PATH_EXAMPLE, 'example.spj')
    app = application.GtkApplication(filename)
    plot = app.project.get_plot(0)
    win = LayerWindow(app, plot)
    win.show()
    gtk.main()
def test2():
    const.set_path(Sloppy.__path__[0])
    filename = const.internal_path(const.PATH_EXAMPLE, 'example.spj')
    app = application.GtkApplication(filename)
    plot = app.project.get_plot(0)

    win = ToolWindow(app, app.project)
    win.connect("destroy", gtk.main_quit)

    win.show()
    gtk.main()
    def _cb_help_about(self, action):
        " Display a help dialog with version and copyright information. "
        dialog = gtk.AboutDialog()
        dialog.set_name(version.NAME)
        dialog.set_version(version.VERSION)
        dialog.set_comments(version.DESCRIPTION)
        dialog.set_copyright(version.COPYRIGHT)
        dialog.set_license("\n\n\n".join(version.LICENSES))
        dialog.set_website(version.HOMEPAGE)
        # dialog.set_website_label("Heh?")
        dialog.set_authors(version.AUTHORS)
        # dialog.set_documenters(["Documenters"])
        # dialog.set_artists(["Artists"])
        # dialog.set_translator_credits("Whoever translated")
        # dialog.set_log_icon_name("SloppyPlot")
        path = const.internal_path("Gtk", "Icons", "Plot.png")
        logo = gtk.gdk.pixbuf_new_from_file(path)
        dialog.set_logo(logo)

        dialog.run()
        dialog.destroy()
Beispiel #10
0
        raise SystemExit


#------------------------------------------------------------------------------
   
parser = OptionParser(version="%prog 1.0")

parser.add_option("-f","--file",dest="filename",
                  help="specify filename of project to use")
parser.add_option("-q","--quiet",action="store_true", dest="verbose",
                  help="don't print status messages to stdout")
parser.add_option("-d","--debug",action="store_true", dest="debug",
                  default=True,help="print debug messages to stdout")


args = ["-f", os.path.join(const.internal_path(const.PATH_EXAMPLE),"zno.spj"), "plot"]
(options,args) = parser.parse_args(args)

#------------------------------------------------------------------------------
# process options
logging.debug("Supplied options: %s" % options)

logger = logging.getLogger('')
if options.debug is True:
    print "(debug mode)"
    logger.setLevel(logging.DEBUG)
else:
    if options.verbose is False:
        print "(quiet mode)"
        logger.setLevel(logging.WARNING)
    else:
def main(filename):
    filename = filename or const.internal_path(const.PATH_EXAMPLE, 'example.spj')
    app = GtkApplication(filename)
    gtk.main()
    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()
 def init(self):
     register_all_png_icons(const.internal_path(const.PATH_ICONS), 'sloppy-')
     
     self.window = AppWindow(self)
     self._clipboard = gtk.Clipboard()  # not implemented yet
     self._current_plot = None
 def init(self):
     register_all_png_icons(const.internal_path(const.PATH_ICONS), 'sloppy-')
     
     self.window = AppWindow(self)
     self._clipboard = gtk.Clipboard()  # not implemented yet
     self.progresslist = GtkProgressList