inp.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_ggen » 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_ggen » inp.py
# -*- coding: iso-8859-7 -*-

from gen import ing,prg,tog
from jorpath import path

def inpDouble(mes, douDef=None):
      "Inputs a double with default value."
      while True:
          dline = raw_input(tog(mes)).strip()
          if dline == '' and douDef != None: return douDef     # Default value
          try: return float(dline)
          except: pass
          prg("\n  \n .\n")

def inpLong(mes, douDef=None):
      "Inputs an integer with default value."
      while True:
          dline = raw_input(tog(mes)).strip()
          if dline == '' and douDef != None: return douDef     # Default value
          try: return int(dline)
    except: pass
          prg("\n  \n .\n")

def inpNo(mes, douDef=None):
      "Inputs yes or no."
      while True:
          dline = raw_input(tog(mes)).strip()
          if dline == '' and douDef != None: return douDef     # Default value
    dl = ing(dline[:2])
#---------Check what We read
          if dl in ('', '', 'na', 'NA', 'ye', 'YE', '1'): return True
          if dl in ('', '', 'ox', 'OX', 'no', 'NO', '0'): return False
          prg('\n  (, , na, ye, YE, 1)   (X, , x, no, NO, 0)\n .\n')


def inpStr(mes, douDef=None):
      "Inputs a string with default value."
      while True:
          dline = ing(raw_input(tog(mes)).strip())
          if dline == '' and douDef != None: return douDef     # Default value
          return dline


def inpFiles(mes, suf, nest=False):
    """Gets data files with suffix suf.
    
    Examples:
    1. fils = inpFiles(" .asc  .    * (enter=*) : ", ".asc")
       The above gets all the files in current directory (and recursively in the 
       subdirectories if nest==True)
       which have .asc as a suffix:  a.asc, thanasis.asc, 1.asc, ...
    2. The filenames are transformed to lower, to facilitate windows..
    """
    while True:
        suf = suf.lower()
        fentries = inpStr(mes, "*")
        fildats = []; cdir = path(".")
        for fentry in fentries.split():
            if "*" in fentry or "?" in fentry:
          if nest: f = list(cdir.walkfiles(fentry+suf))      # nested subdirectories
          else:    f = list(cdir.files(fentry+suf))          # only current directory
                if len(f) == 0: prg("Warning: no %s files matches '%s'" % (suf, fentry))
                fildats.extend(f)
            else:
                fildats.append(path(fentry+suf))
        if len(fildats) > 0: return fildats
        prg("Error: No %s files defined or found." % suf)
        prg("Try again.")


def inpStrB(mes, douDef=None):
      "Inputs a non-blank string with default value."
      while True:
          dline = ing(raw_input(tog(mes)).strip())
          if dline == '' and douDef != None: dline = douDef         # Default value
          if dline.strip() != '': return dline
          prg('\n  ( )\n .\n')

def inpDoubleR (mes, douMin, douMax, douDef):
      "Inputs a double with default value and range check."
      while True:
          dou = inpDouble(mes, douDef)
          if douMin <= dou <= douMax: return dou
          prg('\n     :')
          prg('%.3f  %.3f' % (douMin, douMax))
          prg('\n .\n')

def inpLongR (mes, douMin, douMax, douDef):
      "Inputs an integer with default value and range check."
      while True:
          dou = inpLong(mes, douDef)
          if douMin <= dou <= douMax: return dou
          prg('\n     :')
          prg('%d  %d' % (douMin, douMax))
          prg('\n .\n')

#===========================================================================

def medDoubleR (un, mes, douMin, douMax, douDef):
      """
c-----This routine tries to read a double number dou from unit iun.

c     If it does and dou is between douMin and douMax -> OK.
c     If dou can not be read or is outside douMin-douMax,
c     dou takes the default value, and warning message mes is printed.
c     This routine is used to read values from file "mediate.tmp". See
c     library fildat
      """
      dline = un.readline()
      if dline != "":                  # not end of file
          try:
        dou = float(dline.strip())
              if douMin <= dou <= douMax: return dou
          except:
        pass
      prg("%s %.3f" % (mes, douDef))  # Use the default value and print message
      return douDef

def medLongR (un, mes, douMin, douMax, douDef):
      """
c-----This routine tries to read a long number dou from unit iun.

c     If it does and dou is between douMin and douMax -> OK.
c     If dou can not be read or is outside douMin-douMax,
c     dou takes the default value, and warning message mes is printed.
c     This routine is used to read values from file "mediate.tmp". See
c     library fildat
      """
      dline = un.readline()
      if dline != "":                  # not end of file
          try:
              dou = int(dline.strip())
              if douMin <= dou <= douMax: return dou
          except:
              pass
      prg("%s %d" % (mes, douDef))  # Use the default value and print message
      return douDef

def medStr(un, mes, douDef):
      """
c-----This routine tries to read a string dou from unit iun.

c     If it does and dou is not blank -> OK.
c     If dou can not be read or is blank,
c     dou takes the default value, and warning message mes is printed.
c     This routine is used to read values from file "mediate.tmp". See
c     library fildat
      """
      dline = un.readline()
      if dline != "":                  # not end of file
          dline = dline.strip()
    if dline != "": return dline
      prg("%s %s" % (mes, douDef))  # Use the default value and print message
      return douDef


def test():
    "Tests the functions."
    akl = inpDoubleR('   (return=500) : ', 1.0e-10, 1.0e10, 500.0)
    print "akl=", akl


if __name__ == "__main__": 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.