Exemple #1
0
    def _do_request_delete(self, __button):
        """
        Request to delete the selected record from the RAMSTKValidation table.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        _prompt = _(u"You are about to delete Validation {0:d} and all data "
                    u"associated with it.  Is this really what you want "
                    u"to do?").format(self._validation_id)
        _dialog = ramstk.RAMSTKMessageDialog(_prompt,
                                             self._dic_icons['question'],
                                             'question')
        _response = _dialog.do_run()

        if _response == gtk.RESPONSE_YES:
            _dialog.do_destroy()
            if self._dtc_function.request_do_delete(self._function_id):
                _prompt = _(u"An error occurred when attempting to delete "
                            u"Validation {0:d}.").format(self._validation_id)
                _error_dialog = ramstk.RAMSTKMessageDialog(
                    _prompt, self._dic_icons['error'], 'error')
                if _error_dialog.do_run() == gtk.RESPONSE_OK:
                    _error_dialog.do_destroy()

                _return = True
        else:
            _dialog.do_destroy()

        return _return
Exemple #2
0
    def _on_select_revision(self, module_id):
        """
        Load the Requirement Module View gtk.TreeModel().

        This method is called whenever an RAMSTK Program database is opened or a
        Revision is selected in the Module Book.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        self._revision_id = module_id

        # pylint: disable=attribute-defined-outside-init
        # It is defined in RAMSTKBaseView.__init__
        if self._dtc_data_controller is None:
            self._dtc_data_controller = self._mdcRAMSTK.dic_controllers[
                'requirement']

        _requirements = self._dtc_data_controller.request_do_select_all(
            revision_id=self._revision_id)
        _return = RAMSTKModuleView.on_select_revision(self, tree=_requirements)
        if _return:
            _prompt = _(u"An error occured while loading the Requirements for "
                        u"Revision ID {0:d} into the Module "
                        u"View.").format(self._revision_id)
            _dialog = ramstk.RAMSTKMessageDialog(_prompt,
                                                 self._dic_icons['error'],
                                                 'error')
            if _dialog.do_run() == self._response_ok:
                _dialog.do_destroy()

        return _return
Exemple #3
0
    def _do_request_update_all(self, __button):
        """
        Save all the Stakeholder Inputs.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        self.set_cursor(gtk.gdk.WATCH)
        if not self._dtc_data_controller.request_do_update_all():
            self._on_select_revision(self._revision_id)
        else:
            _prompt = _(u"An error occurred attempting to save the "
                        u"stakeholder inputs for Stakeholder {0:d}.").\
                format(self._stakeholder_id)
            ramstk.RAMSTKMessageDialog(_prompt, self._dic_icons['error'],
                                       'error')
            _return = True

        self.set_cursor(gtk.gdk.LEFT_PTR)

        return _return
    def _do_request_update_all(self, __button):
        """
        Request to update all Failure Definitions records.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :py:class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        self.set_cursor(gtk.gdk.WATCH)
        if not self._dtc_data_controller.request_do_update_all():
            self._on_select_revision(module_id=self._revision_id)
        else:
            _prompt = _(u"An error occurred attempting to save the failure "
                        u"definitions for Revision {0:d}.").\
                format(self._revision_id)
            ramstk.RAMSTKMessageDialog(_prompt, self._dic_icons['error'], 'error')

            _return = True

        self.set_cursor(gtk.gdk.LEFT_PTR)

        return _return
Exemple #5
0
    def _do_request_delete(self, __button):
        """
        Request to delete the selected Stakeholder.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        _model, _row = self.treeview.get_selection().get_selected()
        _stakeholder_id = _model.get_value(_row, 0)

        if not self._dtc_data_controller.request_do_delete(_stakeholder_id):
            self._on_select_revision(module_id=self._revision_id)
        else:
            _prompt = _(u"An error occurred attempting to delete failure "
                        u"stakeholder {0:d} to Stakeholder {1:d}.").\
                format(_stakeholder_id, self._stakeholder_id)
            ramstk.RAMSTKMessageDialog(_prompt, self._dic_icons['error'],
                                       'error')

            _return = True

        return _return
Exemple #6
0
    def _do_request_insert(self, **kwargs):  # pylint: disable=unused-argument
        """
        Send request to insert a new record to the RAMSTKValidation table.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        self._dtc_data_controller.request_do_select(self._validation_id)

        if not self._dtc_data_controller.request_do_insert():
            self._on_select_validation()
        else:
            _prompt = _(u"An error occurred while attempting to add a "
                        u"Validation.")
            _error_dialog = ramstk.RAMSTKMessageDialog(
                _prompt, self._dic_icons['error'], 'error')
            self._mdcRAMSTK.debug_log.error(_prompt)

            if _error_dialog.do_run() == gtk.RESPONSE_OK:
                _error_dialog.do_destroy()

            _return = True

        return _return
