crlay.py :  » Business-Application » ThanCad » thancad-0.0.9 » thansupport » 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 » thansupport » crlay.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 defines utility functions to create/edit layers from within
an embedded program.
"""
from thanvar import THANBYPARENT,THANPERSONAL,ThanLayerError

def thanToplayerCurrent(proj, name, current=True, **atts):
    """Create a toplevel layer, set its colour, and set it as current.

    If the toplevel layer exists:
    a. It is not created.
    b. Its colour is set to col, or if col==None, it is unaffected.
    c. If current==True, it is set as current layer.
    d. If current==False, but it happens that the layer is the current layer
       the attributes of the current layer are set again to the .than object.
    If the toplevel layer does not exist:
    a. It is created.
    b. Its colour is set to col, or if col==None, the colour is inherited.
    c. If current==True, it is set as current layer.
    This routine may raise ThanLayerError if the layer can not be created,
    or if any attributes is not recognised.
    This routine may raise ValueError if the value of the attribute is illegal.
    This routine is safe: if something is invalid, it will perform no changes
    at all, and it will raise the appropriate exception.

    """
    from thanlayer.thanlayatts import thanLayAtts
    lt = proj[1].thanLayerTree
    root = lt.thanRoot
    thanLayerCurrent(proj, root, name, current=True, **atts)

def thanLayerCurrent(proj, parent, name, current=True, **atts):
    """Create a child layer, set its colour, and set it as current.

    If the toplevel layer exists:
    a. It is not created.
    b. Its colour is set to col, or if col==None, it is unaffected.
    c. If current==True, it is set as current layer.
    d. If current==False, but it happens that the layer is the current layer
       the attributes of the current layer are set again to the .than object.
    If the toplevel layer does not exist:
    a. It is created.
    b. Its colour is set to col, or if col==None, the colour is inherited.
    c. If current==True, it is set as current layer.
    This routine may raise ThanLayerError if the layer can not be created,
    or if any attributes is not recognised.
    This routine may raise ValueError if the value of the attribute is illegal.
    This routine is safe: if something is invalid, it will perform no changes
    at all, and it will raise the appropriate exception.

    """
    from thanlayer.thanlayatts import thanLayAtts
    lt = proj[1].thanLayerTree
    class_ = thanLayAtts["moncolor"][3]         # Get class of attribute 'moncolor'
    lay = lt.thanFindic(name)
    if lay == None:                             # Layer does not exist
        try:     lay = parent.thanChildNew(name) # This may raise ThanLayerError
        finally: lt.thanDictRebuild()
        for att, rawval in atts.iteritems():
            if att not in thanLayAtts: raise ThanLayerError, "Attribute %s is not recognised" % att
      if rawval == THANPERSONAL: raise ValueError, "New layer does not have PERSONAL attributes yet"
      class_ = thanLayAtts[att][3]        # Get class of attribute 'moncolor'
      if rawval == THANBYPARENT:
          val = class_(parent.thanAtts[att].thanVal, inherit=True)
      else:
          val = class_(rawval, inherit=False) # This will raise ValueError if rawval is invalid
            lay.thanAtts[att] = val             # No propagation is necessary
        if current:
            lt.thanCur = lay
            lay.thanTkSet(proj[2].than, proj[1].thanTstyles)
            proj[2].thanUpdateLayerButton()
        proj[1].thanTouch()                     # Drawing IS modified
    else:
        if current and len(lay.thanChildren) > 0: raise ThanLayerError, "Only a leaflayer may be current layer"
  leaflayers = {}
        __atts(proj, parent, lay, atts, check=True) # At first checks the attributes and raise exceptions if invalid
        __atts(proj, parent, lay, atts, check=False)

        if current or lay == lt.thanCur:
            lt.thanCur = lay
            lay.thanTkSet(proj[2].than, proj[1].thanTstyles)
            proj[2].thanUpdateLayerButton()
      proj[1].thanTouch()                 # Drawing IS modified

def __atts(proj, parent, lay, atts, check):
        "Check or set the attributes."
        from thanlayer.thanlayatts import thanLayAtts,thanUpdateElements
  if len(atts) == 0: return
  leaflayers = {}
  for att, rawval in atts.iteritems():
            if att not in thanLayAtts: raise ThanLayerError, "Attribute %s is not recognised" % att
      class_ = thanLayAtts[att][3]        # Get class of attribute 'moncolor'
      if rawval == THANBYPARENT:
          val = class_(parent.thanAtts[att].thanVal, inherit=True)
      elif rawval == THANPERSONAL:
          val = class_(lay.thanAtts[att].thanVal.personal, inherit=False)
      else:
          val = class_(thanLayAtts[att][2], inherit=False)
     val.thanValSet(rawval)          # This will raise ValueError if rawval is invalid
      if not check:
                lay.thanSetAtts(leaflayers, att, class_(val, inherit=False))

        if check: return
        draworder = thanUpdateElements(proj, leaflayers)
  if draworder: proj[2].thanRedraw()      # Set relative draworder
  proj[1].thanTouch()                     # Drawing IS modified
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.