Skip to content

Commit

Permalink
Merge pull request #751 from ajdapretnar/focus-tm
Browse files Browse the repository at this point in the history
Topic Modeling: Base selection style on itemdelegates
  • Loading branch information
ajdapretnar authored Nov 19, 2021
2 parents 55345c7 + f62b8d9 commit da42f78
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
5 changes: 3 additions & 2 deletions orangecontrib/text/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

try:
from orangewidget.utils.signals import summarize, PartialSummary
# import to check if Table summary is available
from Orange.widgets.utils import state_summary
# import to check if Table summary is available - if summarize_by_name does
# not exist Orange (3.28) does not support automated summaries
from Orange.widgets.utils.state_summary import summarize_by_name
except ImportError:
summarize, PartialSummary = None, None

Expand Down
5 changes: 4 additions & 1 deletion orangecontrib/text/tests/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

try:
from orangewidget.utils.signals import summarize
# import to check if Table summary is available - if summarize_by_name does
# not exist Orange (3.28) does not support automated summaries
from Orange.widgets.utils.state_summary import summarize_by_name
except ImportError:
summarize = None

Expand Down Expand Up @@ -656,7 +659,7 @@ def test_pickle_corpus(self):
pickle.dumps(c)


@skipIf(summarize is None, "summarize is not available for orange-widget-base<4.13")
@skipIf(summarize is None, "summarize is not available for orange3<=3.28")
class TestCorpusSummaries(unittest.TestCase):
def test_corpus_not_preprocessed(self):
"""Check if details part of the summary is formatted correctly"""
Expand Down
12 changes: 5 additions & 7 deletions orangecontrib/text/widgets/owtopicmodeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
QGroupBox, QTreeWidgetItem, QTreeWidget,
QStyleOptionViewItem, QStyledItemDelegate, QStyle)
from Orange.widgets.utils.concurrent import TaskState, ConcurrentWidgetMixin
from orangewidget.utils.itemdelegates import text_color_for_state

from gensim.models import CoherenceModel

Expand Down Expand Up @@ -369,7 +370,7 @@ class HTMLDelegate(QStyledItemDelegate):
Adopted from https://stackoverflow.com/a/5443112/892987 """
def paint(self, painter, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options,index)
self.initStyleOption(options, index)

style = QApplication.style() if options.widget is None else options.widget.style()

Expand All @@ -380,11 +381,8 @@ def paint(self, painter, option, index):
style.drawControl(QStyle.CE_ItemViewItem, options, painter)

ctx = QtGui.QAbstractTextDocumentLayout.PaintContext()

if options.state & QStyle.State_Selected:
ctx.palette.setColor(QtGui.QPalette.Text,
options.palette.color(QtGui.QPalette.Active,
QtGui.QPalette.HighlightedText))
ctx.palette.setColor(QtGui.QPalette.Text,
text_color_for_state(option.palette, option.state))

textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
painter.save()
Expand All @@ -396,7 +394,7 @@ def paint(self, painter, option, index):

def sizeHint(self, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options,index)
self.initStyleOption(options, index)

doc = QtGui.QTextDocument()
doc.setHtml(options.text)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nltk>=3.0.5 # TweetTokenizer introduced in 3.0.5
numpy
odfpy>=1.3.5
Orange3 >=3.28.0
orange-widget-base >=4.12.0
orange-widget-base >=4.14.0
pandas
pdfminer3k>=1.3.1
pyqtgraph
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ deps =
oldest: orange3==3.28.0

# Use newer canvas-core and widget-base to avoid segfaults on windows
oldest: orange-canvas-core==0.1.19
oldest: orange-widget-base==4.12.0
oldest: orange-canvas-core==0.1.20
oldest: orange-widget-base==4.14.0
latest: git+git://github.com/biolab/orange3.git#egg=orange3
latest: git+git://github.com/biolab/orange3-network.git#egg=orange3-network
latest: git+git://github.com/biolab/orange-canvas-core.git#egg=orange-canvas-core
Expand Down

0 comments on commit da42f78

Please sign in to comment.