thancomvar.py :  » Business-Application » ThanCad » thancad-0.0.9 » thancom » 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 » thancom » thancomvar.py
# -*- 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.

Package which processes commands entered by the user.
This module processes various commands.
"""

import p_ggen, p_gtkuti
import thandr, thancomsel, thantkdia, thanlayer, thanvers
from thanvar import Canc
from thantrans import T,Tmatch
from thancomfile import thanTxtopen


def thanVarElev(proj):
    "Sets the elevation in z,t and other coordinates."
    nd = proj[1].thanVar["dimensionality"]
    assert nd > 2, "Well, this should be ThanCad with limited n-dimensional support!"
    statonce = ""
    if nd > 3:
        statonce = "%s\n%s\n" % (
           T["This drawing has %d dimensions. The elevation and thickness"],
           T["of dimensions higher than 3 are set with the ELEVN command."])
    c = proj[1].thanVar["elevation"]          # Reference to the elevation list
    sd = proj[1].thanUnits.strdis
    statonce = "%s%s %s\n" % (statonce, T["Current elevation:"], sd(c[2]))
    stat = "%s%s): " % (T["New elevation (enter="], sd(c[2]))
    z = proj[2].thanGudGetFloat(stat, c[2], statonce)
    if z == Canc: return proj[2].thanGudCommandCan()
    c[2] = z                                  # Update elevation list
    proj[2].thanGudCommandEnd()


def thanVarSudup(proj):
    "Funny!."
    proj[2].thanGudCommandEnd(T["Sudup, brother!"])


def thanVarFill(proj):
    "Explain what happened with the fill command."
    def prt(s): proj[2].thanCom.thanAppend("%s\n" % s, "info1")
    prt("ThanCad hint: The 'fill' attribute of layers is superior to the 'fill' command.")
    res = proj[2].thanGudGetOpts(T["Enter fill mode for all layers [ON/OFF] <ON>:"],
        default="ON", fullopt=True, options=("ON", "OFF"))
    if res == Canc: return proj[2].thanGudCommandCan()
    res = res == "on"
    from thanlayer.thanlayatts import thanUpdateElements
    leaflayers = {}
    proj[1].thanLayerTree.thanRoot.thanPropAttAll(leaflayers, "fill", res)
    thanUpdateElements(proj, leaflayers)
    proj[1].thanTouch()
    proj[2].thanGudCommandEnd()


def thanVarScript(proj):
    "Run a series of commands."
    fr = thanTxtopen(proj, T["Open script file (with ThanCad's commands)"], suf=".scr")
    if fr == Canc: return Canc      # thanGudCommandCan has been already called
    thanVarScriptDo(proj, fr)
    fr.close()


def thanVarScriptDo(proj, fr):
    "Run a series of commands from an opened file."
    win = proj[2]
    coms = win.thanScriptComs = __itercom(fr)
    cmd = win.thanCom
    dc = win.thanCanvas
    win.thanGudCommandEnd()                   # Finish the sript command and reprompt
    while True:
        while not cmd.thanWaitingInput:
            dc.update()
        try: com1 = coms.next()
        except StopIteration: break
        win.thanScheduler.thanSchedClear()    # The previous command is cleared; breaks some tk gui commands
        cmd.thanEnter(com1)
    win.thanScriptComs = ()


def __itercom(fr):
    "Iterator which excudes the comments."
    for dline in fr:
        dline = dline.strip()
        if dline[:1] == "#": continue
        yield dline


def thanFormLay(proj):
        "Shows interactive window with layer tree in order to manipulates layers."
  lt = proj[1].thanLayerTree
        temp = lt.thanRoot.thanClone()
  names = lt.thanCur.thanGetPathname().split("/")
  cl = temp.thanFind(names)
  assert cl != None, "Current layer should be found!"

  w = thantkdia.ThanDialogLay(proj[2],
           objs=[temp], current=cl,
           atts=thanlayer.thanlayatts.thanLayAttsNames, cargo=proj,
     widths=thanlayer.thanlayatts.thanLayAttsWidths,
           height=15, vscroll=1, hscroll=1,
     onclick=thanlayer.thanlayatts.thanOnclick,
           title=proj[2].thanTitle+": Layer Control")
  if w.result != None:
      leaflayers, cl = w.result
      lt.thanCur = cl
      lt.thanRoot.thanDestroy()
      lt.thanRoot = temp
      lt.thanDictRebuild()
            draworder = thanlayer.thanlayatts.thanUpdateElements(proj, leaflayers)

      lt.thanCur.thanTkSet(proj[2].than, proj[1].thanTstyles)    # Set Attributes of the current layer
      proj[1].thanTouch()                                        # Drawing IS modified
      if draworder: proj[2].thanRedraw()                         # Set relative draworder
      proj[2].thanGudCommandEnd()
      proj[2].thanUpdateLayerButton()
  else:
            proj[2].thanGudCommandCan()


def thanFormTstyle(proj):
    "Manipulates text styles."
    win = thantkdia.ThanTkStyle(proj[2], proj[1].thanTstyles, "standard", lambda x: False, title=T["Edit ThanCad Text styles"])
    if win.result == None: return proj[2].thanGudCommandCan()
    proj[1].thanTstyles = win.result
    proj[1].thanTouch()
    proj[2].thanGudCommandEnd(T["Changes will be visible after the next regeneration."], "can")


def thanList(proj):
    "Lists the properties of elements."
    res = thancomsel.thanSelectGen(proj, standalone=False)
    if res == Canc: proj[2].thanGudResetSelColor(); return proj[2].thanGudCommandCan()
    than = p_ggen.Struct()
    than.write = proj[2].thanCom.thanAppend
    than.read = proj[2].thanGudGetText
    than.writecom = lambda t, proj=proj: proj[2].thanCom.thanAppend(t, "com")
    than.strang = proj[1].thanUnits.strang
    than.strdis = proj[1].thanUnits.strdis
    than.strcoo = proj[1].thanUnits.strcoo
    dilay = proj[1].thanLayerTree.dilay

    for elem in proj[2].thanSelall:
        lay = dilay[elem.thanTags[1]]
        than.laypath = lay.thanGetPathname()
        elem.thanList(than)
    del than, dilay
    proj[2].thanGudResetSelColor()
    proj[2].thanGudCommandEnd()


def thanHelpAbout(proj):
    "Shows brief information about the program."
    p_gtkuti.thanGudHelpWin(proj[2], thanvers.thanCadAbout, T["About "]+thanvers.thanCadName)   # (Gu)i (d)ependent
    proj[2].thanGudCommandEnd()


def thanHelpHelp(proj):
    p_gtkuti.thanGudHelpWin(proj[2], thanvers.thanCadHelp, thanvers.thanCadName+" "+T["Help"])   # (Gu)i (d)ependent
    proj[2].thanGudCommandEnd()

def thanHelpGpl (proj):
    p_gtkuti.thanGudHelpWin(proj[2], thanvers.thanGplText, thanvers.thanCadName+" "+T["GPL"])   # (Gu)i (d)ependent
    proj[2].thanGudCommandEnd()

def thanHelpVer(proj):
    "Prints ThanCad's version."
    proj[2].thanCom.thanCadVer()
    proj[2].thanGudCommandEnd()


def thanDevFont(proj):
    "Show font for debugging reasons."
    c = list(proj[1].thanVar["elevation"])
    c[0] = 0; c[1] = 30; h = 50
    __AddElem(proj, thandr.ThanText, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", c, h, 0.0)
    c[1] -= h*1.2
    __AddElem(proj, thandr.ThanText, "abcdefghijklmnopqrstuvwxyz", c, h, 0.0)
#    y -= h*1.2
#    __AddElem(proj, thandr.ThanText, ""+chr(255), x, y, h, 0.0)

    for i in xrange(0, 256, 8):
        c[1] -= h*3
        c[0] = 0
        for j in xrange(i, i+8):
            t = "%3d:%s" % (j, chr(j))
            __AddElem(proj, thandr.ThanText, t, c, h, 0.0)
            c[0] += h*8
    proj[2].thanGudCommandEnd()


def thanDevCm(proj):
    "Gets dimension of window and screen."
    w, h, width, height, widthmm, heightmm = proj[2].thanGudGetWinDim()
    s = ("screen width x height (mm)     : %7.1f x %7.1f" % (widthmm, heightmm),
         "screen width x height (pixels) : %7d x %7d"     % (width,  height),
         "window width x height (pixels) : %7d x %7d"     % (w, h),
        )
    proj[2].thanGudCommandEnd("\n".join(s), "info")


def thanDevCmdsave(proj):
    "Saves the content of the command window to a txt file."
    import thancomfile
    fout = thancomfile.thanTxtsave(proj, T["Save command window text"])
    if fout == Canc: return proj[2].thanGudCommandCan()
    fout.write(proj[2].thanCom.thanGet())
    fout.close()
    proj[2].thanGudCommandEnd(T["Save command window text was completed."], "info")


def thanDevTrans(proj):
    "Save the translation report to a file."
    import thancomfile
    fout = thancomfile.thanTxtsave(proj, T["Save translation report"])
    if fout == Canc: return proj[2].thanGudCommandCan()
    fout.write("T:\n")
    T.thanReport(fout)
    fout.write("\n\n\nTmatch:\n")
    Tmatch.thanReport(fout)
    fout.close()
    proj[2].thanGudCommandEnd("Translation report was completed", "info")


def __AddElem(proj, elemClass, *args, **kw):
    "Creates an element with attributes *args on the current layer."
    elem = elemClass()
    elem.thanSet(*args, **kw)
    proj[1].thanElementAdd(elem)
    elem.thanTkDraw(proj[2].than)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.