Exemple #7
0
    def _on_select_revision(self, module_id):
        """
        Load the Validation Module View RAMSTKTreeView().

        This method loads the RAMSTKTreeView() with Validation attribute data when
        an RAMSTK Program database is opened.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        self._revision_id = module_id

        # pylint: disable=attribute-defined-outside-init
        # It is defined in RAMSTKBaseView.__init__
        self._dtc_data_controller = self._mdcRAMSTK.dic_controllers[
            'validation']
        _validations = self._dtc_data_controller.request_do_select_all(
            revision_id=self._revision_id)

        _return = RAMSTKModuleView.on_select_revision(self, tree=_validations)
        if _return:
            _prompt = _(u"An error occured while loading Validation Tasks "
                        u"into the Module View.")
            _dialog = ramstk.RAMSTKMessageDialog(_prompt,
                                                 self._dic_icons['error'],
                                                 'error')
            if _dialog.do_run() == self._response_ok:
                _dialog.do_destroy()

        return _return
Exemple #8
0
    def _on_select_revision(self, **kwargs):  # pylint: disable=unused-argument
        """
        Load the Revision Module View RAMSTKTreeView().

        This method loads the RAMSTKTreeView() with Revision attribute data when
        an RAMSTK Program database is opened.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        # pylint: disable=attribute-defined-outside-init
        # It is defined in RAMSTKBaseView.__init__
        if self._dtc_data_controller is None:
            self._dtc_data_controller = self._mdcRAMSTK.dic_controllers[
                'revision']

        _revisions = self._dtc_data_controller.request_do_select_all()
        _return = RAMSTKModuleView.on_select_revision(self, tree=_revisions)
        if _return:
            _prompt = _(u"An error occured while loading Revisions into the "
                        u"Module View.")
            _dialog = ramstk.RAMSTKMessageDialog(_prompt,
                                                 self._dic_icons['error'],
                                                 'error')
            if _dialog.do_run() == self._response_ok:
                _dialog.do_destroy()

        return _return
Exemple #9
0
    def _do_request_delete(self, __button):
        """
        Request to delete the selected Usage Profile record.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        _model, _row = self.treeview.get_selection().get_selected()
        _node_id = _model.get_value(_row, 9)
        _level = _model.get_value(_row, 11)

        if not self._dtc_data_controller.request_do_delete(_node_id):
            self._on_select_revision(module_id=self._revision_id)
        else:
            _prompt = _(u"A problem occurred while attempting to delete {0:s} "
                        u"with ID {1:d}.").format(_level.title(), _node_id)
            ramstk.RAMSTKMessageDialog(_prompt, self._dic_icons['error'],
                                       'error')

            _return = True

        return _return
Exemple #10
0
    def on_select(self, **kwargs):
        """
        Respond to load the List View gtk.Notebook() widgets.

        This method handles the results of the an individual module's
        _on_select() method.  It sets the title of the RAMSTK Work Book and
        raises an error dialog if needed.

        :return: None
        :rtype: None
        """
        _title = kwargs['title']
        _error_code = kwargs['error_code']
        _user_msg = kwargs['user_msg']
        _debug_msg = kwargs['debug_msg']

        try:
            _workbook = self.get_parent().get_parent()
            _workbook.set_title(_title)
        except AttributeError:
            pass

        if _error_code != 0:
            self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_DEBUG_LOG.error(
                _debug_msg)
            _dialog = ramstk.RAMSTKMessageDialog(_user_msg,
                                                 self._dic_icons['error'],
                                                 'error')
            if _dialog.do_run() == gtk.RESPONSE_OK:
                _dialog.destroy()

        return None
Exemple #11
0
    def _on_select_revision(self, module_id):
        """
        Load the Hardware Module View RAMSTKTreeView().

        This method is called whenever an RAMSTK Program database is opened.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        self._revision_id = module_id

        # pylint: disable=attribute-defined-outside-init
        # It is defined in RAMSTKBaseView.__init__
        self._dtc_data_controller = self._mdcRAMSTK.dic_controllers['hardware']
        _hardware = self._dtc_data_controller.request_do_select_all(
            revision_id=self._revision_id)

        _return = RAMSTKModuleView.on_select_revision(self, tree=_hardware)
        if _return:
            _prompt = _(u"An error occured while loading the Hardware for "
                        u"Revision ID {0:d} into the Module "
                        u"View.").format(self._revision_id)
            _dialog = ramstk.RAMSTKMessageDialog(
                _prompt, self._dic_icons['error'], 'error')
            if _dialog.do_run() == self._response_ok:
                _dialog.do_destroy()
        else:
            for _analysis in ['allocation', 'hazops', 'similaritem']:
                _dtc_data_controller = self._mdcRAMSTK.dic_controllers[
                    _analysis]
                _dtc_data_controller.request_do_select_all(
                    revision_id=self._revision_id)

        return _return
