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

Contents of /branches/WIP-pyshapelib-bramz/Extensions/mouseposition/mouseposition.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2734 - (show annotations)
Thu Mar 1 12:42:59 2007 UTC (18 years ago) by bramz
File MIME type: text/x-python
File size: 4160 byte(s)
made a copy
1 # Copyright (C) 2005 by Intevation GmbH
2 # Authors:
3 # Frank Koormann <[email protected]> (2005)
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 """
9 xtend thuban with a locator tool.
10
11 Collect positions of mouse clicks (in map coordinates) in a text control.
12
13 The tool was implemented in the need to collect some coordinates for some
14 work (outside Thuban). The status bar display of the coordinates is quite
15 transient (each mouse movement changes it) and cannot be copied. The tool let
16 one simply collect the coordinates needed and copy them in one block later.
17 """
18
19 __version__ = '$Revision$'
20 # $Source$
21 # $Id$
22
23 import os, sys
24 import string
25
26 import wx
27 from wx.lib.layoutf import Layoutf
28
29 from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
30 from Thuban.UI.command import registry, ToolCommand
31 from Thuban.UI.mainwindow import main_menu, main_toolbar, \
32 make_check_current_tool
33 from Thuban.UI.viewport import Tool
34 from Thuban.UI.dialogs import NonModalDialog
35 from Thuban import _
36
37 import Thuban
38
39 class DynamicMessageDialog(NonModalDialog):
40 """Similar to the wx.ScrolledMessageDialog, contents dynamically
41 changeable by calling applications.
42
43 """
44 def __init__(self, parent, msg, name, caption, pos = wx.DefaultPosition):
45 NonModalDialog.__init__(self, parent, name, caption)
46 x, y = pos
47 if x == -1 and y == -1:
48 self.CenterOnScreen(wx.BOTH)
49 text = wx.TextCtrl(self, -1, msg, wx.DefaultPosition,
50 wx.DefaultSize,
51 wx.TE_MULTILINE | wx.TE_READONLY)
52 ok = wx.Button(self, wx.ID_OK, "OK")
53 text.SetConstraints(Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok)))
54 ok.SetConstraints(Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self,)))
55 wx.EVT_BUTTON(self, wx.ID_OK, self.OnClose)
56 self.text = text
57 self.SetAutoLayout(1)
58 self.Layout()
59
60 def getText(self):
61 return self.text.GetValue()
62
63 def setText(self, text):
64 self.text.SetValue(text)
65
66 def appendText(self, text):
67 self.text.AppendText(text)
68
69 class MousePositionTool(Tool):
70
71 def __init__(self, view, context):
72 Tool.__init__(self, view)
73 self.context = context
74 self.dlg = None
75
76 def Name(self):
77 return "MousePositionTool"
78
79 def MouseDown(self, event):
80 map_proj = self.view.Map().GetProjection()
81 pos = self.view.CurrentPosition()
82 if pos is not None:
83 pMsg = "%10.10g, %10.10g\n" % pos
84 name = "extension_mouse_position"
85
86 dialog = self.context.mainwindow.get_open_dialog(name)
87 if dialog is None:
88 dialog = DynamicMessageDialog(self.context.mainwindow,
89 pMsg, name, _("Mouse Position Tool"))
90 self.context.mainwindow.add_dialog(name, dialog)
91 dialog.Show(True)
92 else:
93 dialog.appendText(pMsg)
94 dialog.Raise()
95
96 def mouse_position_tool(context):
97 canvas = context.mainwindow.canvas
98 canvas.SelectTool(MousePositionTool(canvas, context))
99
100
101 # locator executed as an tool/extension to Thuban
102 iconfile = os.path.join(os.path.abspath(Thuban.__path__[0]),
103 "..", "Resources", "Bitmaps", "identify")
104 iconfile = os.path.join(os.path.abspath(os.path.dirname(__file__)),
105 'position')
106 registry.Add(ToolCommand("mouse_position_tool", "Mouse Position Tool",
107 mouse_position_tool, icon = iconfile,
108 helptext = "Collect mouse click coordinates in a dialog",
109 checked = make_check_current_tool("MousePositionTool")))
110
111 # Add the command to the toolbar
112 main_toolbar.InsertSeparator()
113 main_toolbar.InsertItem("mouse_position_tool")
114
115 # find the extensions menu (create it anew if not found)
116 extensions_menu = main_menu.FindOrInsertMenu('extensions', _('E&xtensions'))
117
118 # finally add the new entry to the extensions menu
119 extensions_menu.InsertItem('mouse_position_tool')

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26