Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistence for unit values in SVG #1144

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions nion/swift/ExportDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,18 @@ class UnitType(enum.Enum):


class ExportSizeModel(Observable.Observable):
def __init__(self, display_item: DisplayItem.DisplayItem) -> None:
def __init__(self, display_item: DisplayItem.DisplayItem, ui: UserInterface.UserInterface) -> None:
super().__init__()
self.ui = ui
display_size = self.__calculate_display_size_in_pixels(display_item)
self.__width = display_size.width
self.__height = display_size.height
self.__aspect_ratio = self.__width / self.__height
self.__units = UnitType.PIXELS
self.__float_to_string_converter = Converter.FloatToStringConverter()
self.__primary_field = 'width' # Primary field to determine which text is calculated
self.__primary_field = 'width' # Primary field to determine which text is calculater
# Load the persisted units value, default to PIXELS if not found
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Load the persisted units value, default to PIXELS if not found

This comment is outdated and can be removed. The default value is set by the caller.

persisted_units = self.ui.get_persistent_string("export_units", UnitType.PIXELS.name)
self.__units = UnitType[persisted_units]

def __calculate_display_size_in_pixels(self, display_item: DisplayItem.DisplayItem) -> Geometry.IntSize:
if display_item.display_data_shape and len(display_item.display_data_shape) == 2:
Expand Down Expand Up @@ -327,6 +330,7 @@ def units(self, new_units: int) -> None:
new_enum = UnitType(new_units)
if self.__units != new_enum:
self.__units = new_enum
self.ui.set_persistent_string("export_units", self.__units.name)
self.notify_property_changed("width")
self.notify_property_changed("height")
self.notify_property_changed("width_text")
Expand Down Expand Up @@ -391,7 +395,7 @@ def __init__(self, document_controller: DocumentController.DocumentController,
super().__init__()
self.__document_controller = document_controller
self.__display_item = display_item
self.__model = ExportSizeModel(display_item)
self.__model = ExportSizeModel(display_item, document_controller.ui)
lisham2000 marked this conversation as resolved.
Show resolved Hide resolved
self.__handler = ExportSVGHandler(self.__model)
self.__init_ui()

Expand Down