/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/svgexport/svgsaver.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Extensions/svgexport/svgsaver.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2482 - (hide annotations)
Sat Dec 18 02:36:59 2004 UTC (20 years, 2 months ago) by bernhard
Original Path: trunk/thuban/Extensions/svgexport/svgsaver.py
File MIME type: text/x-python
File size: 3522 byte(s)
	svgexport 1.0.0: Treats holes and islands nicely. Documentation added.

	* Extensions/svgexport/test/test_svgmapwriter.py:
	Added new tests: test_export_polygon_with_hole()
	and test_polygon_with_hole().

	* Extensions/svgexport/svgmapwriter.py
	(draw_polygon_shape()): Uses DrawPath correctly now.

	* Doc/manual/thuban-manual.xml: Added documentation for stable
	extention svgexport.
	* Doc/manual/thuban-manual-de.xml: Copied English section about
	svexport over.

 	* Extensions/svgexport/__init__.py: Bumped version number to 1.0.0.

	* Extensions/svgexport/svgsaver.py,maplegend.py:
	Moved from experimental to stable extension menu.

	* Extensions/svgexport/TODO: updated.

1 jan 2398 # Copyright (c) 2004 by Intevation GmbH
2 bh 2074 # Authors:
3 jan 2398 # Markus Rechtien <[email protected]> (2004)
4     # Bernhard Herzog <[email protected]> (2004)
5     # Bernhard Reiter <[email protected]> (2004)
6     # Jan-Oliver Wagner <[email protected]> (2004)
7 bh 2074 #
8     # This program is free software under the GPL (>=v2)
9     # Read the file COPYING coming with Thuban for details.
10    
11     __version__ = "$Revision$"
12     # $Source$
13     # $Id$
14    
15    
16     """
17     Classes to write a session in SVG format
18     """
19    
20    
21     # Needed wx-toolkit classes
22 bernhard 2344 from wxPython.wx import wxFileDialog, wxSAVE, wxOVERWRITE_PROMPT, wxID_OK, \
23     wxOK, wxICON_HAND
24 bh 2074
25     # We need os.path
26     import os
27    
28     # use _() already now for all strings that may later be translated
29     from Thuban import _
30    
31     # Import SVG related classes
32 bernhard 2344 from svgmapwriter import VirtualDC, SVGRenderer, SVGMapWriterError
33 bh 2074
34    
35     def write_to_svg(context):
36 bernhard 2388 '''Export data depending on the set properties.
37    
38     This is the main export funcation.
39 bh 2074 '''
40     canvas = context.mainwindow.canvas
41     file = None
42     map = canvas.Map()
43    
44     if hasattr(canvas, "export_path"):
45     export_path = canvas.export_path
46     else:
47     export_path="."
48     # Get the file the session shall be written to
49     dlg = wxFileDialog(canvas, _("Write SVG"), export_path, "",
50     "Scalable Vector Graphics (*.svg)|*.svg",
51     wxSAVE|wxOVERWRITE_PROMPT)
52    
53     response = dlg.ShowModal()
54     if response == wxID_OK:
55     file = dlg.GetPath()
56     else: # Do nothing if choice was interrupted.
57     return 0
58    
59     # If the user selected a file
60     if file and map is not None:
61     canvas.export_path = os.path.dirname(file)
62     # Initialize some dimensions and calculate the map bounds
63     width, height = canvas.GetSizeTuple()
64     llx, lly = canvas.win_to_proj(0, height)
65     urx, ury = canvas.win_to_proj(width, 0)
66     mapwidth, mapheight = ((urx - llx), (ury - lly))
67     mapregion = (llx, lly, mapwidth, mapheight)
68    
69     # Get all selected layers and shapes that should be written as SVG
70     selected_layer = canvas.selection.SelectedLayer()
71     selected_shapes = canvas.selection.SelectedShapes()
72 bernhard 2344 try:
73     dc = VirtualDC(file, (mapwidth, mapheight, ))
74     dc.BeginExport()
75     # map scale offset region
76     renderer = SVGRenderer(dc, map, 1.0, (0 - min(llx, urx),
77     0 + max(lly, ury)), mapregion)
78     # Render the map
79     renderer.RenderMap(selected_layer, selected_shapes)
80     dc.EndExport()
81     except SVGMapWriterError, inst:
82     context.mainwindow.RunMessageBox(_("Error: SVG not written!"),
83     text=_("Could not write SVG because: ")+ str(inst),
84     flags= wxOK | wxICON_HAND)
85     # delete partly writting file
86     os.remove(file)
87 bh 2074
88    
89 bernhard 2344
90 bh 2074 # Thuban has named commands which can be registered in the central
91     # instance registry.
92     from Thuban.UI.command import registry, Command
93    
94     # The instance of the main menu of the Thuban application
95     # See Thuban/UI/menu.py for the API of the Menu class
96     from Thuban.UI.mainwindow import main_menu
97    
98     # create a new command and register it
99     registry.Add(Command('write_to_svg', _('Write SVG Map'), write_to_svg,
100     helptext = _('Export the a map into a SVG file')))
101    
102 bernhard 2482 # find the menu we want to be in (create it anew if not found)
103     menu = main_menu.FindOrInsertMenu('extensions', _('E&xtensions'))
104 jan 2208
105 bh 2074 # finally bind the new command with an entry in the extensions menu
106 bernhard 2482 menu.InsertItem('write_to_svg')

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26