예제 #1
0
 def find_backends(self, key=None, plot=None):
     matches = self.backends
     if key is not None:
         klass = BackendRegistry.get_class(key)
         matches = [item for item in matches if isinstance(item, klass)]
     if plot is not None:
         matches = [item for item in matches if repr(item.plot) == repr(plot)]
     return matches
예제 #2
0
    def request_backend(self, key, plot=None):
        print "Requesting Backend ", key, "for plot", plot

        matches = self.find_backends(key=key, plot=plot)
        print "===> matches = ", matches
        if len(matches) > 0:
            return matches[0]
        else:
            backend = BackendRegistry.new_instance(key, project=self, plot=plot)
            self.backends.append(backend)
            return backend
예제 #3
0
    def list_backends(self, verbose=True):       
        backends = BackendRegistry.find_instances(project=self)
            
        rv = ["Listing %d Backends:" % len(backends)]
        for backend in backends:
            rv.append("  %s" % str(backend))

        result = "\n".join(rv)
        if verbose is True:
            print result
        else:
            return result
예제 #4
0
    def __init__(self, app):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

        self.app = app
        self._windows = list()  # keeps track of all subwindows
        self._windowlist_merge_id = None

        #        self.set_size_request(640,480)

        self.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST)
        self.move(0, 0)
        icon = self.render_icon("sloppy-Plot", gtk.ICON_SIZE_BUTTON)
        self.set_icon(icon)

        self.connect("delete-event", (lambda sender, event: app.quit()))
        # self.connect("destroy", (lambda sender: app.quit()))

        self.uimanager = self._construct_uimanager()
        self._construct_logwindow()

        # and build ui
        self.uimanager.add_ui_from_string(self.ui_string)
        self.add_accel_group(self.uimanager.get_accel_group())

        self._construct_menubar()
        self._construct_toolbar()
        self._construct_treeview()
        self._construct_statusbar()

        self.plotbook = gtk.Notebook()
        self.plotbook.show()

        hpaned = gtk.HPaned()
        hpaned.pack1(self.treeview_window, True, True)
        #        hpaned.pack2(self.plotbook, True, True)
        hpaned.show()

        ##vpaned = gtk.VPaned()
        ##vpaned.pack1(self.treeview_window,True,True)
        ###vpaned.pack2(self.logwidget,False,True)
        ##vpaned.show()

        # Set up vbox to hold everything...
        vbox = gtk.VBox()
        vbox.pack_start(self.menubar, expand=False)
        vbox.pack_start(self.toolbar, expand=False)
        ###vbox.pack_start(self.treeview_window, expand=True, fill=True)
        vbox.pack_start(hpaned, True, True)
        vbox.pack_end(self.statusbar, expand=False)
        vbox.show()

        # ...and add vbox to the window.
        self.add(vbox)

        self.show()

        # check for backends
        has_mpl = BackendRegistry.has_key("matplotlib")
        #        if has_mpl is True:

        self._refresh_windowlist()
예제 #5
0
        for layer in self.plot.layers:
            group_info = {}
            self.draw_layer(layer, group_info)
       
        self.canvas.draw()


#------------------------------------------------------------------------------


class BackendWithWindow(Backend):

    def connect(self):
        win = gtk.Window()        
        Backend.connect(self)
        win.add(self.canvas)
        win.connect("destroy", Backend.disconnect(self))
        win.show()

        
    def disconnect(self):
        win.destroy()
        

#------------------------------------------------------------------------------
BackendRegistry.register('matplotlib', Backend)
BackendRegistry.register('matplotlib/w', Backend)


            
예제 #6
0
        logger.info("Gnuplot command list:\n\n%s" % "\n".join(cmd_list))
        for cmd in cmd_list:
            self(cmd)

        Signals.emit(self,'gnuplot-after-plot', window_title=self.window_title)
        
    draw = redraw        
        


# ======================================================================

class BackendDumb(Backend):

    def __init__(self, *args, **kwargs):
        kwargs.update({'terminal' : DumbTerminal(), 'encoding' : 'iso_8859_15'})
        Backend.__init__(self, *args, **kwargs)

class BackendX11(Backend):
    def __init__(self, *args, **kwargs):
        kwargs.update({'terminal' : XTerminal(), 'encoding' : 'iso_8859_15'})
        Backend.__init__(self, *args, **kwargs)

        
BackendRegistry.register('gnuplot', Backend)
BackendRegistry.register('gnuplot/dumb', BackendDumb)
BackendRegistry.register('gnuplot/x11', BackendX11)



    def plot_postscript(app, project, plot):

        #
        # request filename
        #
        filename = PostscriptTerminal.build_filename('ps', project, plot)
        
        chooser = gtk.FileChooserDialog(
            title="PostScript Export",
            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_select_multiple(False)
        chooser.set_current_folder(os.path.dirname(filename))
        chooser.set_current_name(os.path.basename(filename))

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

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

        #
        # request export options
        #
        ##props = ['mode', 'enhanced', 'color', 'blacktext', 'solid',
        ##         'dashlength', 'linewidth', 'duplexing', 'rounded', 'fontname',
        ##         'fontsize', 'timestamp']          
        
        dialog = OptionsDialog(PostscriptTerminal(), app.window)
        dialog.set_size_request(320,520)

        # determine requested postscript mode (ps or eps) from extension
        path, ext = os.path.splitext(filename)
        ext = ext.lower()
        if ext == '.eps':
            dialog.container.mode = 'eps'
        elif ext == '.ps':
            dialog.container.mode = 'landscape'
            
        try:
            result = dialog.run()
            terminal = dialog.container
        finally:
            dialog.destroy()

        if result != gtk.RESPONSE_ACCEPT:
            return
        

        #
        # now check if mode and filename extension match
        #

        def fix_filename(filename, mode):
            msg = "The postscript mode you selected (%s) does not match the given filename extension (%s).  Do you want to adjust the filename to match the mode? " % (mode, os.path.splitext(filename)[1])
            dialog = gtk.MessageDialog(type = gtk.MESSAGE_QUESTION, message_format = msg)
            dialog.add_button("Keep Filename", gtk.RESPONSE_NO)
            btn_default = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
            dialog.add_button("Adjust Filename", gtk.RESPONSE_YES)

            btn_default.grab_focus()

            response = dialog.run()
            dialog.destroy()

            if response == gtk.RESPONSE_YES:
                # yes = yes, adjust filename
                if mode == '.eps':  new_ext = '.eps'
                else: new_ext = '.ps'
                path, ext = os.path.splitext(filename)
                return path + new_ext
            elif response == gtk.RESPONSE_NO:
                # no = no, keep filename
                return filename
            else:
                # everything else -> abort action
                raise error.UserCancel

        if (terminal.mode == 'eps' and ext != '.eps') or \
               (terminal.mode != 'eps' and ext != '.ps'):
            filename = fix_filename(filename, terminal.mode)
        
        #
        # construct backend for output
        #
        backend = BackendRegistry.new_instance(
            'gnuplot', project=project, plot=plot,
            filename=filename,
            terminal=terminal)
        try:
            backend.draw()
        finally:
            backend.disconnect()