1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import os.path
20
21 import wx
22
23 from timelinelib.wxgui.utils import _ask_question
24 from timelinelib.wxgui.utils import WildcardHelper
25 from timelinelib.wxgui.utils import display_warning_message
26 from timelinelib.plugin.pluginbase import PluginBase
27 from timelinelib.plugin.factory import EXPORTER
28
29
31
34
36 return _("Export Current view to Image...")
37
41
42 - def run(self, main_frame):
44
45
47
50
52 return _("Export Whole Timeline to Images...")
53
57
58 - def run(self, main_frame):
60
61
66
67
69 path = get_image_path(main_frame)
70 if path is not None:
71 try:
72 periods, current_period = main_frame.get_export_periods()
73 except ValueError:
74 msg = _("The first image contains a Julian day < 0\n\nNavigate to first event or\nUse the feature 'Accept negative Julian days'")
75 display_warning_message(msg)
76 return
77 view_properties = main_frame.main_panel.timeline_panel.timeline_canvas.controller.view_properties
78 view_properties.set_use_fixed_event_vertical_pos(True)
79 path_without_extension, extension = path.rsplit(".", 1)
80 view_properties.set_use_fixed_event_vertical_pos(True)
81 view_properties.periods = periods
82 count = 1
83 paths = []
84 for period in periods:
85 path = "%s_%d.%s" % (path_without_extension, count, extension)
86 if overwrite_existing_path(main_frame, path):
87 main_frame.main_panel.timeline_panel.timeline_canvas.Navigate(lambda tp: period)
88 main_frame.main_panel.timeline_panel.timeline_canvas.SaveAsPng(path)
89 count += 1
90 paths.append(path)
91 view_properties.set_use_fixed_event_vertical_pos(False)
92 main_frame.main_panel.timeline_panel.timeline_canvas.Navigate(lambda tp: current_period)
93 merged_image_path = "%s_merged.%s" % (path_without_extension, extension)
94 merge_images(paths, merged_image_path)
95
96
98 path = None
99 file_info = _("Image files")
100 file_types = [("png", wx.BITMAP_TYPE_PNG)]
101 images_wildcard_helper = WildcardHelper(file_info, file_types)
102 wildcard = images_wildcard_helper.wildcard_string()
103 dialog = wx.FileDialog(main_frame, message=_("Export to Image"), wildcard=wildcard, style=wx.FD_SAVE)
104 if dialog.ShowModal() == wx.ID_OK:
105 path = images_wildcard_helper.get_path(dialog)
106 dialog.Destroy()
107 return path
108
109
111 if os.path.exists(path):
112 overwrite_question = _("File '%s' exists. Overwrite?") % path
113 return _ask_question(overwrite_question, main_frame) == wx.YES
114 return True
115
116
118 from PIL import Image
119 images = map(Image.open, images_paths)
120 widths, heights = zip(*(i.size for i in images))
121 total_width = sum(widths)
122 max_height = max(heights)
123 new_image = Image.new('RGB', (total_width, max_height))
124 x_offset = 0
125 for image in images:
126 new_image.paste(image, (x_offset, 0))
127 x_offset += image.size[0]
128 new_image.save(merged_image_path)
129