Exemple #12
0
    def _do_request_delete(self, __button):
        """
        Request to delete the selected Requirement and it's children.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        _prompt = _(u"You are about to delete Requirement {0:d} and all data "
                    u"associated with it.  Is this really what you want "
                    u"to do?").format(self._requirement_id)
        _dialog = ramstk.RAMSTKMessageDialog(_prompt,
                                             self._dic_icons['question'],
                                             'question')
        _response = _dialog.do_run()

        if _response == gtk.RESPONSE_YES:
            _dialog.do_destroy()
            if self._dtc_data_controller.request_do_delete(
                    self._requirement_id):
                _prompt = _(u"An error occurred when attempting to delete "
                            u"Requirement {0:d}.").format(self._requirement_id)
                _error_dialog = ramstk.RAMSTKMessageDialog(
                    _prompt, self._dic_icons['error'], 'error')
                if _error_dialog.do_run() == gtk.RESPONSE_OK:
                    _error_dialog.do_destroy()

                _return = True
            else:
                _model, _row = self.treeview.get_selection().get_selected()
                _prow = _model.iter_parent(_row)
                _model.remove(_row)

                if _prow is not None:
                    _path = _model.get_path(_prow)
                    _column = self.treeview.get_column(0)
                    self.treeview.set_cursor(_path, None, False)
                    self.treeview.row_activated(_path, _column)

        else:
            _dialog.do_destroy()

        return _return
Exemple #13
0
    def _do_request_insert(self, **kwargs):
        """
        Send request to insert a new Hardware into the RAMSTK Program database.

        :param bool sibling: indicates whether to insert a sibling (default)
                             Hardware item or a child Hardware item.
        :param int part: indicates whether the item to insert is an
                         assembly (default) or a component/part.
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _sibling = kwargs['sibling']
        _part = kwargs['part']
        _return = False

        _attributes = self._dtc_data_controller.request_get_attributes(
                self._hardware_id)
        _attributes['revision_id'] = self._revision_id

        _model, _row = self.treeview.get_selection().get_selected()
        try:
            _path = _model.get_path(_row)
        except TypeError:
            _path = '0'

        if _sibling:
            _parent_id = _attributes['parent_id']
        else:
            _parent_id = _attributes['hardware_id']

        if not self._dtc_data_controller.request_do_insert(
                revision_id=self._revision_id, parent_id=_parent_id,
                part=_part):

            self._on_select_revision(self._revision_id)
            if _part == 1:
                print "TODO: Add code to the FMEA Class to respond to the 'insertedHardware' pubsub message and insert a set of hardware failure modes."

            self.treeview.set_cursor(_path)

        else:
            _prompt = _(u"An error occurred while attempting to add a "
                        u"hardware item to Revision "
                        u"{0:d}.").format(self._revision_id)
            _error_dialog = ramstk.RAMSTKMessageDialog(
                _prompt, self._dic_icons['error'], 'error')
            self._mdcRAMSTK.debug_log.error(_prompt)

            if _error_dialog.do_run() == gtk.RESPONSE_OK:
                _error_dialog.do_destroy()

            _return = True

        return _return
