/[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 2208 - (hide annotations)
Sun May 16 09:33:04 2004 UTC (20 years, 9 months ago) by jan
Original Path: trunk/thuban/Extensions/svgexport/svgsaver.py
File MIME type: text/x-python
File size: 3021 byte(s)
Use FindOrInsertMenu() instead of finding menu on its own.

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