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

Changing the SVG export to only require height an accept multiple units #1056

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Add Issue to Kanban Board

on:
issues:
types: [opened]

jobs:
add-to-kanban:
runs-on: ubuntu-latest

steps:
- name: Add issue to Kanban board
uses: actions/github-script@0.7.0
with:
script: |
const issueNumber = context.payload.issue.number;
const projectId = '1';
const columnId = '1';
const octokit = new Octokit({ auth: process.env.PAT });
await octokit.projects.createCard({
column_id: columnId,
content_id: issueNumber,
content_type: 'Issue'
});
env:
PAT: ${{ secrets.PAT }}
85 changes: 85 additions & 0 deletions artwork/mag_glass_in.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions artwork/mag_glass_out.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion nion/swift/DisplayPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3066,7 +3066,8 @@ def preview(ui_settings: UISettings.UISettings, display_item: DisplayItem.Displa
display_data_delta.mark_changed()
display_canvas_item.update_display_data_delta(display_data_delta)
with drawing_context.saver():
frame_width, frame_height = width, int(width / display_canvas_item.default_aspect_ratio)
frame_width, frame_height = width, height
display_canvas_item._prepare_render()
display_canvas_item.repaint_immediate(drawing_context, Geometry.IntSize(height=frame_height, width=frame_width))
shape = Geometry.IntSize(height=frame_height, width=frame_width)
return drawing_context, shape
25 changes: 15 additions & 10 deletions nion/swift/DocumentController.py
Original file line number Diff line number Diff line change
Expand Up @@ -3278,7 +3278,8 @@ def execute(self, context: Window.ActionContext) -> Window.ActionResult:
Window.register_action(SetToolModeAction("wedge", _("Wedge"), "wedge_icon.png", _("Wedge tool for creating wedge masks")))
Window.register_action(SetToolModeAction("ring", _("Ring"), "annular_ring.png", _("Ring tool for creating ring masks")))
Window.register_action(SetToolModeAction("lattice", _("Lattice"), "lattice_icon.png", _("Lattice tool for creating periodic lattice masks")))

Window.register_action(SetToolModeAction("zoom-in", _("Zoom In"), "mag_glass_in.png", _("Zoom in on image")))
Window.register_action(SetToolModeAction("zoom-out", _("Zoom Out"), "mag_glass_out.png", _("Zoom out on image")))

class WorkspaceChangeSplits(Window.Action):
# this is for internal testing only. since it requires passing the splitter and splits,
Expand Down Expand Up @@ -3497,15 +3498,19 @@ def execute(self, context: Window.ActionContext) -> Window.ActionResult:
workspace_controller = window.workspace_controller
display_panels = context.display_panels
selected_display_panel = context.selected_display_panel
if workspace_controller and display_panels and selected_display_panel:
h = self.get_int_property(context, "horizontal_count")
v = self.get_int_property(context, "vertical_count")
h = max(1, min(8, h))
v = max(1, min(8, v))
display_panels = workspace_controller.apply_layouts(selected_display_panel, display_panels, h, v)
action_result = Window.ActionResult(Window.ActionStatus.FINISHED)
action_result.results["display_panels"] = list(display_panels)
return action_result
if workspace_controller:
if display_panels and selected_display_panel:
h = self.get_int_property(context, "horizontal_count")
v = self.get_int_property(context, "vertical_count")
h = max(1, min(8, h))
v = max(1, min(8, v))
display_panels = workspace_controller.apply_layouts(selected_display_panel, display_panels, h, v)
action_result = Window.ActionResult(Window.ActionStatus.FINISHED)
action_result.results["display_panels"] = list(display_panels)
return action_result

# no selected panel, cannot split
return Window.ActionResult(Window.ActionStatus.FINISHED)
raise ValueError("Missing workspace controller")

def is_enabled(self, context: Window.ActionContext) -> bool:
Expand Down
37 changes: 29 additions & 8 deletions nion/swift/ExportDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ def __init__(self, display_item: DisplayItem.DisplayItem, display_size: Geometry

self.width_model = Model.PropertyModel(display_size.width)
self.height_model = Model.PropertyModel(display_size.height)

self.int_converter = Converter.IntegerToStringConverter()

self.units = Model.PropertyModel(0)
u = Declarative.DeclarativeUI()

width_row = u.create_row(u.create_label(text=_("Width (in)"), width=80), u.create_line_edit(text="@binding(width_model.value, converter=int_converter)"), spacing=12)
height_row = u.create_row(u.create_label(text=_("Height (in)"), width=80), u.create_line_edit(text="@binding(height_model.value, converter=int_converter)"), spacing=12)
main_page = u.create_column(width_row, height_row, spacing=12, margin=12)
height_row = u.create_row(u.create_label(text=_("Height: "), width=80), u.create_line_edit(text="@binding(height_model.value, converter=int_converter)"),
u.create_combo_box(items=["Inches", "Centimeters","Pixels"],
current_index="@binding(units.value)"), spacing=12)

main_page = u.create_column(height_row, spacing=12, margin=12)
self.ui_view = main_page

def close(self) -> None:
Expand All @@ -233,17 +235,25 @@ def __init__(self, document_controller: DocumentController.DocumentController, d
display_item.display_properties = display_properties

if display_item.display_data_shape and len(display_item.display_data_shape) == 2:
display_size = Geometry.IntSize(height=4, width=4)
display_size = Geometry.IntSize(height=10, width=10)
else:
display_size = Geometry.IntSize(height=3, width=4)

handler = ExportSVGHandler(display_item, display_size)

def ok_clicked() -> bool:
dpi = 96
width_px = (handler.width_model.value or display_size.width) * dpi
height_px = (handler.height_model.value or display_size.height) * dpi
pixels_per_unit: float = 96.0
if handler.units.value ==1:
pixels_per_unit = 37.7953
elif handler.units.value ==2:
pixels_per_unit = 1

display_shape: tuple = display_item.display_data_shape
display_item_ratio = display_shape[1]/display_shape[0]


height_px = int((handler.height_model.value)) * pixels_per_unit
width_px = int(height_px*display_item_ratio)
ui = document_controller.ui
filter = "SVG File (*.svg);;All Files (*.*)"
export_dir = ui.get_persistent_string("export_directory", ui.get_document_location())
Expand All @@ -254,7 +264,18 @@ def ok_clicked() -> bool:
if path:
ui.set_persistent_string("export_directory", selected_directory)
display_shape = Geometry.IntSize(height=height_px, width=width_px)

document_controller.export_svg_file(DisplayPanel.DisplayPanelUISettings(ui), display_item, display_shape, pathlib.Path(path))

drawing_context, shape = DisplayPanel.preview(DisplayPanel.DisplayPanelUISettings(ui), display_item, display_shape.width, display_shape.height)
view_box = Geometry.IntRect(Geometry.IntPoint(), shape)

svg = drawing_context.to_svg(shape, view_box)

with Utility.AtomicFileWriter(pathlib.Path(path)) as fp:
fp.write(svg)


return True

def cancel_clicked() -> bool:
Expand Down
Loading
Loading