Exemple #14
0
    def _do_request_insert(self, **kwargs):
        """
        Request to insert a new Requirement into the RAMSTK Program database.

        :param bool sibling: indicates whether to insert a sibling (default)
                             Requirement or a child Requirement.
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _sibling = kwargs['sibling']
        _return = False

        _requirement = self._dtc_data_controller.request_do_select(
            self._requirement_id)

        if _sibling:
            try:
                _parent_id = _requirement.parent_id
            except AttributeError:
                _parent_id = 0
        else:
            _parent_id = _requirement.requirement_id

        # By default we add the new requirement as a top-level requirement.
        if _parent_id is None:
            _parent_id = 0

        if not self._dtc_data_controller.request_do_insert(
                revision_id=self._revision_id,
                parent_id=_parent_id,
                sibling=_sibling):
            # TODO: Add code to the Matrix Class to respond to the 'insertedRequirement' pubsub message and insert a record into each of the Requirement-X matrices.

            self._on_select_revision(self._revision_id)
        else:
            _prompt = _(u"An error occurred while attempting to add a "
                        u"requirement to Revision "
                        u"{0:d}.").format(self._revision_id)
            _error_dialog = ramstk.RAMSTKMessageDialog(
                _prompt, self._dic_icons['error'], 'error')
            self._mdcRAMSTK.debug_log.error(_prompt)

            if _error_dialog.do_run() == gtk.RESPONSE_OK:
                _error_dialog.do_destroy()

            _return = True

        return _return
Exemple #15
0
    def _do_request_open_project(self):
        """
        Open or connect to a RAMSTK Program database.

        :return: None
        :rtype: None
        """
        if self._mdcRAMSTK.loaded:
            _prompt = _(u"A database is already open.  Only one database can "
                        u"be open at a time in RAMSTK.  You must close the "
                        u"currently open RAMSTK database before a new "
                        u"database can be opened.")
            _icon = (self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_ICON_DIR +
                     '/32x32/information.png')
            _dialog = ramstk.RAMSTKMessageDialog(_prompt, _icon, 'information')
            if _dialog.run() == gtk.RESPONSE_OK:
                _dialog.destroy()

        else:
            _dialog = gtk.FileChooserDialog(
                title=_(u"RAMSTK - Open Program"),
                buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL,
                         gtk.RESPONSE_REJECT))
            _dialog.set_current_folder(
                self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_PROG_DIR)

            # Set some filters to select all files or only some text files.
            _filter = gtk.FileFilter()
            _filter.set_name(_(u"RAMSTK Program Databases"))
            _filter.add_pattern("*.rtk")
            _dialog.add_filter(_filter)

            _filter = gtk.FileFilter()
            _filter.set_name(_(u"All files"))
            _filter.add_pattern("*")
            _dialog.add_filter(_filter)

            if _dialog.run() == gtk.RESPONSE_ACCEPT:
                self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_PROG_INFO['database'] = \
                    _dialog.get_filename()

            _dialog.destroy()

            self._mdcRAMSTK.request_do_open_program()

        return None
Exemple #16
0
    def _do_request_insert(self, __assistant):
        """
        Request the data controller insert new records.

        :param __assistant: this gtk.Assistant() instance.
        :type __assistant: :class:`gtk.Assistant`
        :return: None
        :rtype: None
        """
        set_cursor(self._mdcRAMSTK, gtk.gdk.WATCH)

        (_count, _error_code,
         _msg) = self._dtc_data_controller.request_do_insert(self._module)

        set_cursor(self._mdcRAMSTK, gtk.gdk.LEFT_PTR)

        if _error_code == 2:
            _msg_type = 'error'
            _user_msg = _(u"A RAMSTK Program database must be connected to "
                          u"import the data into from an external file.  "
                          u"Please create or open a RAMSTK Program database "
                          u"and try again.")
        elif _error_code == 3:
            _msg_type = 'error'
            _user_msg = _(u"One or more import records violated PRIMARY KEY "
                          u"constraints.  Check your import file data and try "
                          u"again.")
        elif _error_code == 4:
            _msg_type = 'error'
            _user_msg = _(
                u"One or more import records contains a field with "
                u"a value that is incompatible with the required "
                u"data type for the RAMSTK Program database field it "
                u"was mapped to.")
        else:
            _msg_type = 'information'
            _user_msg = _(u"Successfully imported {0:d} {1:s} "
                          u"records.").format(_count, self._module)

        _dialog = ramstk.RAMSTKMessageDialog(
            _user_msg, self._dic_icons[_msg_type], _msg_type)
        if _dialog.do_run() == gtk.RESPONSE_OK:
            _dialog.destroy()

        return None
Exemple #17
0
    def _do_request_insert(self, **kwargs):  # pylint: disable=unused-argument
        """
        Request to add a Failure Definition record.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :py:class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        if not self._dtc_data_controller.request_do_insert(
                revision_id=self._revision_id):
            self._on_select_revision(module_id=self._revision_id)
        else:
            _prompt = _(u"An error occurred attempting to add a failure "
                        u"definition to Revision {0:d}.").\
                format(self._revision_id)
            ramstk.RAMSTKMessageDialog(_prompt, self._dic_icons['error'], 'error')

            _return = True

        return _return
