Skip to content

Commit

Permalink
DomainEditor: Use signals instead of calling open_context on widget
Browse files Browse the repository at this point in the history
  • Loading branch information
astaric committed Dec 9, 2016
1 parent 960ee9e commit fb22fd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def load_data(self):
# We need to catch any exception type since anything can happen in
# file readers
# pylint: disable=broad-except
self.closeContext()
self.domain_editor.set_domain(None)
self.apply_button.setEnabled(False)
self.Warning.file_too_big.clear()
Expand Down Expand Up @@ -306,7 +307,7 @@ def load_data(self):

add_origin(data, self.loaded_file or self.last_path())
self.data = data
self.domain_editor.set_domain(data.domain)
self.openContext(data.domain)
self.apply_domain_edit() # sends data

def _get_reader(self):
Expand Down
17 changes: 4 additions & 13 deletions Orange/widgets/utils/domaineditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ class DomainEditor(QTableView):
def __init__(self, widget):
super().__init__()
widget.settingsHandler.initialize(self)
self.openContext = widget.openContext
self.closeContext = widget.closeContext
widget.contextAboutToBeOpened.connect(lambda args: self.set_domain(args[0]))
widget.contextOpened.connect(self.update_model)

self.setModel(VarTableModel(self.variables))
self.setSelectionMode(QTableView.NoSelection)
Expand Down Expand Up @@ -238,18 +238,9 @@ def is_missing(x):
return domain, cols

def set_domain(self, domain):
"""Update the widget with information about given domain.
If domain has been seen before (saved context settings),
the existing edits will be shown.
Parameters
----------
domain : of the new data file.
"""
self.closeContext()
self.variables = self.parse_domain(domain)
self.openContext(domain)

def update_model(self):
self.model().set_variables(self.variables)

@staticmethod
Expand Down
8 changes: 6 additions & 2 deletions Orange/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
QShortcut, QSplitter, QSplitterHandle, QPushButton
)
from AnyQt.QtCore import (
Qt, QByteArray, QSettings, QUrl, pyqtSignal as Signal
)
Qt, QByteArray, QSettings, QUrl, pyqtSignal as Signal)
from AnyQt.QtGui import QIcon, QKeySequence, QDesktopServices

from Orange.data import FileFormat
Expand Down Expand Up @@ -172,6 +171,9 @@ class OWWidget(QDialog, OWComponent, Report, ProgressBarMixin,
#: :type: list of :class:`Message`
UserAdviceMessages = []

contextAboutToBeOpened = Signal(object)
contextOpened = Signal()

def __new__(cls, *args, captionTitle=None, **kwargs):
self = super().__new__(cls, None, cls.get_flags())
QDialog.__init__(self, None, self.get_flags())
Expand Down Expand Up @@ -488,7 +490,9 @@ def openContext(self, *a):
`DomainContextHandler` expects `Orange.data.Table` or
`Orange.data.Domain`.
"""
self.contextAboutToBeOpened.emit(a)
self.settingsHandler.open_context(self, *a)
self.contextOpened.emit()

def closeContext(self):
"""Save the current settings and close the current context.
Expand Down

0 comments on commit fb22fd5

Please sign in to comment.