Skip to content

Commit

Permalink
Add User Preferences for Load Marker UI options.
Browse files Browse the repository at this point in the history
The Distortion Mode, Use (Embedded) Overscan and Load
Bundle Positions default values can be controlled by the
User Preferences window.
  • Loading branch information
david-cattermole committed Oct 9, 2023
1 parent 1ef13af commit 104baed
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 16 deletions.
10 changes: 5 additions & 5 deletions python/mmSolver/tools/loadmarker/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
Contains constant values for the Load Marker tool.
"""

import mmSolver.tools.userpreferences.constant as userprefs_const


CONFIG_FILE_NAME = "tools_loadmarker.json"

WINDOW_TITLE = 'Load Markers - mmSolver'
Expand Down Expand Up @@ -52,12 +55,9 @@
NEW_MARKER_GROUP_VALUE = '<Create New>'
NEW_COLLECTION_VALUE = '<Create New>'

DISTORTION_MODE_VALUE = 'Distorted'
UNDISTORTION_MODE_VALUE = 'Undistorted'
DISTORTION_MODE_VALUE = userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_LABEL
UNDISTORTION_MODE_VALUE = userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_LABEL


# Default values
LOAD_MODE_DEFAULT_VALUE = LOAD_MODE_NEW_VALUE
DISTORTION_MODE_DEFAULT_VALUE = UNDISTORTION_MODE_VALUE
LOAD_BUNDLE_POS_DEFAULT_VALUE = True
USE_OVERSCAN_DEFAULT_VALUE = True
46 changes: 37 additions & 9 deletions python/mmSolver/tools/loadmarker/ui/loadmarker_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ def get_user_prefs_add_marker_to_collection():
return value != userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_NONE_VALUE


def get_user_prefs_distortion_mode_default():
config = userprefs_lib.get_config()
key = userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY
value = userprefs_lib.get_value(config, key)
result = None
if value == userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_VALUE:
result = userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_LABEL
elif value == userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_VALUE:
result = userprefs_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_LABEL
return result


def get_user_prefs_use_overscan_default():
config = userprefs_lib.get_config()
key = userprefs_const.LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY
value = userprefs_lib.get_value(config, key)
return value == userprefs_const.LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TRUE_VALUE


def get_user_prefs_load_bundle_positions_default():
config = userprefs_lib.get_config()
key = userprefs_const.LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY
value = userprefs_lib.get_value(config, key)
return value == userprefs_const.LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TRUE_VALUE


class LoadMarkerLayout(QtWidgets.QWidget, ui_loadmarker_layout.Ui_Form):
def __init__(self, parent=None, *args, **kwargs):
super(LoadMarkerLayout, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -143,9 +169,8 @@ def populateUi(self):

self.fileInfo_plainTextEdit.setReadOnly(True)

value = get_config_value(
config, 'data/load_bundle_position', const.LOAD_BUNDLE_POS_DEFAULT_VALUE
)
default_value = get_user_prefs_load_bundle_positions_default()
value = get_config_value(config, 'data/load_bundle_position', default_value)
self.loadBndPositions_checkBox.setChecked(value)

# Get the file path from the clipboard.
Expand Down Expand Up @@ -197,16 +222,19 @@ def populateUi(self):
index = self.loadMode_model.stringList().index(value)
self.loadMode_comboBox.setCurrentIndex(index)

value = get_config_value(
config, "data/distortion_mode", const.DISTORTION_MODE_DEFAULT_VALUE
)
default_value = get_user_prefs_distortion_mode_default()
value = get_config_value(config, "data/distortion_mode", default_value)
self.populateDistortionModeModel(self.distortionMode_model)
index = self.distortionMode_model.stringList().index(value)
self.distortionMode_comboBox.setCurrentIndex(index)

value = get_config_value(
config, 'data/use_overscan', const.USE_OVERSCAN_DEFAULT_VALUE
)
default_value = get_user_prefs_use_overscan_default()
value = get_config_value(config, 'data/use_overscan', default_value)
self.overscan_checkBox.setChecked(value)
self.updateOverscanValues()

default_value = get_user_prefs_load_bundle_positions_default()
value = get_config_value(config, 'data/load_bundle_positions', default_value)
self.overscan_checkBox.setChecked(value)
self.updateOverscanValues()
return
Expand Down
63 changes: 63 additions & 0 deletions python/mmSolver/tools/userpreferences/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,57 @@
]


# "Load Marker UI - Distortion Mode Default" preference.
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY = 'load_marker_ui/distortion_mode_default'
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_TYPE = TYPE_ENUMERATION_INT
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_VALUE = 1
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_LABEL = 'Undistorted'
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_VALUE = 0
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_LABEL = 'Distorted'
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_VALUES = [
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_VALUE,
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_VALUE,
]
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_LABELS = [
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_LABEL,
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_DISTORT_LABEL,
]


# "Load Marker UI - Use Overscan Default" preference.
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY = 'load_marker_ui/use_overscan_default'
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TYPE = TYPE_ENUMERATION_INT
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TRUE_VALUE = 1
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TRUE_LABEL = 'Yes'
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_FALSE_VALUE = 0
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_FALSE_LABEL = 'No'
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_VALUES = [
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TRUE_VALUE,
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_FALSE_VALUE,
]
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_LABELS = [
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TRUE_LABEL,
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_FALSE_LABEL,
]


# "Load Marker UI - Load Bundle Positions Default" preference.
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY = 'load_marker_ui/load_bundle_positions_default'
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TYPE = TYPE_ENUMERATION_INT
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TRUE_VALUE = 1
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TRUE_LABEL = 'Yes'
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_FALSE_VALUE = 0
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_FALSE_LABEL = 'No'
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_VALUES = [
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TRUE_VALUE,
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_FALSE_VALUE,
]
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_LABELS = [
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TRUE_LABEL,
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_FALSE_LABEL,
]


# "Solver UI - Validate on open" preference.
#
# This option is deprecated and is not used.
Expand Down Expand Up @@ -159,6 +210,9 @@
VALUES_MAP = {
REG_EVNT_ADD_NEW_MKR_TO_KEY: REG_EVNT_ADD_NEW_MKR_TO_VALUES,
REG_EVNT_ADD_NEW_LINE_TO_KEY: REG_EVNT_ADD_NEW_LINE_TO_VALUES,
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY: LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_VALUES,
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY: LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_VALUES,
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY: LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_VALUES,
SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY: SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_VALUES,
CREATE_CONTROLLER_SHAPE_KEY: CREATE_CONTROLLER_SHAPE_VALUES,
}
Expand All @@ -168,6 +222,9 @@
LABELS_MAP = {
REG_EVNT_ADD_NEW_MKR_TO_KEY: REG_EVNT_ADD_NEW_MKR_TO_LABELS,
REG_EVNT_ADD_NEW_LINE_TO_KEY: REG_EVNT_ADD_NEW_LINE_TO_LABELS,
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY: LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_LABELS,
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY: LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_LABELS,
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY: LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_LABELS,
SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY: SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_LABELS,
CREATE_CONTROLLER_SHAPE_KEY: CREATE_CONTROLLER_SHAPE_LABELS,
}
Expand All @@ -177,6 +234,9 @@
DEFAULT_VALUE_MAP = {
REG_EVNT_ADD_NEW_MKR_TO_KEY: REG_EVNT_ADD_NEW_MKR_TO_ACTIVE_COL_VALUE,
REG_EVNT_ADD_NEW_LINE_TO_KEY: REG_EVNT_ADD_NEW_LINE_TO_ACTIVE_COL_VALUE,
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY: LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_UNDISTORT_VALUE,
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY: LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TRUE_VALUE,
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY: LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TRUE_VALUE,
SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY: SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_TRUE_VALUE,
CREATE_CONTROLLER_SHAPE_KEY: CREATE_CONTROLLER_SHAPE_LOCATOR_VALUE,
}
Expand All @@ -186,6 +246,9 @@
VALUE_TYPE_MAP = {
REG_EVNT_ADD_NEW_MKR_TO_KEY: REG_EVNT_ADD_NEW_MKR_TO_TYPE,
REG_EVNT_ADD_NEW_LINE_TO_KEY: REG_EVNT_ADD_NEW_LINE_TO_TYPE,
LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY: LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_TYPE,
LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY: LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_TYPE,
LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY: LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_TYPE,
SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY: SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_TYPE,
CREATE_CONTROLLER_SHAPE_KEY: CREATE_CONTROLLER_SHAPE_TYPE,
}
Expand Down
54 changes: 54 additions & 0 deletions python/mmSolver/tools/userprefswindow/ui/pref_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def populateUI(self, config):
self.updateAddNewMarkersToWidget(config)
self.updateAddNewLinesToWidget(config)
self.updateSolverUIMinimalUIWhileSolvingWidget(config)
self.updateLoadMarkerUIDistortionModeDefaultWidget(config)
self.updateLoadMarkerUIUseOverscanDefaultWidget(config)
self.updateLoadMarkerUILoadBundlePositionsDefaultWidget(config)

# Deprecated options, kept for backwards compatibility, but
# they are hidden by default anyway.
Expand Down Expand Up @@ -101,6 +104,57 @@ def getAddNewLinesToConfigValue(self):
value = userprefs_lib.get_value_from_label(key, label)
return value

def updateLoadMarkerUIDistortionModeDefaultWidget(self, config):
key = pref_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY
value = userprefs_lib.get_value(config, key)
label = userprefs_lib.get_label_from_value(key, value)
assert isinstance(label, pycompat.TEXT_TYPE)
labels = userprefs_lib.get_labels(key)
self.distortionModeDefaultComboBox.clear()
self.distortionModeDefaultComboBox.addItems(labels)
self.distortionModeDefaultComboBox.setCurrentText(label)
return

def getLoadMarkerUIDistortionModeDefaultConfigValue(self):
key = pref_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY
label = self.distortionModeDefaultComboBox.currentText()
value = userprefs_lib.get_value_from_label(key, label)
return value

def updateLoadMarkerUIUseOverscanDefaultWidget(self, config):
key = pref_const.LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY
value = userprefs_lib.get_value(config, key)
label = userprefs_lib.get_label_from_value(key, value)
assert isinstance(label, pycompat.TEXT_TYPE)
labels = userprefs_lib.get_labels(key)
self.useOverscanDefaultComboBox.clear()
self.useOverscanDefaultComboBox.addItems(labels)
self.useOverscanDefaultComboBox.setCurrentText(label)
return

def getLoadMarkerUIUseOverscanDefaultConfigValue(self):
key = pref_const.LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY
label = self.useOverscanDefaultComboBox.currentText()
value = userprefs_lib.get_value_from_label(key, label)
return value

def updateLoadMarkerUILoadBundlePositionsDefaultWidget(self, config):
key = pref_const.LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY
value = userprefs_lib.get_value(config, key)
label = userprefs_lib.get_label_from_value(key, value)
assert isinstance(label, pycompat.TEXT_TYPE)
labels = userprefs_lib.get_labels(key)
self.loadBundlePositionsDefaultComboBox.clear()
self.loadBundlePositionsDefaultComboBox.addItems(labels)
self.loadBundlePositionsDefaultComboBox.setCurrentText(label)
return

def getLoadMarkerUILoadBundlePositionsDefaultConfigValue(self):
key = pref_const.LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY
label = self.loadBundlePositionsDefaultComboBox.currentText()
value = userprefs_lib.get_value_from_label(key, label)
return value

def updateSolverUIValidateOnOpenWidget(self, config):
# This feature is deprecated and is no longer allowed.
return
Expand Down
47 changes: 45 additions & 2 deletions python/mmSolver/tools/userprefswindow/ui/pref_layout.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>428</height>
<width>1144</width>
<height>826</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -70,6 +70,49 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="loadMarkerUI_groupBox">
<property name="title">
<string>Load Marker UI Preferences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QFormLayout" name="loadMarkerUI_formLayout">
<item row="1" column="0">
<widget class="QLabel" name="useOverscanDefaultLabel">
<property name="text">
<string>Use Embedded Overscan Default:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="useOverscanDefaultComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="loadBundlePositionsDefaultLabel">
<property name="text">
<string>Load Bundle Positions Default:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="loadBundlePositionsDefaultComboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="distortionModeDefaultLabel">
<property name="text">
<string>Distortion Mode Default:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="distortionModeDefaultComboBox"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="deprecated_groupBox">
<property name="title">
Expand Down
12 changes: 12 additions & 0 deletions python/mmSolver/tools/userprefswindow/ui/pref_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ def save_prefs(self):
pref_const.REG_EVNT_ADD_NEW_LINE_TO_KEY,
self.subForm.getAddNewLinesToConfigValue,
),
(
pref_const.LOAD_MARKER_UI_DISTORTION_MODE_DEFAULT_KEY,
self.subForm.getLoadMarkerUIDistortionModeDefaultConfigValue,
),
(
pref_const.LOAD_MARKER_UI_USE_OVERSCAN_DEFAULT_KEY,
self.subForm.getLoadMarkerUIUseOverscanDefaultConfigValue,
),
(
pref_const.LOAD_MARKER_UI_LOAD_BUNDLE_POSITIONS_DEFAULT_KEY,
self.subForm.getLoadMarkerUILoadBundlePositionsDefaultConfigValue,
),
(
pref_const.SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY,
self.subForm.getSolverUIMinimalUIWhileSolvingConfigValue,
Expand Down

0 comments on commit 104baed

Please sign in to comment.