Exemple #18
0
    def _do_request_insert(self, **kwargs):  # pylint: disable=unused-argument
        """
        Request to add a Stakeholder.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        if not self._dtc_data_controller.request_do_insert(
                self._stakeholder_id):
            self._on_select_stakeholder(self._stakeholder_id)
        else:
            _prompt = _(u"An error occurred attempting to add a stakeholder "
                        u"input to Stakeholder {0:d}.").\
                format(self._stakeholder_id)
            ramstk.RAMSTKMessageDialog(_prompt, self._dic_icons['error'],
                                       'error')

            _return = True

        return _return
Exemple #19
0
    def _on_select_revision(self, module_id):
        """
        Load the Failure Definition List View gtk.TreeModel().

        This method is called whenever a new Revision is selected in the RAMSTK
        Module View.

        :param int module_id: the Revision ID to select the Failure
                              Definitions for.
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        self._revision_id = module_id

        # pylint: disable=attribute-defined-outside-init
        # It is defined in RAMSTKBaseView.__init__
        if self._dtc_data_controller is None:
            self._dtc_data_controller = self._mdcRAMSTK.dic_controllers[
                'definition']

        _definitions = self._dtc_data_controller.request_do_select_all(
            revision_id=self._revision_id)

        _return = RAMSTKListView.on_select_revision(self, tree=_definitions)
        if _return:
            _prompt = _(u"An error occured while loading the Failure "
                        u"Definitions for Revision ID {0:d} into the List "
                        u"View.").format(self._revision_id)
            _dialog = ramstk.RAMSTKMessageDialog(
                _prompt, self._dic_icons['error'], 'error')
            if _dialog.do_run() == self._response_ok:
                _dialog.do_destroy()

        return _return
