frank: thuban/Extensions/mouseposition __init__.py, NONE, 1.1 mouseposition.py, NONE, 1.1 position.xpm, NONE, 1.1
cvs@intevation.de
cvs at intevation.de
Tue Jan 18 11:19:04 CET 2005
Author: frank
Update of /thubanrepository/thuban/Extensions/mouseposition
In directory doto:/tmp/cvs-serv351/Extensions/mouseposition
Added Files:
__init__.py mouseposition.py position.xpm
Log Message:
New Extension: mouseposition
Tool to collect mouse click positions (map coordinates) in a dialog.
* Extensions/mouseposition/__init__.py: New, extension registration
* Extensions/mouseposition/mouseposition.py: New, implements the
dialog and adds a tool to Thuban mainwindow.
* Extensions/mouseposition/position.xpm: New, icon for tool.
--- NEW FILE: __init__.py ---
# Copyright (C) 2005 by Intevation GmbH
# Authors:
# Frank Koormann <frank at intevation.de> (2005)
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.
# import the actual module
import mouseposition
# perform the registration of the extension
from Thuban import _
from Thuban.UI.extensionregistry import ExtensionDesc, ext_registry
ext_registry.add(ExtensionDesc(
name = 'mouseposition',
version = '1.0.0',
authors= [ 'Frank Koormann' ],
copyright = '2005 Intevation GmbH',
desc = _("On mouse click display the current coordinates\n" \
"in a dialog for easy further processing.")))
--- NEW FILE: mouseposition.py ---
# Copyright (C) 2005 by Intevation GmbH
# Authors:
# Frank Koormann <frank at intevation.de> (2005)
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.
"""
Extend thuban with a locator tool.
Collect positions of mouse clicks (in map coordinates) in a text control.
The tool was implemented in the need to collect some coordinates for some
work (outside Thuban). The status bar display of the coordinates is quite
transient (each mouse movement changes it) and cannot be copied. The tool let
one simply collect the coordinates needed and copy them in one block later.
"""
__version__ = '$Revision: 1.1 $'
# $Source: /thubanrepository/thuban/Extensions/mouseposition/mouseposition.py,v $
# $Id: mouseposition.py,v 1.1 2005/01/18 10:19:02 frank Exp $
import os, sys
import string
from wxPython import wx
from wxPython.lib.layoutf import Layoutf
from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
from Thuban.UI.command import registry, ToolCommand
from Thuban.UI.mainwindow import main_menu, main_toolbar, \
make_check_current_tool
from Thuban.UI.viewport import Tool
from Thuban.UI.dialogs import NonModalDialog
from Thuban import _
import Thuban
class DynamicMessageDialog(NonModalDialog):
"""Similar to the wxScrolledMessageDialog, contents dynamically
changeable by calling applications.
"""
def __init__(self, parent, msg, name, caption, pos = wx.wxDefaultPosition):
NonModalDialog.__init__(self, parent, name, caption)
x, y = pos
if x == -1 and y == -1:
self.CenterOnScreen(wx.wxBOTH)
text = wx.wxTextCtrl(self, -1, msg, wx.wxDefaultPosition,
wx.wxDefaultSize,
wx.wxTE_MULTILINE | wx.wxTE_READONLY)
ok = wx.wxButton(self, wx.wxID_OK, "OK")
text.SetConstraints(Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok)))
ok.SetConstraints(Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self,)))
wx.EVT_BUTTON(self, wx.wxID_OK, self.OnClose)
self.text = text
self.SetAutoLayout(1)
self.Layout()
def getText(self):
return self.text.GetValue()
def setText(self, text):
self.text.SetValue(text)
def appendText(self, text):
self.text.AppendText(text)
class MousePositionTool(Tool):
def __init__(self, view, context):
Tool.__init__(self, view)
self.context = context
self.dlg = None
def Name(self):
return "MousePositionTool"
def MouseDown(self, event):
map_proj = self.view.Map().GetProjection()
pos = self.view.CurrentPosition()
if pos is not None:
pMsg = "%10.10g, %10.10g\n" % pos
name = "extension_mouse_position"
dialog = self.context.mainwindow.get_open_dialog(name)
if dialog is None:
dialog = DynamicMessageDialog(self.context.mainwindow,
pMsg, name, _("Mouse Position Tool"))
self.context.mainwindow.add_dialog(name, dialog)
dialog.Show(True)
else:
dialog.appendText(pMsg)
dialog.Raise()
def mouse_position_tool(context):
canvas = context.mainwindow.canvas
canvas.SelectTool(MousePositionTool(canvas, context))
# locator executed as an tool/extension to Thuban
iconfile = os.path.join(os.path.abspath(Thuban.__path__[0]),
"..", "Resources", "Bitmaps", "identify")
iconfile = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'position')
registry.Add(ToolCommand("mouse_position_tool", "Mouse Position Tool",
mouse_position_tool, icon = iconfile,
helptext = "Collect mouse click coordinates in a dialog",
checked = make_check_current_tool("MousePositionTool")))
# Add the command to the toolbar
main_toolbar.InsertSeparator()
main_toolbar.InsertItem("mouse_position_tool")
# find the extensions menu (create it anew if not found)
extensions_menu = main_menu.FindOrInsertMenu('extensions', _('E&xtensions'))
# finally add the new entry to the extensions menu
extensions_menu.InsertItem('mouse_position_tool')
--- NEW FILE: position.xpm ---
/* XPM */
static char * position_xpm[] = {
"24 24 3 1",
" c None",
". c #000000",
"+ c #949194",
" ",
" ",
" . ",
" . .... ",
" .+ .+... .. ",
" .. .+......... ",
" ..+ .+........... ",
" ... ..+...........+ ",
" ...+ .+............+ ",
" .... .............++ ",
" ....+.+ ..........+ ",
" ......+ +.......++ ",
" .....++ ++....+ ",
" ......+ ++++ ",
" ......+ ",
" ....... ",
" ...+...+ ",
" ..++.... ",
" .++.+++.+ ",
" + .+ ++ ",
" .+ ",
" .+ ",
" + ",
" "};
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)