Changeset 11314:2cd807719971 in orange


Ignore:
Timestamp:
02/15/13 12:55:24 (14 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added 'canSaveToMatplotlib' method.

Check if the QGraphicsScene contents can actually be saved by the
savaToMatplotlib method.

(references #1268)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeWidgets/OWDlgs.py

    r10463 r11314  
    2222class OWChooseImageSizeDlg(OWBaseWidget): 
    2323    settingsList = ["selectedSize", "customX", "customY", "lastSaveDirName", "penWidthFactor"] 
    24     def __init__(self, graph, extraButtons = [], defaultName="graph", parent=None): 
     24    def __init__(self, graph, extraButtons = [], defaultName="graph", parent=None, saveMatplotlib=None): 
    2525        OWBaseWidget.__init__(self, parent, None, "Image settings", modal = TRUE, resizingEnabled = 0) 
    2626 
     
    5555        #self.printButton =          OWGUI.button(self.space, self, "Print", callback = self.printPic) 
    5656        self.saveImageButton =      OWGUI.button(box, self, "Save Image", callback = self.saveImage) 
    57         if not (_have_gl and isinstance(graph, QGLWidget)): 
     57 
     58        # If None we try to determine if save can succeed automatically 
     59        if saveMatplotlib is None: 
     60            saveMatplotlib = self.canSaveToMatplotlib(graph) 
     61 
     62        if saveMatplotlib and not (_have_gl and isinstance(graph, QGLWidget)): 
    5863            self.saveMatplotlibButton = OWGUI.button(box, self, "Save Graph as matplotlib Script", callback = self.saveToMatplotlib) 
    5964        for (text, funct) in extraButtons: 
     
    214219        QDialog.accept(self) 
    215220 
     221    def canSaveToMatplotlib(self, graph): 
     222        if _have_qwt and isinstance(graph, QwtPlot): 
     223            # TODO: check all curve items. 
     224            return True 
     225 
     226        elif isinstance(graph, QGraphicsScene): 
     227            items = graph.items() 
     228            supported = set([QGraphicsRectItem, QGraphicsLineItem, 
     229                             QGraphicsTextItem, OWQCanvasFuncts.OWCanvasText]) 
     230            return all(type(item) in supported for item in items) 
     231        else: 
     232            return False 
     233 
    216234    # ############################################################ 
    217235    # EXTRA FUNCTIONS ############################################ 
Note: See TracChangeset for help on using the changeset viewer.