Exemple #20
0
    def _do_request_insert(self, **kwargs):
        """
        Request to insert a new entity to the FMEA.

        :return: False if sucessful or True if an error is encountered.
        :rtype: bool
        """
        _sibling = kwargs['sibling']
        _return = False
        _choose = False
        _undefined = False

        # Try to get the information needed to add a new entity at the correct
        # location in the FMEA.  If there is nothing in the FMEA, by default
        # add a failure Mode.
        _model, _row = self.treeview.get_selection().get_selected()
        try:
            _node_id = _model.get_value(_row, 12)
            _level = self._get_level(_node_id)
            _prow = _model.iter_parent(_row)
        except TypeError:
            _node_id = 0
            _level = 'mode'
            _prow = None

        if _sibling:
            if _level == 'opstress' or _level == 'testmethod':
                _choose = True
            try:
                _entity_id = _model.get_value(_prow, 0)
                _parent_id = _model.get_value(_prow, 12)
            except TypeError:
                _entity_id = self._hardware_id
                _parent_id = _node_id

        elif not _sibling:
            if _level == 'mechanism':
                _level = 'opload'
            elif _level == 'opload':
                _choose = True
            elif _level == 'opstress' or _level == 'testmethod':
                _undefined = True
            _entity_id = _model.get_value(_row, 0)
            _parent_id = _node_id

        # Insert the new entity into the RAMSTK Program database and then refresh
        # the TreeView.
        if _undefined:
            _prompt = _(u"A Physics of Failure operating stress or test "
                        u"method cannot have a child entity.")
            _dialog = ramstk.RAMSTKMessageDialog(
                _prompt, self._dic_icons['error'], 'error')

            if _dialog.do_run() == gtk.RESPONSE_OK:
                _dialog.do_destroy()

            _return = True

        if _choose:
            _dialog = AddStressMethod()

            if _dialog.do_run() == gtk.RESPONSE_OK:
                _opstress = _dialog.rdoStress.get_active()
                _testmethod = _dialog.rdoMethod.get_active()

                if _opstress:
                    _level = 'opstress'
                elif _testmethod:
                    _level = 'testmethod'

            else:
                _return = True

            _dialog.do_destroy()

        # Insert the new entity into the RAMSTK Program database and then refresh
        # the TreeView.
        if (_undefined or _return or
                self._dtc_data_controller.request_do_insert(
                    entity_id=_entity_id, parent_id=_parent_id, level=_level)):
            _return = True

        if not _return:
            self._on_select(module_id=self._hardware_id)

        return _return
