Changeset 8537:ea108d472160 in orange


Ignore:
Timestamp:
07/30/11 10:36:52 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
4ec462dd59911a99b5877e39fccf3569303846d0
Message:

Add a Zoom/Pan/Select toolbar to OWPlotGui and use it from Scatterplot

Location:
orange/OrangeWidgets
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWScatterPlotQt.py

    r8481 r8537  
    100100        self.zoomSelectToolbar = OWToolbars.ZoomSelectToolbar(self, self.GeneralTab, self.graph, self.autoSendSelection) 
    101101        self.connect(self.zoomSelectToolbar.buttonSendSelections, SIGNAL("clicked()"), self.sendSelections) 
     102         
     103        self.graph.gui.zoom_select_toolbar(self.GeneralTab) 
    102104 
    103105        # #################################### 
  • orange/OrangeWidgets/plot/owconstants.py

    r8509 r8537  
    2323HighlightZValue = 5 
    2424LegendZValue = 10 
     25 
     26NOTHING = 0 
     27ZOOMING = 1 
     28SELECT_RECTANGLE = 2 
     29SELECT_POLYGON = 3 
     30PANNING = 4 
     31SELECT = 5 
     32 
     33SELECTION_ADD = 0 
     34SELECTION_REMOVE = 1 
     35SELECTION_TOGGLE = 2 
     36SELECTION_ONE = 3 
  • orange/OrangeWidgets/plot/owplot.py

    r8535 r8537  
    99     
    1010''' 
    11  
    12 NOTHING = 0 
    13 ZOOMING = 1 
    14 SELECT_RECTANGLE = 2 
    15 SELECT_POLYGON = 3 
    16 PANNING = 4 
    17 SELECT = 5 
    1811 
    1912LeftLegend = 0 
  • orange/OrangeWidgets/plot/owplotgui.py

    r8482 r8537  
     1import os 
    12import OWGUI 
    23 
     4from owconstants import * 
     5 
     6from PyQt4.QtGui import QWidget, QToolButton, QGroupBox, QVBoxLayout, QHBoxLayout, QIcon 
     7from PyQt4.QtCore import Qt, qDebug, pyqtSignal 
     8 
     9class OrientedWidget(QWidget): 
     10    def __init__(self, orientation, parent): 
     11        QWidget.__init__(self, parent) 
     12        if orientation == Qt.Vertical: 
     13            self._layout = QVBoxLayout() 
     14        else: 
     15            self._layout = QHBoxLayout() 
     16        self.setLayout(self._layout) 
     17 
     18class StateButtonContainer(OrientedWidget): 
     19    def __init__(self, gui, ids, orientation, parent): 
     20        OrientedWidget.__init__(self, orientation, parent) 
     21        self.buttons = {} 
     22        for i in ids: 
     23            b = gui.tool_button(i, self) 
     24            b.clicked.connect(self.button_clicked) 
     25            self.buttons[i] = b 
     26            self.layout().addWidget(b) 
     27             
     28    def button_clicked(self, checked): 
     29        sender = self.sender() 
     30        qDebug(repr(sender)) 
     31        for button in self.buttons.itervalues(): 
     32            button.setDown(button is sender) 
     33             
     34    def button(self, id): 
     35        return self.buttons[id] 
     36                     
     37class AttributeChangeButton(QToolButton): 
     38    def __init__(self, plot, attr_name, attr_value, parent): 
     39        QToolButton.__init__(self, parent) 
     40        self.setMinimumSize(30, 30) 
     41        self.plot = plot 
     42        self.attr_name = attr_name 
     43        self.attr_value = attr_value 
     44        self.clicked.connect(self.button_clicked) 
     45         
     46    def button_clicked(self, clicked): 
     47        setattr(self.plot, self.attr_name, self.attr_value) 
     48     
     49    downChanged = pyqtSignal('bool') 
     50     
     51    def setDown(self, down): 
     52    self.downChanged.emit(down) 
     53    QToolButton.setDown(self, down) 
     54     
     55                     
    356class OWPlotGUI: 
     57    ''' 
     58        This class contains functions to create common user interface elements (QWidgets) 
     59        for configuration and interaction with the ``plot``.  
     60    ''' 
    461    def __init__(self, plot): 
    562        self._plot = plot 
     
    1269    AlphaValue = 6 
    1370    UseAnimations = 7 
    14          
     71     
     72    Zoom = 11 
     73    Pan = 12 
     74    Select = 13 
     75     
     76    SelectionAdd = 21 
     77    SelectionRemove = 22 
     78    SelectionToggle = 23 
     79    SelectionOne = 24 
     80     
     81    ''' 
     82        A map of  
     83        id : (name, attr_name, attr_value, icon_name) 
     84    ''' 
     85    _buttons = { 
     86        Zoom : ('Zoom', 'state', ZOOMING, 'Dlg_zoom'), 
     87        Pan : ('Pan', 'state', PANNING, 'Dlg_pan_hand'), 
     88        Select : ('Select', 'state', SELECT, 'Dlg_arrow'), 
     89        SelectionAdd : ('Add to selection', 'selection_behavior', SELECTION_ADD, ''), 
     90        SelectionRemove : ('Remove from selection', 'selection_behavior', SELECTION_REMOVE, ''), 
     91        SelectionToggle : ('Toggle selection', 'selection_behavior', SELECTION_TOGGLE, ''), 
     92        SelectionOne : ('Replace selection', 'selection_behavior', SELECTION_ONE, '') 
     93    } 
     94 
    1595    def _get_callback(self, name): 
    1696        return getattr(self._plot, name, self._plot.replot) 
     
    80160        self.add_widgets(ids, widget) 
    81161        return box 
     162         
     163    def tool_button(self, id, widget): 
     164        if id not in self._buttons: 
     165            return None 
     166        name, attr_name, attr_value, icon_name = self._buttons[id] 
     167        b = AttributeChangeButton(self._plot, attr_name, attr_value, widget) 
     168        b.setToolTip(name) 
     169        b.setIcon(QIcon(os.path.dirname(__file__) + "/../icons/" + icon_name + '.png')) 
     170        return b 
     171         
     172    def state_buttons(self, ids, orientation, widget): 
     173        ''' 
     174            This function creates a set of checkable buttons and connects them so that only one 
     175            may be checked at a time.  
     176        ''' 
     177        return StateButtonContainer(self, ids, orientation, widget) 
     178         
     179    def zoom_select_toolbar(self, widget, orientation = Qt.Horizontal): 
     180        o = 'vertial' if orientation == Qt.Vertical else 'horizontal' 
     181        t = OWGUI.widgetBox(widget, 'Zoom / Select', orientation=o) 
     182        zps = self.state_buttons([OWPlotGUI.Zoom, OWPlotGUI.Pan, OWPlotGUI.Select], orientation, t) 
     183        t.layout().addWidget(zps) 
     184        selection_modes = self.state_buttons([OWPlotGUI.SelectionOne, OWPlotGUI.SelectionAdd, OWPlotGUI.SelectionRemove], orientation, t) 
     185        t.layout().addWidget(selection_modes) 
     186        zps.button(OWPlotGUI.Select).downChanged.connect(selection_modes.setEnabled) 
     187        zps.button(OWPlotGUI.Select).downChanged.connect(selection_modes.button(OWPlotGUI.SelectionOne).click) 
     188        zps.button(OWPlotGUI.Zoom).click() 
     189        return t 
Note: See TracChangeset for help on using the changeset viewer.