Skip to content

Commit

Permalink
owdatasets: Add filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lanzagar committed Oct 24, 2017
1 parent 8cbe98a commit 3dcbc9b
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Orange/widgets/data/owdatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
from typing import Optional, Dict, Tuple

from AnyQt.QtWidgets import (
QLabel, QTextBrowser, QSplitter, QTreeView,
QLabel, QLineEdit, QTextBrowser, QSplitter, QTreeView,
QStyleOptionViewItem, QStyledItemDelegate, QApplication
)

from AnyQt.QtGui import QStandardItemModel, QStandardItem
from AnyQt.QtCore import (
Qt, QSize, QObject, QThread, QModelIndex, QSortFilterProxyModel,
Expand All @@ -26,12 +25,12 @@
from serverfiles import LocalFiles, ServerFiles, sizeformat

import Orange.data

from Orange.misc.environ import data_dir
from Orange.widgets import widget, settings, gui
from Orange.widgets.utils.signals import Output
from Orange.widgets.widget import Msg


INDEX_URL = "http://datasets.orange.biolab.si/"
log = logging.getLogger(__name__)

Expand Down Expand Up @@ -141,6 +140,12 @@ def __init__(self):
self.infolabel = QLabel(text="Initializing...\n\n")
box.layout().addWidget(self.infolabel)

gui.widgetLabel(self.mainArea, "Filter")
self.filterLineEdit = QLineEdit(
textChanged=self.filter
)
self.mainArea.layout().addWidget(self.filterLineEdit)

self.splitter = QSplitter(orientation=Qt.Vertical)

self.view = QTreeView(
Expand All @@ -150,6 +155,7 @@ def __init__(self):
rootIsDecorated=False,
editTriggers=QTreeView.NoEditTriggers,
)

box = gui.widgetBox(self.splitter, "Description", addToLayout=False)
self.descriptionlabel = QLabel(
wordWrap=True,
Expand Down Expand Up @@ -181,7 +187,9 @@ def __init__(self):
model.setHorizontalHeaderLabels(HEADER)
proxy = QSortFilterProxyModel()
proxy.setSourceModel(model)
self.view.setModel(model)
proxy.setFilterKeyColumn(-1)
proxy.setFilterCaseSensitivity(False)
self.view.setModel(proxy)

if self.splitter_state:
self.splitter.restoreState(self.splitter_state)
Expand Down Expand Up @@ -294,8 +302,8 @@ def info(prefix, filename):
current_index = i

hs = self.view.header().saveState()
model_ = self.view.model()
self.view.setModel(model)
model_ = self.view.model().sourceModel()
self.view.model().setSourceModel(model)
self.view.header().restoreState(hs)
model_.deleteLater()
model_.setParent(None)
Expand Down Expand Up @@ -344,6 +352,12 @@ def selected_dataset(self):
info = None
return info

def filter(self):
filter_string = self.filterLineEdit.text().strip()
proxyModel = self.view.model()
if proxyModel:
proxyModel.setFilterFixedString(filter_string)

def __on_selection(self):
# Main data sets view selection has changed
rows = self.view.selectionModel().selectedRows(0)
Expand Down

0 comments on commit 3dcbc9b

Please sign in to comment.