thandialexppil1.py :  » Business-Application » ThanCad » thancad-0.0.9 » thantkdia » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » thantkdia » thandialexppil1.py
##############################################################################
# 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 displays a dialog for the user to export to a raster image
using Python Image Library.
"""


from Tkinter import *
from p_ggen import path
from p_gtkwid import ThanEntry,ThanFile,ThanChoice
import p_gtkuti


thanImageTypes = \
{ "TIFF": ".tif",
  "BMP" : ".bmp",
  "JPEG": ".jpg",
}


class ThanTkExppil(p_gtkuti.ThanDialog):
    "Dialog for the visibility of a layer."

    def __init__(self, master, val, *args, **kw):
        "Extract initial style."
  self.__val = val
  p_gtkuti.ThanDialog.__init__(self, master, *args, **kw)

    def body(self, fra):
        "Create dialog widgets."
  w = Label(fra, text="Image type")
  w.grid(row=0, column=0, sticky="e")
        self.thanType = ThanChoice(fra, labels=sorted(thanImageTypes.keys()), command=self.__typeSet,
                  width=10, relief=RIDGE, anchor="w")
  self.thanType.grid(row=0, column=1, sticky="we")

  w = Label(fra, text="Image file")
  w.grid(row=1, column=0, sticky="e")
        self.thanFile = ThanFile(fra, text=self.__val, extension="*.bmp", mode="w", title="Open image file")
  self.thanFile.grid(row=1, column=1, sticky="we")

  w = Label(fra, text="width (pixels)", fg="blue")
  w.grid(row=2, column=0, sticky="e")
  self.thanWidth = ThanEntry(fra)
  self.thanWidth.grid(row=2, column=1, sticky="we")
  self.thanWidth.thanSet("1024")

  w = Label(fra, text="height (pixels)", fg="blue")
  w.grid(row=3, column=0, sticky="e")
  self.thanHeight = ThanEntry(fra)
  self.thanHeight.grid(row=3, column=1, sticky="we")
  self.thanHeight.thanSet("1024")

  self.thanType.thanSetText("BMP")
  del self.__val
  fra.columnconfigure(1, weight=1)
  return self.thanFile                      # This widget has the focus

    def __typeSet(self, i, imtyp):
        "Change the type of the image."
  ext = thanImageTypes[imtyp]
  self.thanFile.config(extension="*"+ext)
  fn = self.thanFile.thanGet().strip()
  if fn == "": return
  fn = path(fn)
  fn = fn.parent / fn.namebase+ext
  self.thanFile.thanSet(fn)

    def destroy(self):
        "Deletes self references."
  del self.thanType, self.thanFile, self.thanWidth, self.thanHeight
        p_gtkuti.ThanDialog.destroy(self)

    def validate(self, strict=True):
        "Returns true if the value chosen by the user is valid."
  ok = True
  try:
      height = int(self.thanHeight.thanGet())
      if height <= 0: raise ValueError
  except:
      if strict:
          p_gtkuti.thanGudModalMessage(self, "Invalid height", "Error Message")
          self.initial_focus = self.thanHeight
          return False
      height = 1024; ok = False
  try:
      width = int(self.thanWidth.thanGet())
      if width <= 0: raise ValueError
  except:
      if strict:
          p_gtkuti.thanGudModalMessage(self, "Invalid width", "Error Message")
          self.initial_focus = self.thanWidth
          return False
      width = 1024; ok = False
        filnam = path(self.thanFile.thanGet())
  if filnam.ext == "":
      ext = thanImageTypes[self.thanType.thanGetText()]
      filnam = filnam.parent / (filnam.namebase+ext)
  self.result = self.thanVals = (filnam, width, height)
  return ok

    def __del__(self):
        print "ThanTstyle ThanDialog", self, "dies.."


def test():
    root = Tk()
    win = ThanTkExppil(root, "q1.png", title="Export to Image: specifications")
    print win.result

test()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.