diff --git a/cobertura.xml b/cobertura.xml index 2b0dd7363..20c2fed64 100644 --- a/cobertura.xml +++ b/cobertura.xml @@ -1,5 +1,5 @@ - + @@ -33,33 +33,32 @@ - - + - - + + - + - - - + + + - - + + - + - + @@ -67,12 +66,13 @@ - - + + + @@ -90,10 +90,10 @@ - - - - + + + + @@ -3243,50 +3243,50 @@ - + + - - - - + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + diff --git a/src/ramstk/__main__.py b/src/ramstk/__main__.py index 42f1335de..0e9bc8efb 100644 --- a/src/ramstk/__main__.py +++ b/src/ramstk/__main__.py @@ -76,9 +76,11 @@ def on_fail_create_user_configuration(error_message: str) -> None: def the_one_ring() -> None: """Execute the main function for RAMSTK.""" - # // TODO: Implement splash screen. - # // - # // Add a splash screen to the launch of RAMSTK. + #// TODO: Implement splash screen. + #// + #// Add a splash screen to the launch of RAMSTK. + #// + #// labels: globalbacklog, normal # splScreen = SplashScreen() # Read the user configuration file and create a logger. The user @@ -163,8 +165,6 @@ def the_one_ring() -> None: _program_mgr.dic_managers['function']['matrix'] = mmFunction() _program_mgr.dic_managers['function']['analysis'] = amFunction( user_configuration) - # _program_mgr.dic_managers['ffmea']['analysis'] = amFMEA(user_configuration) - # _program_mgr.dic_managers['ffmea']['data'] = dmFMEA(functional=True) _program_mgr.dic_managers['requirement']['data'] = dmRequirement() _program_mgr.dic_managers['requirement']['matrix'] = mmRequirement() _program_mgr.dic_managers['stakeholder']['analysis'] = amStakeholder( @@ -189,6 +189,7 @@ def the_one_ring() -> None: _logger.do_log_info(__name__, "Initialized the RAMSTK application.") _logger.do_log_info(__name__, "Launching RAMSTK GUI.") + # If you don't do this, the splash screen will show, but won't render it's # contents # while Gtk.events_pending(): diff --git a/src/ramstk/controllers/options/datamanager.py b/src/ramstk/controllers/options/datamanager.py index cbc8a4e0d..c76dcf728 100644 --- a/src/ramstk/controllers/options/datamanager.py +++ b/src/ramstk/controllers/options/datamanager.py @@ -3,7 +3,7 @@ # ramstk.controllers.options.datamanager.py is part of The RAMSTK Project # # All rights reserved. -# Copyright 2007 - 2019 Doyle Rowland doyle.rowland reliaqual com +# Copyright 2007 - 2020 Doyle Rowland doyle.rowland reliaqual com """Options Package Data Model.""" # Standard Library Imports diff --git a/src/ramstk/views/gtk3/assistants/__init__.py b/src/ramstk/views/gtk3/assistants/__init__.py index 2a9940c3a..c07c4028a 100644 --- a/src/ramstk/views/gtk3/assistants/__init__.py +++ b/src/ramstk/views/gtk3/assistants/__init__.py @@ -11,6 +11,6 @@ from .fmea import AddControlAction from .options import EditOptions from .pof import AddStressTestMethod -#from .preferences import EditPreferences +from .preferences import EditPreferences from .project import CreateProject, OpenProject from .similaritem import EditFunction diff --git a/src/ramstk/views/gtk3/assistants/preferences.py b/src/ramstk/views/gtk3/assistants/preferences.py index 7581e219a..9ae9255a2 100644 --- a/src/ramstk/views/gtk3/assistants/preferences.py +++ b/src/ramstk/views/gtk3/assistants/preferences.py @@ -10,18 +10,21 @@ # Standard Library Imports from os.path import basename +from shutil import copyfile # Third Party Imports +# noinspection PyPackageRequirements import defusedxml.lxml as lxml # RAMSTK Package Imports -from ramstk.models.commondb import (RAMSTKRPN, RAMSTKCondition, RAMSTKGroup, - RAMSTKLoadHistory, RAMSTKMeasurement, - RAMSTKUser) -from ramstk.views.gtk3 import Gdk, GObject, Gtk, Pango, _ +from ramstk.configuration import RAMSTKUserConfiguration +from ramstk.logger import RAMSTKLogManager +from ramstk.views.gtk3 import Gdk, GObject, Gtk, _ from ramstk.views.gtk3.widgets import ( - RAMSTKBaseView, RAMSTKCheckButton, RAMSTKComboBox, RAMSTKEntry, - RAMSTKFrame, RAMSTKLabel, RAMSTKMessageDialog) + RAMSTKBaseView, RAMSTKComboBox, RAMSTKEntry, RAMSTKFrame, RAMSTKLabel, + RAMSTKScrolledWindow, do_make_buttonbox, do_make_column, + do_make_label_group, do_make_text_cell, do_make_toggle_cell, + do_set_cell_properties) class EditPreferences(Gtk.Window, RAMSTKBaseView): @@ -34,47 +37,75 @@ class EditPreferences(Gtk.Window, RAMSTKBaseView): $HOME/.config/RAMSTK directory and are applicable only to that specific user. Configuration preferences are edited with the Preferences assistant. """ - def __init__(self, __widget, controller) -> None: + # Define private list class attributes. + _lst_labels = [ + _("Module Book tab position:"), + _("Work Book tab position:"), + _("List Book tab position:"), + _("Report size:"), + _("Failure rate multiplier:"), + _("Decimal places:"), + _("Reliability estimation time:"), + _("Path to RAMSTK configuration files:"), + _("Path to RAMSTK data files:"), + _("Path to RAMSTK log files:"), + _("Select format file to edit:"), + _("Revision Tree Background Color:"), + _("Revision Tree Foreground Color:"), + _("Function Tree Background Color:"), + _("Function Tree Foreground Color:"), + _("Requirements Tree Background Color:"), + _("Requirements Tree Foreground Color:"), + _("Hardware Tree Background Color:"), + _("Hardware Tree Foreground Color:"), + _("Validation Tree Background Color:"), + _("Validation Tree Foreground Color:") + ] + + def __init__(self, __widget: Gtk.ImageMenuItem, + configuration: RAMSTKUserConfiguration, + logger: RAMSTKLogManager, parent: object) -> None: """ Initialize an instance of the Preferences assistant. - :param Gtk.Widget __widget: the Gtk.Widget() that called this class. - :param controller: the RAMSTK master data controller. - :type controller: :class:`RAMSTK.RAMSTK` + :param __widget: the Gtk.ImageMenuItem() that called this assistant. + :type __widget: :class:`Gtk.ImageMenuItem` + :param configuration: the RAMSTKUserConfiguration class instance. + :type configuration: + :class:`ramstk.configuration.RAMSTKUserConfiguration` + :param logger: the RAMSTKLogManager class instance. + :type logger: :class:`ramstk.logger.RAMSTKLogManager` + :param parent: the RAMSTKDesktop from which this assistant was + launched. + :type parent: object """ GObject.GObject.__init__(self) - RAMSTKBaseView.__init__(self, controller, module='preferences') + RAMSTKBaseView.__init__(self, + configuration, + logger, + module='preferences') # Initialize private dictionary attributes. - self._dic_icons['save-layout'] = ( - controller.RAMSTK_CONFIGURATION.RAMSTK_ICON_DIR - + '/32x32/save-layout.png') self._site_preferences = {} self._user_preferences = {} # Initialize private list attributes. + self._lst_callbacks = [self._do_quit, self._do_request_update] + self._lst_icons = ['cancel'] + self._lst_tooltips = [ + _("Quit the RAMSTK preferences assistant without saving.") + ] # Initialize private scalar attributes. - self._dtc_data_controller = self._mdcRAMSTK.dic_controllers[ - 'preferences'] - self._fmt_file = None + self._fmt_file: str = '' + self._notebook = Gtk.Notebook() + self._parent = parent # Initialize public dictionary attributes. # Initialize public list attributes. # Initialize public scalar attributes. - self.notebook = Gtk.Notebook() - - # Which modules are enabled for this RAMSTK program? - self.chkFunctions = RAMSTKCheckButton( - label=_("Function Module Active")) - self.chkRequirements = RAMSTKCheckButton( - label=_("Requirements Module Active")) - self.chkHardware = RAMSTKCheckButton(label=_("Hardware Module Active")) - self.chkValidation = RAMSTKCheckButton( - label=_("Validation Module Active")) - self.chkFMEA = RAMSTKCheckButton(label=_("(D)FME(C)A Module Active")) # What are the general user preferences? self.btnConfDir = Gtk.FileChooserButton( @@ -82,8 +113,6 @@ def __init__(self, __widget, controller) -> None: self.btnDataDir = Gtk.FileChooserButton(_("RAMSTK Data Directory")) self.btnIconDir = Gtk.FileChooserButton(_("RAMSTK Icon Directory")) self.btnLogDir = Gtk.FileChooserButton(_("RAMSTK Log Directory")) - self.btnProgramDir = Gtk.FileChooserButton( - _("RAMSTK Program Directory")) self.cmbModuleBookTabPosition = RAMSTKComboBox(simple=True) self.cmbWorkBookTabPosition = RAMSTKComboBox(simple=True) @@ -91,13 +120,12 @@ def __init__(self, __widget, controller) -> None: self.cmbReportSize = RAMSTKComboBox(simple=True) self.txtFRMultiplier = RAMSTKEntry() - self.txtDecimalPlaces = RAMSTKEntry(width=75) - self.txtMissionTime = RAMSTKEntry(width=75) + self.txtDecimalPlaces = RAMSTKEntry() + self.txtMissionTime = RAMSTKEntry() # What are the names and, optionally, paths to the format files and the # layout of each one? - self.cmbFormatFiles = RAMSTKComboBox( - tooltip=_("Select the Module View layout to edit."), simple=False) + self.cmbFormatFiles = RAMSTKComboBox(simple=False) self.tvwFormatFile = Gtk.TreeView() # What are the desired background and foreground colors for the @@ -119,259 +147,145 @@ def __init__(self, __widget, controller) -> None: self.btnTestingBGColor = Gtk.ColorButton() self.btnTestingFGColor = Gtk.ColorButton() - # What RAMSTK global lists are available to edit? - self.cmbLists = RAMSTKComboBox( - tooltip=_("Select global RAMSTK list to edit."), - simple=False, - ) - self.tvwListEditor = Gtk.TreeView() + self._lst_widgets = [ + self.cmbModuleBookTabPosition, self.cmbWorkBookTabPosition, + self.cmbListBookTabPosition, self.cmbReportSize, + self.txtFRMultiplier, self.txtDecimalPlaces, self.txtMissionTime, + self.btnConfDir, self.btnDataDir, self.btnLogDir, + self.cmbFormatFiles, self.btnRevisionBGColor, + self.btnRevisionFGColor, self.btnFunctionBGColor, + self.btnFunctionFGColor, self.btnRequirementsBGColor, + self.btnRequirementsFGColor, self.btnHardwareBGColor, + self.btnHardwareFGColor, self.btnValidationBGColor, + self.btnValidationFGColor + ] + self.__set_properties() self.__make_ui() + self.__load_comboboxes() + self.__set_callbacks() self._do_load_page() - def __make_active_modules_page(self) -> None: + def __load_comboboxes(self) -> None: """ - Make the Option class Gtk.Notebook() active modules page. + Load the RAMSTKComboBoxes() with their data. :return: None :rtype: None """ - _tooltips = [ - _("Save the active modules used in this RAMSTK " - "program.") - ] - _callbacks = [self._do_request_update] - _icons = ['save'] - _buttonbox = RAMSTKBaseView._make_buttonbox(self, - icons=_icons, - tooltips=_tooltips, - callbacks=_callbacks, - orientation='vertical', - height=-1, - width=-1) - _button = _buttonbox.get_children()[0] - _button.set_property('name', 'modules') - - _hbox = Gtk.HBox() - _fixed = Gtk.Fixed() - _hbox.pack_start(_buttonbox, False, True, 0) - _hbox.pack_end(_fixed, True, True, 0) - - _fixed.put(self.chkFunctions, 5, 5) - _fixed.put(self.chkRequirements, 5, 35) - _fixed.put(self.chkHardware, 5, 65) - _fixed.put(self.chkValidation, 5, 95) - _fixed.put(self.chkFMEA, 5, 125) - - _label = RAMSTKLabel(_("Active RAMSTK Modules"), - justify=Gtk.Justification.CENTER) - _label.set_tooltip_text(_("Select active RAMSTK modules.")) - self.notebook.insert_page(_hbox, tab_label=_label, position=-1) - - def __make_general_preferences_page(self) -> None: - """ - Make the Preferences class Gtk.Notebook() general preferences page. + self.cmbModuleBookTabPosition.do_load_combo([["Bottom"], ["Left"], + ["Right"], ["Top"]]) + self.cmbWorkBookTabPosition.do_load_combo([["Bottom"], ["Left"], + ["Right"], ["Top"]]) + self.cmbListBookTabPosition.do_load_combo([["Bottom"], ["Left"], + ["Right"], ["Top"]]) + self.cmbReportSize.do_load_combo([["A4"], ["Letter"]]) + self.cmbFormatFiles.do_load_combo( + [[_("Allocation"), 'allocation', ''], [ + _("(D)FME(C)A"), 'fmea', '' + ], [_("Failure Definition"), 'failure_definition', ''], + [_("Function"), 'function', ''], [_("Hardware"), 'hardware', ''], + [_("Hazards Analysis"), 'hazard', ''], + [_("Physics of Failure Analysis"), 'pof', ''], + [_("Requirement"), 'requirement', ''], + [_("Revision"), 'revision', ''], + [_("Similar Item Analysis"), 'similar_item', ''], + [_("Stakeholder Input"), 'stakeholder', ''], + [_("Validation"), 'validation', '']], + simple=False) + + def __make_format_treeview(self) -> None: + """ + Make the format file editing Gtk.Treeview(). :return: None :rtype: None """ - _tooltips = [_("Save the user's general preferences.")] - _callbacks = [self._do_request_update] - _icons = ['save'] - _buttonbox = RAMSTKBaseView._make_buttonbox(self, - icons=_icons, - tooltips=_tooltips, - callbacks=_callbacks, - orientation='vertical', - height=-1, - width=-1) - _button = _buttonbox.get_children()[0] - _button.set_property('name', 'general') - - _hbox = Gtk.HBox() - _fixed = Gtk.Fixed() - _hbox.pack_start(_buttonbox, False, True, 0) - _hbox.pack_end(_fixed, True, True, 0) - - _positions = [["Bottom"], ["Left"], ["Right"], ["Top"]] - self.cmbModuleBookTabPosition.do_load_combo(_positions) - self.cmbWorkBookTabPosition.do_load_combo(_positions) - self.cmbListBookTabPosition.do_load_combo(_positions) - - _sizes = [["A4"], ["Letter"]] - self.cmbReportSize.do_load_combo(_sizes) - - _label = RAMSTKLabel( - _("Module Book tab position:"), - tooltip=_("Set the position of the RAMSTK Module Book tabs."), - width=-1) - _fixed.put(_label, 5, 5) - _fixed.put(self.cmbModuleBookTabPosition, 310, 5) - _label = RAMSTKLabel( - _("Work Book tab position:"), - tooltip=_("Set the position of the RAMSTK Work Book tabs."), - width=-1) - _fixed.put(_label, 5, 35) - _fixed.put(self.cmbWorkBookTabPosition, 310, 35) - _label = RAMSTKLabel( - _("List Book tab position:"), - tooltip=_("Set the position of the RAMSTK List Book tabs."), - width=-1) - _fixed.put(_label, 5, 65) - _fixed.put(self.cmbListBookTabPosition, 310, 65) - _label = RAMSTKLabel( - _("Report size:"), - tooltip=_("Set the default paper size of RAMSK reports."), - width=-1) - _fixed.put(_label, 5, 125) - _fixed.put(self.cmbReportSize, 310, 125) - _label = RAMSTKLabel(_("Failure rate multiplier:"), - tooltip=_("Set the failure rate multiplier."), - width=-1) - _fixed.put(_label, 5, 155) - _fixed.put(self.txtFRMultiplier, 310, 155) - _label = RAMSTKLabel( - _("Decimal places:"), - tooltip=_("Set the default number of decimal places displayed " - "in RAMSTK."), - width=-1) - _fixed.put(_label, 5, 185) - _fixed.put(self.txtDecimalPlaces, 310, 185) - _label = RAMSTKLabel( - _("Reliability estimation time:"), - tooltip=_("Set the time at which reliabilities are calculated."), - width=-1) - _fixed.put(_label, 5, 215) - _fixed.put(self.txtMissionTime, 310, 215) - _label = RAMSTKLabel( - _("Path to RAMSTK configuration files:"), - tooltip=_("Set the path to the directory where RAMSTK looks for " - "configuration files."), - width=-1) - _fixed.put(_label, 5, 245) - _fixed.put(self.btnConfDir, 310, 245) - _label = RAMSTKLabel( - _("Path to RAMSTK data files:"), - tooltip=_("Set the path to the directory where RAMSTK looks for " - "data files (e.g., layout formats, icons, etc.)."), - width=-1) - _fixed.put(_label, 5, 275) - _fixed.put(self.btnDataDir, 310, 275) - _label = RAMSTKLabel( - _("Path to RAMSTK log files:"), - tooltip=_("Set the path to the directory where RAMSTK writes " - "log files."), - width=-1) - _fixed.put(_label, 5, 305) - _fixed.put(self.btnLogDir, 310, 305) - _label = RAMSTKLabel( - _("Path to RAMSTK analyses:"), - tooltip=_("Set the path to the directory where RAMSTK stores " - "analyses databases."), - width=-1) - _fixed.put(_label, 5, 335) - _fixed.put(self.btnProgramDir, 310, 335) + _model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, + GObject.TYPE_INT, GObject.TYPE_INT, + GObject.TYPE_INT, GObject.TYPE_STRING, + GObject.TYPE_STRING, GObject.TYPE_STRING) + self.tvwFormatFile.set_model(_model) - self.btnConfDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) - self.btnDataDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) - self.btnIconDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) - self.btnLogDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) - self.btnProgramDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) + for _idx, _text in enumerate([ + _("Default\nTitle"), + _("User\nTitle"), + _("Column\nPosition"), + _("Can\nEdit?"), + _("Is\nVisible?") + ]): + if _idx == 0: + _cell = do_make_text_cell(False) + do_set_cell_properties(_cell, + bg_color='light gray', + editable=False, + fg_color='#000000', + weight=700, + weight_set=True) + _column = do_make_column([_cell], heading=_text) + _column.set_attributes(_cell, text=_idx) + elif _idx in [1, 2]: + _cell = do_make_text_cell(False) + do_set_cell_properties(_cell, + bg_color='#FFFFFF', + editable=True, + fg_color='#000000') + _cell.connect('edited', self._do_edit_cell, _idx, _model) + _column = do_make_column([_cell], heading=_text) + _column.set_attributes(_cell, text=_idx) + elif _idx > 4: + _cell = do_make_text_cell(False) + do_set_cell_properties(_cell, + bg_color='light gray', + editable=False, + fg_color='#000000') + _column = do_make_column([_cell], heading=_text, visible=False) + else: + _cell = do_make_toggle_cell() + do_set_cell_properties(_cell, editable=True) + _cell.connect('toggled', self._do_toggle_cell, _idx, _model) + _column = do_make_column([_cell], heading=_text) + _column.set_attributes(_cell, active=_idx) - _label = RAMSTKLabel(_("General\nPreferences"), - height=-1, - justify=Gtk.Justification.CENTER) - _label.set_tooltip_text( - _("Allows setting general user preferences for RAMSTK.")) - self.notebook.insert_page(_hbox, tab_label=_label, position=-1) + self.tvwFormatFile.append_column(_column) - def __make_global_lists_page(self) -> None: + def __make_general_preferences_page(self) -> None: """ - Make the page used to edit global RAMSTK lists. + Make the Preferences class Gtk.Notebook() general preferences page. :return: None :rtype: None """ - _tooltips = [ - _("Add an entry to the currently selected global list."), - _("Remove the currently selected item from the global list."), - _("Save the RAMSTK global lists.") - ] - _callbacks = [ - self._do_request_list_add, self._do_request_list_remove, - self._do_request_update - ] - _icons = ['add', 'remove', 'save'] - _buttonbox = RAMSTKBaseView._make_buttonbox(self, - icons=_icons, - tooltips=_tooltips, - callbacks=_callbacks, - orientation='vertical', - height=-1, - width=-1) - _button = _buttonbox.get_children()[0] - _button.set_property('name', 'globallists') - - _hbox = Gtk.HBox() - _vbox = Gtk.VBox() - _frame = RAMSTKFrame(_("Edit RAMSTK Lists")) - _frame.add(_vbox) - _fixed = Gtk.Fixed() - _scrollwindow = Gtk.ScrolledWindow() - _hbox.pack_start(_buttonbox, False, True, 0) - _hbox.pack_end(_frame, True, True, 0) - _vbox.pack_start(_fixed, False, True, 0) - _vbox.pack_end(_scrollwindow, True, True, 0) - - _label = RAMSTKLabel(_("Select RAMSTK list to load:"), width=-1) - _fixed.put(_label, 5, 5) - _fixed.put(self.cmbLists, 225, 5) - _scrollwindow.add(self.tvwListEditor) - - _model = Gtk.ListStore( - GObject.TYPE_INT, - GObject.TYPE_STRING, - GObject.TYPE_STRING, - GObject.TYPE_STRING, - GObject.TYPE_STRING, - ) - for _idx in [0, 1, 2, 3]: - _cell = Gtk.CellRendererText() - _cell.set_property('cell-background', '#FFFFFF') - _cell.set_property('editable', True) - _cell.set_property('foreground', '#000000') - _cell.set_property('wrap-width', 250) - _cell.set_property('wrap-mode', Pango.WrapMode.WORD) - _cell.set_property('yalign', 0.1) - _cell.connect('edited', self._do_edit_cell, _idx, _model) - _column = Gtk.TreeViewColumn("") - _column.set_alignment(0.5) - _column.set_visible(True) - _column.pack_start(_cell, True) - _column.set_attributes(_cell, text=_idx) - self.tvwListEditor.append_column(_column) - self.tvwListEditor.set_model(_model) - - _lists = [[ - _("Damaging Operating Conditions"), 'damaging_conditions', '' - ], [_("Means for Classifying Load Histories"), 'load_history', ''], - [_("Measureable Parameters"), 'measureable_parameters', ''], - [_("RPN Detection"), 'rpn_detection', ''], - [_("RPN Occurrence"), 'rpn_occurrence', ''], - [_("RPN Severity"), 'rpn_severity', ''], - [_("RAMSTK Work Groups"), 'workgroups', ''], - [_("RAMSTK Users"), 'users', '']] - self.cmbLists.do_load_combo(_lists, simple=False) - - _label = RAMSTKLabel( - _("Global RAMSTK Lists"), + _fixed: Gtk.Fixed = Gtk.Fixed() + _scrollwindow: RAMSTKScrolledWindow = RAMSTKScrolledWindow(_fixed) + _frame: RAMSTKFrame = RAMSTKFrame() + _frame.do_set_properties(title="General Preferences and Directory " + "Paths") + _frame.add(_scrollwindow) + + # Create and place the labels. Place the associated widget. + _y_pos = 5 + _x_pos, _lst_labels = do_make_label_group(self._lst_labels[:10]) + for _idx, _label in enumerate(_lst_labels): + _minimum: Gtk.Requisition = self._lst_widgets[ + _idx].get_preferred_size()[0] + if _minimum.height == 0: + try: + _minimum.height = self._lst_widgets[_idx].height + except AttributeError: + _minimum.height = 35 + + _fixed.put(_label, 5, _y_pos) + _fixed.put(self._lst_widgets[_idx], _x_pos + 5, _y_pos) + _y_pos += _minimum.height + 5 + + _label = RAMSTKLabel(_("General\nPreferences")) + _label.do_set_properties( + height=-1, justify=Gtk.Justification.CENTER, - ) - _label.set_tooltip_text( - _("Edit global RAMSTK lists; lists available " - "to all RAMSTK Programs.")) - self.notebook.insert_page(_hbox, tab_label=_label, position=-1) + tooltip=_("Allows setting general user preferences for RAMSTK.")) + self._notebook.insert_page(_frame, tab_label=_label, position=-1) def __make_look_and_feel_page(self) -> None: """ @@ -380,172 +294,48 @@ def __make_look_and_feel_page(self) -> None: :return: None :rtype: None """ - _tooltips = [ - _("Save the layout format."), - _("Save the look & feel preferences.") - ] - _callbacks = [self._do_request_update, self._do_request_update] - _icons = ['save-layout', 'save'] - _buttonbox = RAMSTKBaseView._make_buttonbox(self, - icons=_icons, - tooltips=_tooltips, - callbacks=_callbacks, - orientation='vertical', - height=-1, - width=-1) - _button = _buttonbox.get_children()[0] - _button.set_property('name', 'format') - _button = _buttonbox.get_children()[1] - _button.set_property('name', 'looknfeel') - - _hbox_outer = Gtk.HBox() - _hbox_inner = Gtk.HBox() - _frame = RAMSTKFrame(label=_("Edit Module View Layout and Colors")) - _frame.add(_hbox_inner) - _fixed = Gtk.Fixed() - _scrollwindow = Gtk.ScrolledWindow() - _hbox_outer.pack_start(_buttonbox, False, True, 0) - _hbox_outer.pack_end(_frame, True, True, 0) - _hbox_inner.pack_start(_fixed, False, True, 0) - _hbox_inner.pack_end(_scrollwindow, True, True, 0) - - _formats = [[_("Allocation"), 'allocation', ''], - [_("(D)FME(C)A"), 'dfmeca', ''], - [_("Functional FMEA"), 'ffmea', ''], - [_("Function"), 'function', ''], - [_("Hardware"), 'hardware', ''], - [_("Hazards"), 'hazard', ''], - [_("Physics of Failure Analysis"), 'pof', ''], - [_("Requirement"), 'requirement', ''], - [_("Revision"), 'revision', ''], - [_("Similar Item Analysis"), 'similaritem', ''], - [_("Stakeholder Input"), 'stakeholder', ''], - [_("Validation"), 'validation', '']] - self.cmbFormatFiles.do_load_combo(_formats, 0, False) - - _label = RAMSTKLabel(_("Select format file to edit:"), width=350) - _fixed.put(_label, 5, 5) - _fixed.put(self.cmbFormatFiles, 310, 5) - _label = RAMSTKLabel(_("Revision Tree Background Color:"), width=350) - _fixed.put(_label, 5, 95) - _fixed.put(self.btnRevisionBGColor, 340, 95) - _label = RAMSTKLabel(_("Revision Tree Foreground Color:"), width=350) - _fixed.put(_label, 5, 125) - _fixed.put(self.btnRevisionFGColor, 340, 125) - _label = RAMSTKLabel(_("Function Tree Background Color:"), width=350) - _fixed.put(_label, 5, 155) - _fixed.put(self.btnFunctionBGColor, 340, 155) - _label = RAMSTKLabel(_("Function Tree Foreground Color:"), width=350) - _fixed.put(_label, 5, 185) - _fixed.put(self.btnFunctionFGColor, 340, 185) - _label = RAMSTKLabel(_("Requirements Tree Background Color:"), - width=350) - _fixed.put(_label, 5, 215) - _fixed.put(self.btnRequirementsBGColor, 340, 215) - _label = RAMSTKLabel(_("Requirements Tree Foreground Color:"), - width=350) - _fixed.put(_label, 5, 245) - _fixed.put(self.btnRequirementsFGColor, 340, 245) - _label = RAMSTKLabel(_("Hardware Tree Background Color:"), width=350) - _fixed.put(_label, 5, 275) - _fixed.put(self.btnHardwareBGColor, 340, 275) - _label = RAMSTKLabel(_("Hardware Tree Foreground Color:"), width=350) - _fixed.put(_label, 5, 305) - _fixed.put(self.btnHardwareFGColor, 340, 305) - # _label = RAMSTKLabel(_(u"Software Tree Background Color:"), width=350) - # _fixed.put(_label, 5, 335) - # _fixed.put(self.btnSoftwareBGColor, 340, 335) - # _label = RAMSTKLabel(_(u"Software Tree Foreground Color:"), width=350) - # _fixed.put(_label, 5, 365) - # _fixed.put(self.btnSoftwareFGColor, 340, 365) - _label = RAMSTKLabel(_("Validation Tree Background Color:"), - width=350) - _fixed.put(_label, 5, 335) - _fixed.put(self.btnValidationBGColor, 340, 335) - _label = RAMSTKLabel(_("Validation Tree Foreground Color:"), width=350) - _fixed.put(_label, 5, 365) - _fixed.put(self.btnValidationFGColor, 340, 365) - # _label = RAMSTKLabel(_(u"Incident Tree Background Color:"), width=350) - # _fixed.put(_label, 5, 455) - # _fixed.put(self.btnIncidentBGColor, 340, 455) - # _label = RAMSTKLabel(_(u"Incident Tree Foreground Color:"), width=350) - # _fixed.put(_label, 5, 485) - # _fixed.put(self.btnIncidentFGColor, 340, 485) - # _label = RAMSTKLabel(_(u"Testing Tree Background Color:"), width=350) - # _fixed.put(_label, 5, 515) - # _fixed.put(self.btnTestingBGColor, 340, 515) - # _label = RAMSTKLabel(_(u"Testing Tree Foreground Color:"), width=350) - # _fixed.put(_label, 5, 545) - # _fixed.put(self.btnTestingFGColor, 340, 545) - - _labels = [ - _("Default\nTitle"), - _("User\nTitle"), - _("Column\nPosition"), - _("Can\nEdit?"), - _("Is\nVisible?") - ] - - self.tvwFormatFile = Gtk.TreeView() - _model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, - GObject.TYPE_INT, GObject.TYPE_INT, - GObject.TYPE_INT, GObject.TYPE_STRING, - GObject.TYPE_STRING, GObject.TYPE_STRING) - self.tvwFormatFile.set_model(_model) - - for i in range(5): - if i == 0: - _cell = Gtk.CellRendererText() - _cell.set_property('background', 'light gray') - _cell.set_property('editable', 0) - _cell.set_property('foreground', '#000000') - _cell.set_property('weight', 700) - _cell.set_property('weight-set', True) - _cell.set_property('wrap-width', 250) - _cell.set_property('wrap-mode', Pango.WrapMode.WORD) - elif i in [1, 2]: - _cell = Gtk.CellRendererText() - _cell.set_property('background', '#FFFFFF') - _cell.set_property('editable', 1) - _cell.set_property('foreground', '#000000') - _cell.set_property('wrap-width', 250) - _cell.set_property('wrap-mode', Pango.WrapMode.WORD) - _cell.connect('edited', self._do_edit_cell, i, _model) - elif i > 4: - _cell = Gtk.CellRendererText() - _cell.set_property('editable', 0) - else: - _cell = Gtk.CellRendererToggle() - _cell.set_property('activatable', 1) - _cell.connect('toggled', self._do_toggle_cell, i, _model) - - _label = Gtk.Label() - _label.set_line_wrap(True) - _label.set_justify(Gtk.Justification.CENTER) - _label.set_alignment(xalign=0.5, yalign=0.5) - _label.set_markup("" + _labels[i] + "") - _label.show_all() - - _column = Gtk.TreeViewColumn() - _column.set_widget(_label) - _column.set_alignment(0.5) - _column.pack_start(_cell, True) - if i < 3: - _column.set_attributes(_cell, text=i) - elif i > 4: - _column.set_visible(False) - else: - _column.set_attributes(_cell, active=i) - - self.tvwFormatFile.append_column(_column) - - _scrollwindow.add(self.tvwFormatFile) - - _label = RAMSTKLabel(_("Look & Feel"), - justify=Gtk.Justification.CENTER) - _label.set_tooltip_text( - _("Allows setting user interface preferences for RAMSTK.")) - self.notebook.insert_page(_hbox_outer, tab_label=_label, position=-1) + _hpaned = Gtk.HPaned() + + _fixed: Gtk.Fixed = Gtk.Fixed() + _scrollwindow: RAMSTKScrolledWindow = RAMSTKScrolledWindow(_fixed) + _frame: RAMSTKFrame = RAMSTKFrame() + _frame.do_set_properties(title="Module View Background & " + "Foreground Colors") + _frame.add(_scrollwindow) + _hpaned.pack1(_frame, True, True) + + # Create and place the labels. Place the associated widget. + _y_pos = 5 + _x_pos, _lst_labels = do_make_label_group(self._lst_labels[10:]) + for _idx, _label in enumerate(_lst_labels): + _minimum: Gtk.Requisition = self._lst_widgets[ + _idx + 10].get_preferred_size()[0] + if _minimum.height == 0: + try: + _minimum.height = self._lst_widgets[_idx + 10].height + except AttributeError: + _minimum.height = 35 + + _fixed.put(_label, 5, _y_pos) + _fixed.put(self._lst_widgets[_idx + 10], _x_pos + 5, _y_pos) + _y_pos += _minimum.height + 5 + + self.__make_format_treeview() + + _scrollwindow: RAMSTKScrolledWindow = RAMSTKScrolledWindow( + self.tvwFormatFile) + _frame: RAMSTKFrame = RAMSTKFrame() + _frame.do_set_properties(title="Module View Column Layout") + _frame.add(_scrollwindow) + _hpaned.pack2(_frame, True, True) + + _label: RAMSTKLabel = RAMSTKLabel(_("Look & Feel")) + _label.do_set_properties( + height=30, + width=-1, + justify=Gtk.Justification.CENTER, + tooltip=_("Allows setting user interface preferences for RAMSTK.")) + self._notebook.insert_page(_hpaned, tab_label=_label, position=-1) def __make_ui(self) -> None: """ @@ -554,20 +344,49 @@ def __make_ui(self) -> None: :return: None :rtype: None """ + _vbox = Gtk.VBox() + _vbox.pack_start(self._notebook, True, True, 0) + self.add(_vbox) + + _scrolledwindow = Gtk.ScrolledWindow() + _scrolledwindow.set_policy(Gtk.PolicyType.NEVER, + Gtk.PolicyType.AUTOMATIC) + _scrolledwindow.add_with_viewport( + do_make_buttonbox(self, + callbacks=[self._lst_callbacks[0]], + icons=[self._lst_icons[0]], + orientation='horizontal', + tooltips=[self._lst_tooltips[0]])) + _vbox.pack_end(_scrolledwindow, False, False, 0) + _n_screens = Gdk.Screen.get_default().get_n_monitors() _width = Gdk.Screen.width() / _n_screens _height = Gdk.Screen.height() - self.set_default_size(_width - 450, (2 * _height / 7)) - self.set_resizable(True) self.set_border_width(5) + self.set_default_size(_width - 450, (4 * _height / 7)) + self.set_modal(True) self.set_position(Gtk.WindowPosition.CENTER) + self.set_resizable(True) + self.set_transient_for(self._parent) + self.__make_general_preferences_page() + self.__make_look_and_feel_page() + + self.show_all() + + def __set_callbacks(self) -> None: + """ + Set the callback functions/methods for each of the widgets. + + :return: None + :rtype: None + """ + # ----- BUTTONS self.btnConfDir.connect('file-set', self._do_select_path, 0) self.btnDataDir.connect('file-set', self._do_select_path, 1) self.btnIconDir.connect('file-set', self._do_select_path, 2) self.btnLogDir.connect('file-set', self._do_select_path, 3) - self.btnProgramDir.connect('file-set', self._do_select_path, 4) self.btnRevisionBGColor.connect('color-set', self._do_set_color, 'revisionbg') @@ -602,45 +421,22 @@ def __make_ui(self) -> None: self.btnTestingFGColor.connect('color-set', self._do_set_color, 'testingfg') - self._lst_handler_id.append( - self.cmbFormatFiles.connect('changed', self._on_combo_changed, 0)) - self._lst_handler_id.append( - self.cmbLists.connect('changed', self._on_combo_changed, 1)) - self._lst_handler_id.append( - self.cmbModuleBookTabPosition.connect('changed', - self._on_combo_changed, 2)) - self._lst_handler_id.append( - self.cmbWorkBookTabPosition.connect('changed', - self._on_combo_changed, 3)) - self._lst_handler_id.append( - self.cmbListBookTabPosition.connect('changed', - self._on_combo_changed, 4)) - self._lst_handler_id.append( - self.cmbReportSize.connect('changed', self._on_combo_changed, 5)) - - _buttonbox = RAMSTKBaseView._make_buttonbox( - self, - icons=['cancel'], - tooltips=[_("Quit the RAMSTK preferences dialog without saving.")], - callbacks=[self._do_quit], - orientation='horizontal', - height=-1, - width=-1) - _buttonbox.set_layout(Gtk.ButtonBoxStyle.END) - - _vbox = Gtk.VBox() - _vbox.pack_start(self.notebook, True, True, 0) - _vbox.pack_end(_buttonbox, False, False, 0) - - self.add(_vbox) - - # if self._mdcRAMSTK.loaded: - # self.__make_active_modules_page() - self.__make_general_preferences_page() - self.__make_look_and_feel_page() - self.__make_global_lists_page() - - self.show_all() + # ----- COMBOBOXES + self.cmbFormatFiles.dic_handler_id[ + 'changed'] = self.cmbFormatFiles.connect('changed', + self._on_combo_changed, 0) + self.cmbModuleBookTabPosition.dic_handler_id[ + 'changed'] = self.cmbModuleBookTabPosition.connect( + 'changed', self._on_combo_changed, 1) + self.cmbWorkBookTabPosition.dic_handler_id[ + 'changed'] = self.cmbWorkBookTabPosition.connect( + 'changed', self._on_combo_changed, 2) + self.cmbListBookTabPosition.dic_handler_id[ + 'changed'] = self.cmbListBookTabPosition.connect( + 'changed', self._on_combo_changed, 3) + self.cmbReportSize.dic_handler_id[ + 'changed'] = self.cmbReportSize.connect('changed', + self._on_combo_changed, 4) def __set_properties(self) -> None: """ @@ -649,16 +445,19 @@ def __set_properties(self) -> None: :return: None :rtype: None """ - self.chkFunctions.do_set_properties(tooltip=_( - "Enables/disables the Function module for this program.")) - self.chkRequirements.do_set_properties(tooltip=_( - "Enables/disables the Requirements module for this program.")) - self.chkHardware.do_set_properties(tooltip=_( - "Enables/disables the Hardware module for this program.")) - self.chkValidation.do_set_properties(tooltip=_( - "Enables/disables the Validation module for this program.")) - self.chkFMEA.do_set_properties(tooltip=_( - "Enables/disables the (D)FME(C)A module for this program.")) + # ----- BUTTONS + self.btnConfDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) + self.btnDataDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) + self.btnIconDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) + self.btnLogDir.set_action(Gtk.FileChooserAction.SELECT_FOLDER) + + # ----- COMBOBOXES + self.cmbFormatFiles.do_set_properties( + tooltip=_("Select the Module View layout to edit.")) + + # ----- ENTRIES + self.txtFRMultiplier.do_set_properties(width=75) + self.txtDecimalPlaces.do_set_properties(width=75) @staticmethod def _do_edit_cell(__cell, path, new_text, position, model) -> None: @@ -666,16 +465,14 @@ def _do_edit_cell(__cell, path, new_text, position, model) -> None: Handle Gtk.CellRenderer() edits. :param __cell: the Gtk.CellRenderer() that was edited. - :type __cell: Gtk.CellRenderer - :param path: the Gtk.TreeView() path of the Gtk.CellRenderer() that was - edited. - :type path: string - :param new_text: the new text in the edited Gtk.CellRenderer(). - :type new_text: string - :param position: the column position of the edited Gtk.CellRenderer(). - :type position: integer + :type __cell: :class:`Gtk.CellRenderer` + :param str path: the Gtk.TreeView() path of the Gtk.CellRenderer() + that was edited. + :param str new_text: the new text in the edited Gtk.CellRenderer(). + :param int position: the column position of the edited + Gtk.CellRenderer(). :param model: the Gtk.TreeModel() the Gtk.CellRenderer() belongs to. - :type model: Gtk.TreeModel + :type model: :class:`Gtk.TreeModel` """ _type = GObject.type_name(model.get_column_type(position)) @@ -686,32 +483,19 @@ def _do_edit_cell(__cell, path, new_text, position, model) -> None: elif _type == 'gfloat': model[path][position] = float(new_text) - def _do_load_format(self, combo) -> None: + def _do_load_format(self, module: str) -> None: """ Load the selected Module View format file for editing. + :param str module: the name of the RAMSTK workstream module whose + Module View layout is to be edited. :return: None :rtype: None """ - _model = combo.get_model() - _row = combo.get_active_iter() - _module = _model.get_value(_row, 1) - self._fmt_file = ( - self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_CONF_DIR + '/layouts/' - + self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_FORMAT_FILE[_module]) - if _module == 'dfmeca': - _fmt_path = "/root/tree[@name='DFMECA']/column" - elif _module == 'ffmea': - _fmt_path = "/root/tree[@name='FFMEA']/column" - elif _module == 'hazard': - _fmt_path = "/root/tree[@name='Hazard']/column" - elif _module == 'pof': - _fmt_path = "/root/tree[@name='PoF']/column" - elif _module == 'similaritem': - _fmt_path = "/root/tree[@name='SimilarItem']/column" - else: - _fmt_path = "/root/tree[@name='" + _module.title() + "']/column" + self.RAMSTK_USER_CONFIGURATION.RAMSTK_CONF_DIR + '/layouts/' + + self.RAMSTK_USER_CONFIGURATION.RAMSTK_FORMAT_FILE[module]) + _fmt_path = "/root/tree[@name='" + module.title() + "']/column" # Retrieve the default heading text from the format file. _path = _fmt_path + '/defaulttitle' @@ -761,92 +545,7 @@ def _do_load_format(self, combo) -> None: ] _model.append(_data) - def _do_load_list(self, combo) -> None: - """ - Load the selected global RAMSTK list for editing. - - :return: None - :rtype: None - """ - _dic_headers = { - 'damaging_conditions': - ['', _("Condition Description"), '', '', ''], - 'load_history': ['', _("History Description"), '', '', ''], - 'measureable_parameters': - ['', _("Parameter Code"), - _("Parameter Description"), '', ''], - 'rpn_detection': ['', - _("Name"), - _("Description"), - _("Value"), ''], - 'rpn_occurrence': - ['', _("Name"), _("Description"), - _("Value"), ''], - 'rpn_severity': ['', - _("Name"), - _("Description"), - _("Value"), ''], - 'workgroups': ['', _("Description"), '', '', ''], - 'users': [ - '', - _("First Name"), - _("Last Name"), - _("User E-Mail"), - _("User Phone") - ] - } - # Retrieve the name of the list to display; this name is the key for - # the dict above. - _model = combo.get_model() - _row = combo.get_active_iter() - _list = _model.get_value(_row, 1) - try: - _headers = _dic_headers[_list] - except KeyError: - _headers = ['', '', '', '', ''] - - # Clear out any existing models and columns. - i = 0 - for _column in self.tvwListEditor.get_columns(): - _label = RAMSTKLabel(_headers[i], - width=-1, - height=-1, - justify=Gtk.Justification.CENTER) - _column.set_widget(_label) - if _headers[i] == '': - _column.set_visible(False) - else: - _column.set_visible(True) - i += 1 - _model = self.tvwListEditor.get_model() - _model.clear() - - i = 0 - _entities = self._site_preferences[_list] - for _entity in _entities: - if _list == 'users': - _data = [ - i, - _entity.get_attributes()['user_fname'], - _entity.get_attributes()['user_lname'], - _entity.get_attributes()['user_email'], - _entity.get_attributes()['user_phone'] - ] - elif _list in ['rpn_detection', 'rpn_occurrence', 'rpn_severity']: - _data = [ - i, - _entity.get_attributes()[1], - _entity.get_attributes()[2], - _entity.get_attributes()[4], '' - ] - else: - _data = [ - i, _entity.get_attributes()['description'], '', '', '' - ] - _model.append(_data) - i += 1 - - def _do_load_page(self, **kwargs) -> None: # pylint: disable=unused-argument + def _do_load_page(self) -> None: """ Load the current preference values. @@ -858,76 +557,62 @@ def _do_load_page(self, **kwargs) -> None: # pylint: disable=unused-argument _positions = {"bottom": 1, "left": 2, "right": 3, "top": 4} _papersize = {'a4': 1, 'letter': 2} - self._site_preferences = self._dtc_data_controller.request_get_preferences( - site=True, user=False) - self._user_preferences = self._dtc_data_controller.request_get_preferences( - site=False, user=True) - - # if self._mdcRAMSTK.loaded: - # self.chkFunctions.set_active(_results[0][1]) - # self.chkRequirements.set_active(_results[0][2]) - # self.chkSoftware.set_active(_results[0][4]) - # self.chkValidation.set_active(_results[0][5]) - # self.chkRG.set_active(_results[0][6]) - # self.chkIncidents.set_active(_results[0][8]) - # self.chkSurvivalAnalysis.set_active(_results[0][10]) - self.cmbModuleBookTabPosition.set_active( - _positions[self._user_preferences['tabpos']['modulebook'].lower()]) - self.cmbWorkBookTabPosition.set_active( - _positions[self._user_preferences['tabpos']['workbook'].lower()]) - self.cmbListBookTabPosition.set_active( - _positions[self._user_preferences['tabpos']['listbook'].lower()]) - self.cmbReportSize.set_active( - _papersize[self._user_preferences['report_size'].lower()]) - - self.txtFRMultiplier.set_text(self._user_preferences['hr_multiplier']) - self.txtDecimalPlaces.set_text(self._user_preferences['decimal']) - self.txtMissionTime.set_text(self._user_preferences['calcreltime']) - - self.btnConfDir.set_current_folder(self._user_preferences['sitedir']) - self.btnDataDir.set_current_folder(self._user_preferences['datadir']) - self.btnIconDir.set_current_folder(self._user_preferences['icondir']) - self.btnLogDir.set_current_folder(self._user_preferences['logdir']) - self.btnProgramDir.set_current_folder( - self._user_preferences['progdir']) - - _color = Gdk.color_parse( - self._user_preferences['colors']['revisionbg']) - self.btnRevisionBGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['revisionfg']) - self.btnRevisionFGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['functionbg']) - self.btnFunctionBGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['functionfg']) - self.btnFunctionFGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['requirementbg']) - self.btnRequirementsBGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['requirementfg']) - self.btnRequirementsFGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['hardwarebg']) - self.btnHardwareBGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['hardwarefg']) - self.btnHardwareFGColor.set_color(_color) - # self.btnSoftwareBGColor.set_color(_color) - # self.btnSoftwareFGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['validationbg']) - self.btnValidationBGColor.set_color(_color) - _color = Gdk.color_parse( - self._user_preferences['colors']['validationfg']) - self.btnValidationFGColor.set_color(_color) - # self.btnIncidentBGColor.set_color(_color) - # self.btnIncidentFGColor.set_color(_color) - # self.btnTestingBGColor.set_color(_color) - # self.btnTestingFGColor.set_color(_color) + _positions[self.RAMSTK_USER_CONFIGURATION. + RAMSTK_TABPOS['modulebook'].lower()]) + self.cmbWorkBookTabPosition.set_active(_positions[ + self.RAMSTK_USER_CONFIGURATION.RAMSTK_TABPOS['workbook'].lower()]) + self.cmbListBookTabPosition.set_active(_positions[ + self.RAMSTK_USER_CONFIGURATION.RAMSTK_TABPOS['listbook'].lower()]) + self.cmbReportSize.set_active(_papersize[ + self.RAMSTK_USER_CONFIGURATION.RAMSTK_REPORT_SIZE.lower()]) + + self.txtFRMultiplier.set_text( + str(self.RAMSTK_USER_CONFIGURATION.RAMSTK_HR_MULTIPLIER)) + self.txtDecimalPlaces.set_text( + str(self.RAMSTK_USER_CONFIGURATION.RAMSTK_DEC_PLACES)) + self.txtMissionTime.set_text( + str(self.RAMSTK_USER_CONFIGURATION.RAMSTK_MTIME)) + + self.btnConfDir.set_current_folder( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_CONF_DIR) + self.btnDataDir.set_current_folder( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_DATA_DIR) + self.btnIconDir.set_current_folder( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR) + self.btnLogDir.set_current_folder( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_LOG_DIR) + + self.btnRevisionBGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['revisionbg'])) + self.btnRevisionFGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['revisionfg'])) + self.btnFunctionBGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['functionbg'])) + self.btnFunctionFGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['functionfg'])) + self.btnRequirementsBGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['requirementbg'])) + self.btnRequirementsFGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['requirementfg'])) + self.btnHardwareBGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['hardwarebg'])) + self.btnHardwareFGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['hardwarefg'])) + self.btnValidationBGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['validationbg'])) + self.btnValidationFGColor.set_color( + Gdk.color_parse( + self.RAMSTK_USER_CONFIGURATION.RAMSTK_COLORS['validationfg'])) def _do_quit(self, __button: Gtk.Button) -> None: """ @@ -940,128 +625,37 @@ def _do_quit(self, __button: Gtk.Button) -> None: """ self.destroy() - def _do_request_list_add(self, __button: Gtk.Button) -> None: + def _do_request_update(self, __button: Gtk.Button) -> None: """ - Add a new item to the global list. + Request to update the user and program preferences. - :param __button: the Gtk.ToolButton() that called this method. - :type __button: :class:`Gtk.ToolButton()` + :param __button: the Gtk.Button() that called this method. + :type __button: :class:`Gtk.Button` :return: None :rtype: None """ - _model = self.cmbLists.get_model() - _row = self.cmbLists.get_active_iter() - _list = _model.get_value(_row, 1) - - _id = len(self._site_preferences[_list]) - _data = [_id, '', '', '', ''] - - _model = self.tvwListEditor.get_model() - _model.append(_data) - - if _list == 'damaging_conditions': - _entity = RAMSTKCondition() - _entity.description = 'New Damaging Operating Condition' - _entity.cond_type = 'operating' - elif _list == 'load_history': - _entity = RAMSTKLoadHistory() - _entity.description = 'New Load History' - elif _list == 'measureable_parameters': - _entity = RAMSTKMeasurement() - _entity.code = 'NMP' - _entity.description = 'New Measureable Parameter' - _entity.measurement_type = 'damage' - elif _list == 'rpn_detection': - _entity = RAMSTKRPN() - _entity.name = 'New RPN Name' - _entity.description = 'New RPN Description' - _entity.rpn_type = 'detection' - elif _list == 'rpn_occurrence': - _entity = RAMSTKRPN() - _entity.name = 'New RPN Name' - _entity.description = 'New RPN Description' - _entity.rpn_type = 'occurrence' - elif _list == 'rpn_severity': - _entity = RAMSTKRPN() - _entity.name = 'New RPN Name' - _entity.description = 'New RPN Description' - _entity.rpn_type = 'severity' - elif _list == 'workgroups': - _entity = RAMSTKGroup() - _entity.description = 'New RAMSTK Workgroup' - _entity.group_type = 'workgroup' - elif _list == 'users': - _entity = RAMSTKUser() - _entity.user_lname = 'New RAMSTK User Last Name' - _entity.user_fname = 'New RAMSTK User First Name' - _entity.user_email = 'new@user' - _entity.user_phane = '867.5309' - - self._site_preferences[_list].append(_entity) - - def _do_request_list_remove(self, __button: Gtk.Button) -> None: - """ - Remove the seleced item from the global list. + _conf_file = self.RAMSTK_USER_CONFIGURATION.RAMSTK_CONF_DIR + \ + '/RAMSTK.toml' + copyfile(_conf_file, _conf_file + '_bak') + self.RAMSTK_USER_CONFIGURATION.set_user_configuration() - :param __button: the Gtk.ToolButton() that called this method. - :type __button: :class:`Gtk.ToolButton()` - :return: None - :rtype: None - """ - _model = self.cmbLists.get_model() - _row = self.cmbLists.get_active_iter() - _list = _model.get_value(_row, 1) - - (_model, _row) = self.tvwListEditor.get_selection().get_selected() - _id = _model.get_value(_row, 0) - - _record = self._site_preferences[_list].pop(_id) - if self._dtc_data_controller.request_do_delete(_record): - _prompt = _("There was an error removing an item from the {0:s} " - "RAMSTK global list.").format(_list) - _icon = self._dic_icons['error'] - _dialog = RAMSTKMessageDialog(_prompt, _icon, 'error', parent=self) - - if _dialog.run() == Gtk.ResponseType.OK: - _dialog.destroy() - else: - self._do_load_list(self.cmbLists) - - def _do_request_update(self, button: Gtk.Button) -> None: + try: + copyfile(self._fmt_file, self._fmt_file + '_bak') + self._do_save_tree_layout() + # This happens when no format file was edited. + except FileNotFoundError: + pass + + def _do_request_update_all(self, button: Gtk.Button) -> None: """ - Request to update the user and program preferences. + Wrapper method for _do_request_update(). :param button: the Gtk.Button() that called this method. :type button: :class:`Gtk.Button` :return: None :rtype: None """ - from shutil import copyfile - - # Make a backup of the original configuration files. - _conf_file = self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_CONF_DIR + '/Site.conf' - copyfile(_conf_file, _conf_file + '_bak') - _conf_file = self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_CONF_DIR + '/RAMSTK.conf' - copyfile(_conf_file, _conf_file + '_bak') - - if button.get_property('name') == 'format': - copyfile(self._fmt_file, self._fmt_file + '_bak') - self._do_save_tree_layout() - elif button.get_property('name') == 'globallists': - self._dtc_data_controller.request_set_preferences( - self._site_preferences, site=True, user=False) - else: - self._dtc_data_controller.request_set_preferences( - self._user_preferences, site=False, user=True) - - if self._dtc_data_controller.request_do_update(): - _prompt = _("There was an error saving user and program " - "preferences.") - _icon = self._dic_icons['error'] - _dialog = RAMSTKMessageDialog(_prompt, _icon, 'error', parent=self) - - if _dialog.run() == Gtk.ResponseType.OK: - _dialog.destroy() + self._do_request_update(button) def _do_save_tree_layout(self) -> None: """ @@ -1083,7 +677,7 @@ def _do_save_tree_layout(self) -> None: _file.write("-*- coding: utf-8 -*-\n\n") _file.write( "{0:s} is part of the RAMSTK Project\n\n".format(_basename)) - _file.write('Copyright 2011-2018 Doyle "weibullguy" Rowland ' + _file.write('Copyright 2011-2020 Doyle "weibullguy" Rowland ' '\n\n') _file.write("All rights reserved.-->\n\n") _file.write("