# -*- coding: iso-8859-7 -*-
##############################################################################
# ThanCad 0.0.9 "DoesSomething": 2dimensional CAD with raster support for engineers.
#
# Copyright (c) 2001-2009 Thanasis Stamos, August 23, 2009
# URL: http://thancad.sourceforge.net
# e-mail: cyberthanasis@excite.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details (www.gnu.org/licenses/gpl.html).
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
"""\
ThanCad 0.0.9 "DoesSomething": 2dimensional CAD with raster support for engineers.
This module implements an information status bar.
"""
from Tkinter import Frame,Label,SUNKEN,W,E
from p_ggen import prg
from thantrans import T
class ThanStatusBar(Frame):
"Implements a status bar."
def __init__(self, master, proj, **kw):
"Initialise base classes and create status bar (as a label)."
self.__proj = proj
Frame.__init__(self, master, **kw)
self.thanTypeCoor = Label(self, text=T["World xyz:"], anchor=E, width=10)
self.thanTypeCoor.grid(row=0, column=0, sticky="e")
self.thanCoor = Label(self, text="", bd=1, relief=SUNKEN, anchor=W, width=30)
self.thanCoor.grid(row=0, column=1, sticky="w")
self.thanInfo = Label(self, text="This is ThanCad", bd=1, relief=SUNKEN, anchor=W, width=20)
self.thanInfo.grid(row=0, column=2, sticky="we")
self.columnconfigure(1, weight=2)
self.rowconfigure(0, weight=1)
self.strcoo = self.__proj[1].thanUnits.strcoo
self.thanViewCoor(typ="world", every="click")
self.__info = [""]
self.__cp = None
def __coorNone(self, cp):
"Do not display anything into the coordinate widget."
self.__cp = tuple(cp)
def __coorWorld(self, cp):
"Display mouse world coordinates into the coordinate widget."
self.__cp = tuple(cp)
self.thanCoor.config(text=self.strcoo(cp))
if self.__typ != "w":
self.thanTypeCoor.config(text=T["World xyz:"], fg="black")
self.thanCoor.config(fg="black")
self.__typ = "w"
self.thanInfo.config(text=self.__info[-1])
self.thanCoor.update_idletasks()
def __coorImage(self, cp):
"Display image coordinates into the coordinate widget."
self.__cp = tuple(cp)
for im in self.__proj[2].thanImages.itervalues():
try:
px, py = im.thanGetPixCoor(cp)
except IndexError:
pass
else:
self.thanCoor.config(text="%d %d" % (px, py))
if self.__typ != "p":
self.thanTypeCoor.config(text=T["Pixel xy:"], fg="blue")
self.thanCoor.config(fg="blue")
self.__typ = "p"
self.thanInfo.config(text=im.filnam)
self.thanCoor.update_idletasks()
return
self.__coorWorld(cp)
def thanViewCoor(self, typ="world", every="mouse"):
"View world coordinates."
self.__every = "c" # "click"
self.thanCoorMouse = self.__coorNone
if every[0] == "m": self.__every = "m"
if typ[0] == "w":
self.__typ = None
self.thanCoorClick = self.__coorWorld
if self.__every == "m": self.thanCoorMouse = self.__coorWorld
else:
self.__typ = None
self.thanCoorClick = self.__coorImage
if self.__every == "m": self.thanCoorMouse = self.__coorImage
def thanToggleCoord(self, evt=None):
"Toggle between world and pixel coordinates."
if self.thanCoorClick == self.__coorWorld: typ1 = "pixel"
else: typ1 = "world"
self.thanViewCoor(typ1, self.__every)
if self.__cp != None: self.thanCoorClick(self.__cp)
return typ1
def thanInfoPush(self, text):
"Pushes a new message to the info label."
self.__info.append(text)
self.thanInfo.config(text=text)
self.thanInfo.update_idletasks()
def thanInfoPop(self):
"Pushes a new message to the info label."
if len(self.__info) > 1: del self.__info[-1]
self.thanInfo.config(text=self.__info[-1])
self.thanInfo.update_idletasks()
def thanClear(self):
"Clears the info label."
del self.__info[1:]
self.__info[-1] = ""
self.thanInfo.config(text="")
self.thanInfo.update_idletasks()
def destroy(self):
"Deletes circular references."
del self.__proj, self.thanTypeCoor, self.thanCoor, self.thanInfo
del self.thanCoorMouse, self.thanCoorClick, self.strcoo
Frame.destroy(self)
def test():
"Tests status bar."
from Tkinter import Tk
root = Tk()
sb = ThanStatusBar(root, ())
sb.grid()
root.mainloop()
if __name__ == "__main__":
prg(__doc__)
test()
|