

from PySide import QtGui

from .selector import SelectorWidget
from .options import OptionsWidget


class ExporterWidget(QtGui.QWidget):
    '''Manage exporting.'''
    
    def __init__(self, host, parent=None):
        '''Initialise with *host* application and *parent*.'''
        super(ExporterWidget, self).__init__(parent=parent)
        self.host = host
        self.build()
        self.post_build()
        
    def build(self):
        '''Build and layout the interface.'''
        self.setLayout(QtGui.QVBoxLayout())

        self.selector_widget = SelectorWidget(host=self.host)
        self.selector_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.selector_widget)
        
        self.options_widget = OptionsWidget(host=self.host)
        self.options_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.options_widget)
        
        self.export_button = QtGui.QPushButton('Export')
        self.layout().addWidget(self.export_button)
        
    def post_build(self):
        '''Perform post-build operations.'''
        self.setWindowTitle('Segue Exporter')
        


from PySide import QtGui

from .selector import SelectorWidget
from .options import OptionsWidget


class ExporterWidget(QtGui.QWidget):
    '''Manage exporting.'''
    
    def __init__(self, host, parent=None):
        '''Initialise with *host* application and *parent*.'''
        super(ExporterWidget, self).__init__(parent=parent)
        self.host = host
        self.build()
        self.post_build()
        
    def build(self):
        '''Build and layout the interface.'''
        self.setLayout(QtGui.QVBoxLayout())

        self.selector_widget = SelectorWidget(host=self.host)
        self.selector_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.selector_widget)
        
        self.options_widget = OptionsWidget(host=self.host)
        self.options_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.options_widget)
        
        self.export_button = QtGui.QPushButton('Export')
        self.layout().addWidget(self.export_button)
        
    def post_build(self):
        '''Perform post-build operations.'''
        self.setWindowTitle('Segue Exporter')
        
        self.selector_widget.added.connect(self.on_selection_changed)
        self.selector_widget.removed.connect(self.on_selection_changed)
        
        self.validate()
        
    def on_selection_changed(self, items):
        '''Handle selection change.'''
        self.validate()
        
    def validate(self):
        '''Validate options and update UI state.'''
        self.export_button.setEnabled(False)
        
        if not self.selector_widget.items():
            return
        
        self.export_button.setEnabled(True)


Add basic validation of ui state.
Add basic validation of ui state.

  
  
  from PySide import QtGui
  
  from .selector import SelectorWidget
  from .options import OptionsWidget
  
  
  class ExporterWidget(QtGui.QWidget):
      '''Manage exporting.'''
      
      def __init__(self, host, parent=None):
          '''Initialise with *host* application and *parent*.'''
          super(ExporterWidget, self).__init__(parent=parent)
          self.host = host
          self.build()
          self.post_build()
          
      def build(self):
          '''Build and layout the interface.'''
          self.setLayout(QtGui.QVBoxLayout())
  
          self.selector_widget = SelectorWidget(host=self.host)
          self.selector_widget.setFrameStyle(
              QtGui.QFrame.StyledPanel
          )
          self.layout().addWidget(self.selector_widget)
          
          self.options_widget = OptionsWidget(host=self.host)
          self.options_widget.setFrameStyle(
              QtGui.QFrame.StyledPanel
          )
          self.layout().addWidget(self.options_widget)
          
          self.export_button = QtGui.QPushButton('Export')
          self.layout().addWidget(self.export_button)
          
      def post_build(self):
          '''Perform post-build operations.'''
          self.setWindowTitle('Segue Exporter')
          
+         self.selector_widget.added.connect(self.on_selection_changed)
+         self.selector_widget.removed.connect(self.on_selection_changed)
+         
+         self.validate()
+         
+     def on_selection_changed(self, items):
+         '''Handle selection change.'''
+         self.validate()
+         
+     def validate(self):
+         '''Validate options and update UI state.'''
+         self.export_button.setEnabled(False)
+         
+         if not self.selector_widget.items():
+             return
+         
+         self.export_button.setEnabled(True)
+ 
+ 
Add basic validation of ui state.
## Code Before:


from PySide import QtGui

from .selector import SelectorWidget
from .options import OptionsWidget


class ExporterWidget(QtGui.QWidget):
    '''Manage exporting.'''
    
    def __init__(self, host, parent=None):
        '''Initialise with *host* application and *parent*.'''
        super(ExporterWidget, self).__init__(parent=parent)
        self.host = host
        self.build()
        self.post_build()
        
    def build(self):
        '''Build and layout the interface.'''
        self.setLayout(QtGui.QVBoxLayout())

        self.selector_widget = SelectorWidget(host=self.host)
        self.selector_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.selector_widget)
        
        self.options_widget = OptionsWidget(host=self.host)
        self.options_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.options_widget)
        
        self.export_button = QtGui.QPushButton('Export')
        self.layout().addWidget(self.export_button)
        
    def post_build(self):
        '''Perform post-build operations.'''
        self.setWindowTitle('Segue Exporter')
        
## Instruction:
Add basic validation of ui state.
## Code After:


from PySide import QtGui

from .selector import SelectorWidget
from .options import OptionsWidget


class ExporterWidget(QtGui.QWidget):
    '''Manage exporting.'''
    
    def __init__(self, host, parent=None):
        '''Initialise with *host* application and *parent*.'''
        super(ExporterWidget, self).__init__(parent=parent)
        self.host = host
        self.build()
        self.post_build()
        
    def build(self):
        '''Build and layout the interface.'''
        self.setLayout(QtGui.QVBoxLayout())

        self.selector_widget = SelectorWidget(host=self.host)
        self.selector_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.selector_widget)
        
        self.options_widget = OptionsWidget(host=self.host)
        self.options_widget.setFrameStyle(
            QtGui.QFrame.StyledPanel
        )
        self.layout().addWidget(self.options_widget)
        
        self.export_button = QtGui.QPushButton('Export')
        self.layout().addWidget(self.export_button)
        
    def post_build(self):
        '''Perform post-build operations.'''
        self.setWindowTitle('Segue Exporter')
        
        self.selector_widget.added.connect(self.on_selection_changed)
        self.selector_widget.removed.connect(self.on_selection_changed)
        
        self.validate()
        
    def on_selection_changed(self, items):
        '''Handle selection change.'''
        self.validate()
        
    def validate(self):
        '''Validate options and update UI state.'''
        self.export_button.setEnabled(False)
        
        if not self.selector_widget.items():
            return
        
        self.export_button.setEnabled(True)