Exemple #21
0
    def _do_request_insert(self, **kwargs):
        """
        Request to add an entity to the Usage Profile.

        :param __button: the gtk.ToolButton() that called this method.
        :type __button: :class:`gtk.ToolButton`
        :param bool sibling: indicator variable that determines whether a
                             sibling entity be added (default) or a child
                             entity be added to the currently selected entity.
        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _sibling = kwargs['sibling']
        _return = False

        # Get the currently selected row, the level of the currently selected
        # item, and it's parent row in the Usage Profile.
        _model, _row = self.treeview.get_selection().get_selected()
        try:
            _level = _model.get_value(_row, 11)
            _prow = _model.iter_parent(_row)
        except TypeError:
            _level = ''
            _prow = None

        if _sibling:
            if _level == 'mission':
                _entity_id = self._revision_id
                _parent_id = 0
            else:
                _entity_id = _model.get_value(_prow, 1)
                _parent_id = _model.get_value(_prow, 9)
        else:
            _entity_id = _model.get_value(_row, 1)
            _parent_id = _model.get_value(_row, 9)

        if _level == 'mission' and not _sibling:
            _level = 'phase'

        elif _level == 'phase' and not _sibling:
            _level = 'environment'

        elif _level == 'environment' and not _sibling:
            _prompt = _(u"An environmental condition cannot have a child.")
            _dialog = ramstk.RAMSTKMessageDialog(_prompt,
                                                 self._dic_icons['error'],
                                                 'error')
            if _dialog.do_run() == gtk.RESPONSE_OK:
                _dialog.do_destroy()
            else:
                _dialog.do_destroy()

            _return = True

        if (not _return and not self._dtc_data_controller.request_do_insert(
                entity_id=_entity_id, parent_id=_parent_id, level=_level)):
            self._on_select_revision(module_id=self._revision_id)
        else:
            _return = True

        return _return
Exemple #22
0
    def __init__(self, **kwargs):
        """Initialize an instance of the RAMSTK data controller."""
        # Read the site configuration file.
        self.RAMSTK_CONFIGURATION.set_site_variables()
        if self.RAMSTK_CONFIGURATION.set_user_variables():
            _prompt = _(
                u"A user-specific configuration directory could not "
                u"be found at {0:s}.  You will be given the option to "
                u"create and populate this directory.  If you choose "
                u"not to, you will recieve this prompt every time you "
                u"execute RAMSTK.  Would you like to create and populate "
                u"a user-specific configuration directory?").format(
                    self.RAMSTK_CONFIGURATION.RAMSTK_HOME_DIR +
                    "/.config/RAMSTK")
            _dialog = ramstk.RAMSTKMessageDialog(_prompt, '', 'question')
            _response = _dialog.do_run()
            _dialog.do_destroy()

            if _response == gtk.RESPONSE_YES:
                self.RAMSTK_CONFIGURATION.create_user_configuration()

            self.RAMSTK_CONFIGURATION.set_user_variables(first_run=False)

        self.RAMSTK_CONFIGURATION.get_user_configuration()

        # Create loggers.
        (self.RAMSTK_CONFIGURATION.RAMSTK_DEBUG_LOG,
         self.RAMSTK_CONFIGURATION.RAMSTK_USER_LOG,
         self.RAMSTK_CONFIGURATION.RAMSTK_IMPORT_LOG) = \
            _initialize_loggers(self.RAMSTK_CONFIGURATION)

        # Initialize private dictionary instance attributes.

        # Initialize private list instance attributes.
        self.__test = kwargs['test']
        self._lst_modules = [
            'requirement', 'function', 'hardware', 'validation'
        ]

        # Initialize private scalar instance attributes.

        # Initialize public dictionary instance attributes.
        self.dic_controllers = {
            'options': None,
            'allocation': None,
            'definition': None,
            'function': None,
            'revision': None,
            'requirement': None,
            'hardware': None,
            'validation': None,
            'matrices': None,
            'profile': None,
            'ffmea': None,
            'fmea': None,
            'stakeholder': None,
            'hazard': None,
            'similaritem': None,
            'pof': None,
            'imports': None,
            'exports': None,
        }
        self.dic_books = {
            'listbook': None,
            'modulebook': None,
            'workbook': None
        }

        # Define public list attributes.

        # Define public scalar attributes.
        self.icoStatus = gtk.StatusIcon()
        self.loaded = False

        # Connect to the RAMSTK Common database.
        _database = None
        if self.RAMSTK_CONFIGURATION.RAMSTK_COM_BACKEND == 'sqlite':
            _database = self.RAMSTK_CONFIGURATION.RAMSTK_COM_BACKEND + \
                        ':///' + \
                        self.RAMSTK_CONFIGURATION.RAMSTK_COM_INFO['database']
        _dao = DAO()
        _dao.db_connect(_database)

        # Create an instance of the RAMSTK Data Model and load global constants.
        self.ramstk_model = Model(_dao, DAO())
        self.request_do_load_globals()

        # Create an Options module instance and read the Site options.
        self.dic_controllers['options'] = dtcOptions(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            site_dao=_dao,
            test=False)
        self.dic_controllers['options'].request_do_select_all(site=True,
                                                              program=False)

        # Create a Preferences module instance and read the user preferences.
        self.dic_controllers['preferences'] = dtcPreferences(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            site_dao=_dao,
            test=False)
        self.dic_controllers['preferences'].request_do_select_all(site=True,
                                                                  user=True)

        # Create an Import module instance.
        self.dic_controllers['imports'] = dtcImports(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            test=False)

        # Create an Export module instance.
        self.dic_controllers['exports'] = dtcExports(
            self.ramstk_model.program_dao,
            self.RAMSTK_CONFIGURATION,
            test=False)

        # Validate the license.
        # if self._validate_license():
        #    sys.exit(2)

        # Create RAMSTK Books.  These need to be initialized after reading the
        # configuration.
        if self.RAMSTK_CONFIGURATION.RAMSTK_GUI_LAYOUT == 'basic':  # Single window.
            pass
        else:  # Multiple windows.
            self.dic_books['listbook'] = ListBook(self)
            self.dic_books['modulebook'] = ModuleBook(self)
            self.dic_books['workbook'] = WorkBook(self)

        _icon = self.RAMSTK_CONFIGURATION.RAMSTK_ICON_DIR + \
            '/32x32/db-disconnected.png'
        _icon = gtk.gdk.pixbuf_new_from_file_at_size(_icon, 22, 22)
        self.icoStatus.set_from_pixbuf(_icon)
        self.icoStatus.set_tooltip(
            _(u"RAMSTK is not currently connected to a "
              u"project database."))