# Path: dpa/app/session.py
# class Session(object):
# 
#     __metaclass__ = ABCMeta 
# 
#     app_name = None
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def current(cls):
#         return None
# 
#     # -------------------------------------------------------------------------
#     def __init__(self):
#         pass
# 
#     # -------------------------------------------------------------------------
#     @abstractmethod
#     def close(self):
#         """Close the current file."""
# 
#     # -------------------------------------------------------------------------
#     def list_entities(self, categories=None):
#         """List entities in the session.""" 
# 
#         entities = []
#         entity_classes = EntityRegistry().get_entity_classes(
#             self.__class__.app_name)
#         for entity_class in entity_classes:
#             entities.extend(entity_class.list(self))
# 
#         if categories:
#             filtered = [e for e in entities if e.category in categories]
#         else:
#             filtered = entities
# 
#         return filtered
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def open_file(self, filepath):
#         """Open a new session with the supplied file."""
# 
#     # -------------------------------------------------------------------------
#     @abstractmethod
#     def save(self, filepath=None):
#         """Save the current session. Save to the file path if provided."""
# 
#     # -------------------------------------------------------------------------
#     @abstractproperty
#     def in_session(self):
#         """Returns True if inside a current app session."""
# 
#     # -------------------------------------------------------------------------
#     def init_module(self, module_path):
# 
#         _module = None
# 
#         if self.in_session:
#             try:
#                 _module = importlib.import_module(module_path)
#             except ImportError:
#                 pass # will raise below
# 
#         if not _module:
#             raise SessionError(
#                 "Failed to initialize session. " + \
#                 "'{mod}' module could not be imported.".format(mod=module_path)
#             )
# 
#         return _module
# 
#     # -------------------------------------------------------------------------
#     def require_executable(self, executable):
#         """Returns the full path for the supplied executable name."""
# 
#         (path, file_name) = os.path.split(executable)
# 
#         # path already included
#         if path:
#             if not os.path.isfile(executable):
#                 raise SessionError("Unable to locate executable: " + executable)
#             elif not os.access(executable, os.X_OK):
#                 raise SessionError("File is not executable: " + executable)
#             else:
#                 return executable
#         else:
#             bin_paths = DpaVars.path()
#             bin_paths.get()
#             for path in bin_paths.list:
#                 executable_path = os.path.join(path, executable)
#                 if (os.path.isfile(executable_path) and
#                     os.access(executable_path, os.X_OK)):
#                     return executable_path
#     
#         raise SessionError("Unable to locate executable: " + executable)
# 
#     # -------------------------------------------------------------------------
#     @property
#     def app_name(self):
#         return self.__class__.app_name
# 
#     # -------------------------------------------------------------------------
#     @property
#     def ptask_area(self):
#         """Return the current ptask area for this session."""
# 
#         if not hasattr(self, '_ptask_area'):
#             self._ptask_area = PTaskArea.current()
# 
#         return self._ptask_area
# 
#     # -------------------------------------------------------------------------
#     @property
#     def ptask(self):
# 
#         if not hasattr(self, '_ptask'):
#             ptask_area = self.ptask_area
#             if not ptask_area.spec:
#                 self._ptask = None
#             else:
#                 try:
#                     self._ptask = PTask.get(ptask_area.spec)
#                 except PTaskError as e:
#                     raise SessionError("Unable to determine ptask.")
# 
#         return self._ptask
# 
#     # -------------------------------------------------------------------------
#     @property
#     def ptask_version(self):
#         """Return the current ptask version for this session."""
# 
#         if not hasattr(self, '_ptask_version'):
# 
#             ptask = self.ptask
#             if not ptask:
#                 self._ptask_version = None
#             else:
#                 self._ptask_version = ptask.latest_version
# 
#         return self._ptask_version
# 
# class SessionRegistry(Singleton):
# 
#     # -------------------------------------------------------------------------
#     def init(self):
# 
#         self._registry = {}
# 
#     # -------------------------------------------------------------------------
#     def current(self):
# 
#         for registered_cls in self._registry.values():
#             if registered_cls.current():
#                 return registered_cls()
# 
#         return None
# 
#     # -------------------------------------------------------------------------
#     def register(self, cls):
#         self._registry[cls.app_name] = cls
# 
# class SessionError(Exception):
#     pass
# 
# Path: dpa/ui/action/options.py
# class ActionOptionWidget(ActionOptionGroup):
# 
#     # -------------------------------------------------------------------------
#     def __init__(self, config, name='root', parent=None):
# 
#         super(ActionOptionWidget, self).__init__(name, config)
# 
#         show_required_label = False
#         for widget in self.widgets:
#             if widget.required:
#                 show_required_label = True
#                 break
# 
#         if show_required_label:
#             required_label = QtGui.QLabel(REQUIRED + ' required options')
#             required_label.setAlignment(QtCore.Qt.AlignRight)
#             self._main_layout.addWidget(required_label)


from PySide import QtCore, QtGui
from dpa.app.session import Session, SessionRegistry, SessionError
from dpa.ui.action.options import ActionOptionWidget



# -----------------------------------------------------------------------------
class SessionDialog(QtGui.QDialog):

    # -------------------------------------------------------------------------
    def __init__(self, parent=None):

        self._session = SessionRegistry().current()
        if not self._session:

# Path: dpa/app/session.py
# class Session(object):
# 
#     __metaclass__ = ABCMeta 
# 
#     app_name = None
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def current(cls):
#         return None
# 
#     # -------------------------------------------------------------------------
#     def __init__(self):
#         pass
# 
#     # -------------------------------------------------------------------------
#     @abstractmethod
#     def close(self):
#         """Close the current file."""
# 
#     # -------------------------------------------------------------------------
#     def list_entities(self, categories=None):
#         """List entities in the session.""" 
# 
#         entities = []
#         entity_classes = EntityRegistry().get_entity_classes(
#             self.__class__.app_name)
#         for entity_class in entity_classes:
#             entities.extend(entity_class.list(self))
# 
#         if categories:
#             filtered = [e for e in entities if e.category in categories]
#         else:
#             filtered = entities
# 
#         return filtered
# 
#     # -------------------------------------------------------------------------
#     @classmethod
#     def open_file(self, filepath):
#         """Open a new session with the supplied file."""
# 
#     # -------------------------------------------------------------------------
#     @abstractmethod
#     def save(self, filepath=None):
#         """Save the current session. Save to the file path if provided."""
# 
#     # -------------------------------------------------------------------------
#     @abstractproperty
#     def in_session(self):
#         """Returns True if inside a current app session."""
# 
#     # -------------------------------------------------------------------------
#     def init_module(self, module_path):
# 
#         _module = None
# 
#         if self.in_session:
#             try:
#                 _module = importlib.import_module(module_path)
#             except ImportError:
#                 pass # will raise below
# 
#         if not _module:
#             raise SessionError(
#                 "Failed to initialize session. " + \
#                 "'{mod}' module could not be imported.".format(mod=module_path)
#             )
# 
#         return _module
# 
#     # -------------------------------------------------------------------------
#     def require_executable(self, executable):
#         """Returns the full path for the supplied executable name."""
# 
#         (path, file_name) = os.path.split(executable)
# 
#         # path already included
#         if path:
#             if not os.path.isfile(executable):
#                 raise SessionError("Unable to locate executable: " + executable)
#             elif not os.access(executable, os.X_OK):
#                 raise SessionError("File is not executable: " + executable)
#             else:
#                 return executable
#         else:
#             bin_paths = DpaVars.path()
#             bin_paths.get()
#             for path in bin_paths.list:
#                 executable_path = os.path.join(path, executable)
#                 if (os.path.isfile(executable_path) and
#                     os.access(executable_path, os.X_OK)):
#                     return executable_path
#     
#         raise SessionError("Unable to locate executable: " + executable)
# 
#     # -------------------------------------------------------------------------
#     @property
#     def app_name(self):
#         return self.__class__.app_name
# 
#     # -------------------------------------------------------------------------
#     @property
#     def ptask_area(self):
#         """Return the current ptask area for this session."""
# 
#         if not hasattr(self, '_ptask_area'):
#             self._ptask_area = PTaskArea.current()
# 
#         return self._ptask_area
# 
#     # -------------------------------------------------------------------------
#     @property
#     def ptask(self):
# 
#         if not hasattr(self, '_ptask'):
#             ptask_area = self.ptask_area
#             if not ptask_area.spec:
#                 self._ptask = None
#             else:
#                 try:
#                     self._ptask = PTask.get(ptask_area.spec)
#                 except PTaskError as e:
#                     raise SessionError("Unable to determine ptask.")
# 
#         return self._ptask
# 
#     # -------------------------------------------------------------------------
#     @property
#     def ptask_version(self):
#         """Return the current ptask version for this session."""
# 
#         if not hasattr(self, '_ptask_version'):
# 
#             ptask = self.ptask
#             if not ptask:
#                 self._ptask_version = None
#             else:
#                 self._ptask_version = ptask.latest_version
# 
#         return self._ptask_version
# 
# class SessionRegistry(Singleton):
# 
#     # -------------------------------------------------------------------------
#     def init(self):
# 
#         self._registry = {}
# 
#     # -------------------------------------------------------------------------
#     def current(self):
# 
#         for registered_cls in self._registry.values():
#             if registered_cls.current():
#                 return registered_cls()
# 
#         return None
# 
#     # -------------------------------------------------------------------------
#     def register(self, cls):
#         self._registry[cls.app_name] = cls
# 
# class SessionError(Exception):
#     pass
# 
# Path: dpa/ui/action/options.py
# class ActionOptionWidget(ActionOptionGroup):
# 
#     # -------------------------------------------------------------------------
#     def __init__(self, config, name='root', parent=None):
# 
#         super(ActionOptionWidget, self).__init__(name, config)
# 
#         show_required_label = False
#         for widget in self.widgets:
#             if widget.required:
#                 show_required_label = True
#                 break
# 
#         if show_required_label:
#             required_label = QtGui.QLabel(REQUIRED + ' required options')
#             required_label.setAlignment(QtCore.Qt.AlignRight)
#             self._main_layout.addWidget(required_label)


# Path: dpa/ui/app/session.py
from PySide import QtCore, QtGui
from dpa.app.session import Session, SessionRegistry, SessionError
from dpa.ui.action.options import ActionOptionWidget




# -----------------------------------------------------------------------------
class SessionDialog(QtGui.QDialog):

    # -------------------------------------------------------------------------
    def __init__(self, parent=None):

        self._session = SessionRegistry().current()
        if not self._session:

            raise SessionError("Unable to determine current app session.")