thandataformold.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_gtkwid » 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 » p_gtkwid » thandataformold.py
from Tkinter import *

from p_gtkuti import thanGudModalMessage,thanGudAskOkCancel
from thanval import ThanEntryFloat,ThanEntryInt
from thanwids import ThanYesno,ThanChoice
from thanwidstrans import T

##############################################################################
##############################################################################


class ThanDataForm(Toplevel):
    "A form which accepts data."

    def __init__(self, vals, callerapply, master, **kw):
        self.thanCallerApply = callerapply
        
        Toplevel.__init__(self, master, **kw)
  self.protocol("WM_DELETE_WINDOW", self.thanCancel)
        fraWid = Frame(self, relief=SUNKEN, borderwidth=1)
        fraWid.grid(row=0, sticky="wesn")
        self.thanWidgetsCreate(fraWid)
        fraBut = Frame(self)
        fraBut.grid(row=1, sticky="we")
        self.thanButtonsCreate(fraBut)
  for i in 0,: self.columnconfigure(i, weight=1)
  for i in 0,: self.rowconfigure(i, weight=1)

  self.thanSet(vals)
  self.thanValsOri = self.thanGet()

    def thanSet(self, v):
        for wid,v1 in zip(self.thanWids2val,v): wid.thanSet(v1)

    def thanValidate(self):
        v = []
        for wid in self.thanWids2val:
            v.append(wid.thanValidate())
            if v[-1] == None:
                thanGudModalMessage(self, wid.thanGetErr(), T["Error in data"])
                wid.focus_set()
                return None
        return v

    def thanGet(self):
        return [wid.thanGet() for wid in self.thanWids2val]

    def thanWidgetsCreate(self, fra):
        "Creates data widgets."

        pass
            
    def thanButtonsCreate(self, fra):
        "Creates OK, APPLY, CANCEL buttons."

        but = Button(fra, text=T["OK"], bg="lightgreen", activebackground="green", width=8, relief=RAISED, command=self.thanOk)
        but.grid(row=0, column=0)
        but = Button(fra, text=T["Apply"], bg="lightyellow", activebackground="yellow", width=8, relief=RAISED, command=self.thanApply)
        but.grid(row=0, column=1)
        but = Button(fra, text=T["Cancel"], bg="pink", activebackground="red", width=8, relief=RAISED, command=self.thanCancel)
        but.grid(row=0, column=2)
  for i in 0,1,2: fra.columnconfigure(i, weight=1)

    def thanOk(self, evt=None):
        if self.thanApply() == "break": return
        self.destroy()
        
    def thanApply(self, evt=None):
        v = self.thanValidate()
        if v == None: return "break"
        self.thanCallerApply(tuple(v))
        self.thanValsOri = v
        
    def thanCancel(self, evt=None):
        if self.thanGet() != self.thanValsOri:
            if not thanGudAskOkCancel(self,
               T["Values have changed.\nAbandon changes?"], T["WARNING"]):
                return "break"
        self.destroy()


##############################################################################
##############################################################################


class ThanDataGen(ThanDataForm):
    "A form which accepts data."

    def thanWidgetsCreate(self, fra):
        "Creates data widgets."

        fs = T["HIGHWAY"], T["SEWAGE"], T["IRIGATION"]
        wids = \
        ( (T["POSITION SCALE 1/"], ThanEntryFloat(fra, bounds=(1e-6, 1e6))),
          (T["HEIGHT SCALE 1/"], ThanEntryFloat(fra, bounds=(1e-6, 1e6))),
          (T["DRAW GRADE LINES"], ThanYesno(fra, relief=RAISED)),
          (T["HORIZONTAL CURVES"], ThanYesno(fra, relief=RAISED)),
          (T["MAIN FUNCTION"], ThanChoice(fra, labels=fs, relief=RAISED)),
          (T["DRAW VERTICAL SLOPES"], ThanYesno(fra, relief=RAISED)),
          (T["TITLE IN EACH DRAWING"], ThanYesno(fra, relief=RAISED)),
          (T["DRAW DRIVER LINES"], ThanYesno(fra, relief=RAISED)),
          (T["PAPER WIDTH (cm)"], ThanEntryFloat(fra, bounds=(15, 1000))),
          (T["HORIZON MARGIN (cm)"], ThanEntryFloat(fra, bounds=(0, 1000))),
          (T["MAIN SOIL LINE"], ThanEntryInt(fra, bounds=(1, 50))),
          (T["MAIN GRADE LINE"], ThanEntryInt(fra, bounds=(1, 50))),
          (T["NUMBER OF LINES"], ThanEntryInt(fra, bounds=(1, 50)))
  )
          
        i = -1
        for text,wid in wids:
            i += 1
            lab = Label(fra, text=text)
            lab.grid(row=i, column=0, sticky="e")
            s = "we"
            if isinstance(wid, ThanYesno) or isinstance(wid, ThanChoice): s = "w"
            wid.grid(row=i, column=1, sticky=s)

        self.thanWids2val = [w for (t,w) in wids]
  for i in 1,: fra.columnconfigure(i, weight=1)
            

##############################################################################
##############################################################################

if __name__ == "__main__" and 1:
    import sys
    def f(v): print v
    root = Tk()
    if sys.platform == "win32":
        root.option_add("*font", "arialgreek 8")
    else:
        root.option_add("*font", "greekcourier 12")
    v = (1000.0, 100.0, 1, 1, 0, 1, 0, 0, 30.0, 1.5, 1, 2, 2)
    d = ThanDataGen(v, f, root, class_="ThanHigh")
    t = Entry()
    t.grid()
    root.mainloop()
    T.thanReport()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.