Skip to content

Commit

Permalink
both widgets added and yaml file correctly updated when leaving the a…
Browse files Browse the repository at this point in the history
…pplication. this refs #7 #8
  • Loading branch information
JeanBilheux committed Aug 23, 2022
1 parent 923407e commit 72d5bed
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
45 changes: 40 additions & 5 deletions rockit_autoreconstruction_ui/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from qtpy.QtWidgets import QApplication, QMainWindow
import sys
import numpy as np
import os
import logging
import warnings
from enum import Enum
import yaml
Expand All @@ -14,7 +14,7 @@
from .utilities.status_message_config import StatusMessageStatus, show_status_message
from .history import History

DEBUG = False
DEBUG = True
AUTOREDUCE_CONFIG_FILE_NAME = "autoreduce_cg1d_config.yaml"


Expand Down Expand Up @@ -47,7 +47,7 @@ def initialize(self):
if status == Status.error:
return

status = self.read_yaml()
status = self.read_yaml_and_set_widgets()
if status == Status.error:
return

Expand Down Expand Up @@ -98,7 +98,13 @@ def initialize_widgets(self):
self.automatic_open_beam_checkBox_changed(self.ui.ob_checkBox.isChecked())
self.ob_radioButton_changed()

def read_yaml(self):
# ring removal algorithm
self.ui.ring_removal_algorithm_comboBox.addItems(self.removal_ring_list_algorithm)
self.ui.ring_removal_algorithm_comboBox.setCurrentIndex(self.removal_ring_algorithm_current_index)
self.ui.ring_removal_algorithm_checkBox.setChecked(self.removal_ring_mode)
self.ring_removal_algorithm_checkBox_changed(self.removal_ring_mode)

def read_yaml_and_set_widgets(self):
file_name = self.autoreduce_config_file
with open(file_name, "r") as stream:
yaml_data = yaml.safe_load(stream)
Expand Down Expand Up @@ -182,6 +188,24 @@ def read_yaml(self):
except KeyError:
self.automatic_edge_cropping = True

# removal ring artifact algorithms
try:
self.removal_ring_list_algorithm = yaml_data['ring_removal']['list_algorithm']
except KeyError:
self.removal_ring_list_algorithm = ["Vos", "bm3d"]

try:
self.removal_ring_mode = yaml_data['ring_removal']['mode']
except KeyError:
self.removal_ring_mode = True

try:
self.removal_ring_algorithm = yaml_data['ring_removal']['algorithm']
except KeyError:
self.removal_ring_algorithm = "Vos"

self.removal_ring_algorithm_current_index = self.removal_ring_list_algorithm.index(self.removal_ring_algorithm)

return Status.ok

def initialize_statusbar(self):
Expand Down Expand Up @@ -309,6 +333,12 @@ def ok_clicked(self):
ob_max_number_of_files = self.ui.maximum_number_of_ob_spinBox.value()
ob_use_max_number_of_files = self.ui.maximum_number_of_ob_radioButton.isChecked()
automatic_edge_cropping = self.ui.automatic_edge_cropping_checkBox.isChecked()
ring_removal_flag = self.ui.ring_removal_algorithm_checkBox.isChecked()
ring_removal_algorithm = self.ui.ring_removal_algorithm_comboBox.currentText()

ring_removal_list_algorithm = []
for _row in np.arange(self.ui.ring_removal_algorithm_comboBox.count()):
ring_removal_list_algorithm.append(self.ui.ring_removal_algorithm_comboBox.itemText(_row))

yaml_data = {'DataPath':
{'ipts': ipts_number,
Expand All @@ -331,7 +361,12 @@ def ok_clicked(self):
},
'edge_cropping': {
'automatic': automatic_edge_cropping,
}
},
'ring_removal': {
'mode': ring_removal_flag,
'algorithm': ring_removal_algorithm,
'list_algorithm': ring_removal_list_algorithm,
},
}
with io.open(self.autoreduce_config_file, 'w') as outfile:
yaml.dump(yaml_data, outfile, default_flow_style=False, allow_unicode=True)
Expand Down
13 changes: 1 addition & 12 deletions rockit_autoreconstruction_ui/ui/mainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -563,18 +563,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="ring_removal_algorithm_comboBox">
<item>
<property name="text">
<string>Vo's</string>
</property>
</item>
<item>
<property name="text">
<string>bm3d</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="ring_removal_algorithm_comboBox"/>
</item>
<item>
<spacer name="horizontalSpacer_14">
Expand Down

0 comments on commit 72d5bed

Please sign in to comment.