Changeset 8563:d1a52f0c82a6 in orange


Ignore:
Timestamp:
08/01/11 23:04:47 (3 years ago)
Author:
matejd <matejd@…>
Branch:
default
Convert:
ce863e18452379b4ecaa7862f109aa447c16d174
Message:

Sending selections to other widgets

Location:
orange/OrangeWidgets
Files:
2 edited

Legend:

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

    r8558 r8563  
    161161        self.auto_send_selection_update = False 
    162162        self.plot.selection_changed_callback = self.selection_changed_callback 
     163        self.plot.selection_updated_callback = self.selection_updated_callback 
    163164        box = OWGUI.widgetBox(self.settings_tab, 'Auto Send Selected Data When...') 
    164165        OWGUI.checkBox(box, self, 'auto_send_selection', 'Adding/Removing selection areas', 
    165166            callback = self.on_checkbox_update, tooltip='Send selected data whenever a selection area is added or removed') 
    166         OWGUI.checkBox(box, self, 'auto_send_selection_update', 'Moving/Resizing selection areas', 
     167        OWGUI.checkBox(box, self, 'auto_send_selection_update', 'Moving selection areas', 
    167168            callback = self.on_checkbox_update, tooltip='Send selected data when a user moves or resizes an existing selection area') 
    168169 
     
    243244            indices = self.plot.get_selection_indices() 
    244245            if len(indices) < 1: 
    245                 self.plot.selections = [] 
     246                self.plot.remove_all_selections() 
    246247                return 
    247248            X, Y, Z = self.data_array[:, self.x_attr],\ 
     
    255256            min_z, max_z = numpy.min(Z), numpy.max(Z) 
    256257            self.plot.set_new_zoom(min_x, max_x, min_y, max_y, min_z, max_z) 
     258        else: 
     259            if self.auto_send_selection: 
     260                self._send_selections() 
     261 
     262    def selection_updated_callback(self): 
     263        if self.plot.selection_type != SelectionType.ZOOM and self.auto_send_selection_update: 
     264            self._send_selections() 
     265 
     266    def _send_selections(self): 
     267        # TODO: implement precise get_selection_indices 
     268        indices = self.plot.get_selection_indices() 
     269        if len(indices) < 1: 
     270            return 
     271 
     272        selected_indices = [1 if i in indices else 0 
     273                            for i in range(len(self.data))] 
     274        unselected_indices = [1-i for i in selected_indices] 
     275        selected = self.plot.rawData.selectref(selected_indices) 
     276        unselected = self.plot.rawData.selectref(unselected_indices) 
     277 
     278        if len(selected) == 0: 
     279            selected = None 
     280        if len(unselected) == 0: 
     281            unselected = None 
     282 
     283        self.send('Selected Examples', selected) 
     284        self.send('Unselected Examples', unselected) 
    257285 
    258286    def change_selection_type(self): 
     
    264292        self.closeContext("") 
    265293        self.data = data 
    266         self.plot.set_data(data) 
     294        self.plot.set_data(data, self.subsetData) 
    267295        self.x_attr_cb.clear() 
    268296        self.y_attr_cb.clear() 
     
    316344 
    317345    def set_subset_data(self, data=None): 
    318         self.subsetData = data # TODO: what should scatterplot do with this? 
     346        self.subsetData = data 
    319347 
    320348    def handleNewSignals(self): 
  • orange/OrangeWidgets/plot/owplot3d.py

    r8562 r8563  
    436436        self.selections = [] 
    437437        self.selection_changed_callback = None 
     438        self.selection_updated_callback = None 
    438439        self.selection_type = SelectionType.ZOOM 
    439440        self.new_selection = None 
     
    14321433                    self.selection_changed_callback() if self.selection_changed_callback else None 
    14331434        elif self.state == PlotState.PANNING: 
    1434             self.selection_changed_callback() if self.selection_changed_callback else None 
     1435            self.selection_updated_callback() if self.selection_updated_callback else None 
    14351436 
    14361437        if not (self.state == PlotState.SELECTING and self.selection_type == SelectionType.POLYGON): 
     
    14531454            self.selections.pop() 
    14541455            self.updateGL() 
     1456            self.selection_changed_callback() if self.selection_changed_callback else None 
    14551457 
    14561458    def remove_all_selections(self): 
    14571459        self.selections = [] 
     1460        self.selection_changed_callback() if self.selection_changed_callback else None 
    14581461        self.updateGL() 
    14591462 
Note: See TracChangeset for help on using the changeset viewer.