Changeset 3781:a889974b56b9 in orange


Ignore:
Timestamp:
07/13/07 16:11:39 (7 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
52a67d2a3d4eb035a33e446058a442e5aa46ec2a
Message:
  • reworked the zoom/select toolbar to allow other icons, too
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/OWToolbars.py

    r2782 r3781  
    44dir = os.path.dirname(__file__) + "/icons/" 
    55dlg_zoom = dir + "Dlg_zoom.png" 
     6dlg_pan = dir + "Dlg_zoom.png" 
     7dlg_select = dir + "Dlg_zoom.png" 
    68dlg_rect = dir + "Dlg_rect.png" 
    79dlg_poly = dir + "Dlg_poly.png" 
     
    1618    btn = QToolButton(parent) 
    1719    btn.setToggleButton(toggle) 
     20    btn.cback = action   # otherwise garbage collection kills it 
    1821    if action: parent.connect(btn, SIGNAL("clicked()"), action) 
    1922    if icon:   btn.setPixmap(icon) 
     
    2124    return btn 
    2225     
     26class ZoomSelectToolbar(QHButtonGroup): 
     27#                (tooltip, attribute containing the button, callback function, button icon, button cursor, toggle) 
     28    builtinFunctions = (None, 
     29                 ("Zooming", "buttonZoom", "activateZooming", QPixmap(dlg_zoom), Qt.sizeAllCursor, 1),  
     30                 ("Panning", "buttonPan", "activatePanning", QPixmap(dlg_pan), Qt.pointingHandCursor, 1),  
     31                 ("Selection", "buttonSelect", "activateSelection", QPixmap(dlg_select), Qt.arrowCursor, 1),  
     32                 ("Rectangle selection", "buttonSelectRect", "activateRectangleSelection", QPixmap(dlg_rect), Qt.arrowCursor, 1),  
     33                 ("Polygon selection", "buttonSelectPoly", "activatePolygonSelection", QPixmap(dlg_poly), Qt.arrowCursor, 1),  
     34                 ("Remove last selection", "buttonRemoveLastSelection", "removeLastSelection", QPixmap(dlg_undo), None, 0),  
     35                 ("Remove all selections", "buttonRemoveAllSelections", "removeAllSelections", QPixmap(dlg_clear), None, 0),  
     36                 ("Send selections", "buttonSendSelections", "", QPixmap(dlg_send), None, 0) 
     37                ) 
     38                  
     39    IconSpace, IconZoom, IconPan, IconSelect, IconRectangle, IconPolygon, IconRemoveLast, IconRemoveAll, IconSendSelection = range(9) 
    2340 
    24 class ZoomSelectToolbar(QHButtonGroup): 
    25     def __init__(self, widget, parent, graph, autoSend = 0): 
     41    def __init__(self, widget, parent, graph, autoSend = 0, buttons = (1, 4, 5, 0, 6, 7, 8)): 
    2642        QHButtonGroup.__init__(self, "Zoom / Select", parent) 
    2743         
     
    2945        self.widget = None 
    3046         
    31         self.buttonZoom = createButton(self, "Zooming", self.actionZooming, QPixmap(dlg_zoom), toggle = 1) 
    32         self.buttonSelectRect = createButton(self, "Rectangle selection", self.actionRectangleSelection, QPixmap(dlg_rect), toggle = 1) 
    33         self.buttonSelectPoly = createButton(self, "Polygon selection", self.actionPolygonSelection, QPixmap(dlg_poly), toggle = 1) 
     47        self.functions = [type(f) == int and self.builtinFunctions[f] or f for f in buttons] 
     48        for b, f in enumerate(self.functions): 
     49            if not f: 
     50                self.addSpace(10) 
     51            else: 
     52                button = createButton(self, f[0], lambda x=b: self.action(x), f[3], toggle = f[5]) 
     53                setattr(self, f[1], button) 
     54                if f[0] == "Send selections": 
     55                    button.setEnabled(not autoSend) 
    3456 
    35         self.addSpace(10) 
    36  
    37         self.buttonRemoveLastSelection = createButton(self, 'Remove last selection', self.actionRemoveLastSelection, QPixmap(dlg_undo), toggle = 0) 
    38         self.buttonRemoveAllSelections = createButton(self, 'Remove all selections', self.actionRemoveAllSelections, QPixmap(dlg_clear), toggle = 0) 
    39         self.buttonSendSelections = createButton(self, 'Send selections', icon = QPixmap(dlg_send), toggle = 0) 
    40         self.buttonSendSelections.setEnabled(not autoSend) 
    41  
    42         self.actionZooming()    # activate zooming 
     57        self.action(0) 
    4358        self.widget = widget    # we set widget here so that it doesn't affect the value of self.widget.toolbarSelection 
    4459 
    45     def actionZooming(self): 
    46         if self.widget and "toolbarSelection" in self.widget.__dict__.keys(): self.widget.toolbarSelection = 0 
    47         self.buttonZoom.setOn(1) 
    48         self.buttonSelectRect.setOn(0) 
    49         self.buttonSelectPoly.setOn(0) 
    50         self.graph.activateZooming() 
    51  
    52     def actionRectangleSelection(self): 
    53         if self.widget and "toolbarSelection" in self.widget.__dict__.keys(): self.widget.toolbarSelection = 1 
    54         self.buttonZoom.setOn(0) 
    55         self.buttonSelectRect.setOn(1) 
    56         self.buttonSelectPoly.setOn(0) 
    57         self.graph.activateRectangleSelection() 
    58  
    59     def actionPolygonSelection(self): 
    60         if self.widget and "toolbarSelection" in self.widget.__dict__.keys(): self.widget.toolbarSelection = 2 
    61         self.buttonZoom.setOn(0) 
    62         self.buttonSelectRect.setOn(0) 
    63         self.buttonSelectPoly.setOn(1) 
    64         self.graph.activatePolygonSelection() 
    65  
    66     def actionRemoveLastSelection(self): 
    67         self.graph.removeLastSelection() 
    68  
    69     def actionRemoveAllSelections(self): 
    70         self.graph.removeAllSelections() 
    71  
     60    def action(self, b): 
     61        f = self.functions[b] 
     62        if f[5]: 
     63            if hasattr(self.widget, "toolbarSelection"): 
     64                self.widget.toolbarSelection = b 
     65            for fi, ff in enumerate(self.functions): 
     66                if ff and ff[5]: 
     67                    getattr(self, ff[1]).setOn(fi == b) 
     68        getattr(self.graph, f[2])() 
     69         
     70        # why doesn't this work? 
     71        cursor = f[4] 
     72        if not cursor is None: 
     73            self.graph.canvas().setCursor(cursor) 
     74            print self.graph.canvas().cursor().shape() 
     75            if self.widget: 
     76                self.widget.setCursor(cursor) 
     77             
     78         
     79    # for backward compatibility with a previous version of this class 
     80    def actionZooming(self): self.action(0) 
     81    def actionRectangleSelection(self): self.action(3) 
     82    def actionPolygonSelection(self): self.action(4) 
     83     
Note: See TracChangeset for help on using the changeset viewer.