thantkcli.py :  » Business-Application » ThanCad » thancad-0.0.9 » thantk » thantkclist » 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 » thantk » thantkclist » thantkcli.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 implements various types of compound list, based on the generic
compound list.
"""

import p_gtkuti, p_ggen, p_gtkwid
from thanvar import ThanLayerError

from thantkclist import *
from thantkclist import _EXPAND


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

class ThantkClist1(ThantkClistBare):
    "Parallel Tk listboxes working as one; activates bare mechanism."

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

    def __init__(self, master, objs, **kw):
  "Create the parallel lists boxes, and their actions."
  ThantkClistBare.__init__(self, master, **kw)
        self.thanListsPlace(0, 0)
  self.thanListsFill(objs)


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

class ThantkClist2(ThantkClistBare, ThanMixinUtil):
    "Parallel Tk listboxes working as one; bare mechanism."

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

    def __init__(self, master, objs, **kw):
  "Create the parallel lists boxes, bare plus selection buttons."
  ThantkClistBare.__init__(self, master, **kw)
        self.thanCreateButtons(self, 0, 0)
        self.thanListsPlace(1, 0)
  self.thanListsFill(objs)

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

    def thanCreateButtons(self, master, ir, ic):
        "Creates utitlities buttons."
  S = p_ggen.thanStub
        fraBut = Frame(master)
  fraBut.grid(row=ir, column=ic, columnspan=len(self.thanAtts))
  but = Button(fraBut, text="Select All", command=S(self.thanSchedule1, self.thanSelAll))
  but.grid(row=ir, column=0)
  but = Button(fraBut, text="Deselect All", command=S(self.thanSchedule1, self.thanSelNone))
  but.grid(row=ir, column=1)
  but = Button(fraBut, text="Invert selection", command=S(self.thanSchedule1, self.thanSelInvert))
  but.grid(row=ir, column=2)
        return 1, 0


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

class ThantkClist3(ThantkClistHierBare, ThanMixinHierUtil):
    "Hierarchical parallel lists."

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

    def __init__(self, master, objs, **kw):
        "Create the parallel lists boxes, bare plus selection buttons."
#  apply(ThantkClistHierBare.__init__, (self, master), kw)
  ThantkClistHierBare.__init__(self, master, **kw)
        self.thanCreateButtons(self, 0, 0)
        self.thanListsPlace(1, 0)
  self.thanListsFill(objs)

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

    def thanCreateButtons(self, master, ir, ic):
        "Creates utitlities buttons."
  S = self.thanStub
        fraBut = Frame(master)
  fraBut.grid(row=ir, column=ic, columnspan=len(self.thanAtts))
  but = Button(fraBut, text="Select All", command=S(self.thanSchedule1, self.thanSelAll))
  but.grid(row=ir, column=0)
  but = Button(fraBut, text="Deselect All", command=S(self.thanSchedule1, self.thanSelNone))
  but.grid(row=ir, column=1)
  but = Button(fraBut, text="Invert selection", command=S(self.thanSchedule1, self.thanSelInvert))
  but.grid(row=ir, column=2)
        return 1, 0


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

class ThantkClist4(ThantkClistHierBare, ThanMixinHierUtil, ThanMixinPartial):
    "Hierarchical partial parallel lists."

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

    def __init__(self, master, objs, **kw):
        "Create the parallel lists boxes, bare plus selection buttons."
#  apply(ThantkClistHierBare.__init__, (self, master), kw)
  ThantkClistHierBare.__init__(self, master, **kw)
  ThanMixinPartial.__init__(self)
        self.thanCreateButtons(self, 0, 0)
        self.thanListsPlace(2, 0)
  self.thanListsFill(objs)
  self.thanMakePartial()

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

    def thanCreateButtons(self, master, ir, ic):
        "Creates utitlities buttons."
  S = self.thanStub
        fraBut = Frame(master)
  fraBut.grid(row=ir, column=ic, columnspan=len(self.thanAtts), sticky="we")
  for i in (0,1): fraBut.columnconfigure(i, weight=1)

  but = Button(fraBut, text="Previous set", command=S(self.thanSchedule1, self.thanSetPrev))
  but.grid(row=0, column=0, sticky="w")
  but = Button(fraBut, text="Next set", command=S(self.thanSchedule1, self.thanSetNext))
  but.grid(row=0, column=1, sticky="e")

        fraBut = Frame(master)
  fraBut.grid(row=ir+1, column=ic, columnspan=len(self.thanAtts), sticky="we")
  but = Button(fraBut, text="Select All", command=S(self.thanSchedule1, self.thanSelAll))
  but.grid(row=ir, column=0)
  but = Button(fraBut, text="Deselect All", command=S(self.thanSchedule1, self.thanSelNone))
  but.grid(row=ir, column=1)
  but = Button(fraBut, text="Invert selection", command=S(self.thanSchedule1, self.thanSelInvert))
  but.grid(row=ir, column=2)

        return 2, 0


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

class ThantkClist5(ThantkClistHierBare, ThanMixinHierUtil1, ThanMixinPartial):
    "Hierarchical partial parallel lists."

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

    def __init__(self, master, objs, current, **kw):
        "Create the parallel lists boxes, bare plus selection buttons."
        self.__state = 1                                   # Window is alive
  self.thanCargo = kw.pop("cargo", None)
  ThantkClistHierBare.__init__(self, master, **kw)
  ThanMixinPartial.__init__(self)
  self.thanCur = current
  print "cur1=", self.thanCur

        self.thanCreateButtonsup(self, 0, 0)
        (nr, nc) = self.thanListsPlace(1, 0)
  self.thanCreateButtonsdown(self, 1+nr, 0)
  self.thanListsFill(objs)
  self.thanMakePartial(hlen=70)
  self.thanLeaflayers = {}

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

    def thanInsert2Lists(self, i, layers, prefix):
        """Inserts lays to the lists.

  This is exactly the same as the overriden fucntion in class ThantkClistHierBare
  with the exception of braces at the values, if the values
  are inherited.
  """
        for lay in layers:
      i += 1
            self.thanListLayers.insert(i, lay)     # layer pointer

            for att in self.thanAtts:
                li = self.thanLists[att]
                if att == self.thanAttmain:
                    li.thanInsert(i, prefix+str(lay.thanAtts[att]))
    elif att == _EXPAND:
                    li.thanInsert(i, lay.thanAtts[att].thanVal)
                else:
        t = str(lay.thanAtts[att])
        if lay.thanAtts[att].thanInher: t = "["+t+"]"
                    li.thanInsert(i, t)

            if lay.thanAtts[_EXPAND].thanVal == "-":
                i = self.thanInsert2Lists(i, lay.thanChildren, prefix+"....")
  return i

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

    def thanCreateButtonsup(self, master, ir, ic):
        "Creates utilities buttons."
  S = self.thanStub
        fraBut = Frame(master)
  fraBut.grid(row=ir, column=ic, columnspan=len(self.thanAtts), sticky="we")
  for i in (0,1,2,3): fraBut.columnconfigure(i, weight=1)

  but = Button(fraBut, text="Previous set", command=S(self.thanSchedule1, self.thanSetPrev))
  but.grid(row=0, column=0, sticky="we")
  but = Button(fraBut, text="Next set", command=S(self.thanSchedule1, self.thanSetNext))
  but.grid(row=1, column=0, sticky="we")

  but = Button(fraBut, text="Select All", command=S(self.thanSchedule1, self.thanSelAll))
  but.grid(row=0, column=3, sticky="we")
  but = Button(fraBut, text="Deselect All", command=S(self.thanSchedule1, self.thanSelNone))
  but.grid(row=1, column=3, sticky="we")
  but = Button(fraBut, text="Invert selection", command=S(self.thanSchedule1, self.thanSelInvert))
  but.grid(row=2, column=3, sticky="we")

  but = Button(fraBut, text="New Layer", command=S(self.thanSchedule1, self.thanLayerChildNew))
  but.grid(row=0, column=1, sticky="we")
  but = Button(fraBut, text="Rename Layer", command=S(self.thanSchedule1, self.thanLayerRen1))
  but.grid(row=1, column=1, sticky="we")
#  but = Button(fraBut, text="Delete Layer", command=S(self.thanSchedule1, self.thanSelDelete))
#  but.grid(row=3, column=1, sticky="we")

  but = Button(fraBut, text="Copy", command=S(self.thanSchedule1, self.thanSelCopy))
  but.grid(row=0, column=2, sticky="we")
  but = Button(fraBut, text="Paste", command=S(self.thanSchedule1, self.thanSelPaste))
  but.grid(row=1, column=2, sticky="we")
  but = Button(fraBut, text="Cut", command=S(self.thanSchedule1, self.thanSelCut))
  but.grid(row=2, column=2, sticky="we")

        self.__cl = p_gtkwid.ThanEntry(fraBut)
  self.__cl.thanSet(self.thanCur.thanGetPathname())
  self.__cl.grid(row=4, column=0, columnspan=3, sticky="we", pady=10)
  but = Button(fraBut, text="Set Current", command=S(self.thanSchedule1, self.thanSetCur))
  but.grid(row=4, column=3, sticky="we", pady=10)

        return 1, 0


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

    def thanLayerRen1(self, *args):
        "Renames the selected layer; updates current layer."
        lay = self.thanLayerRen()
  if lay == Canc: return
  if lay != self.thanCur: return
        self.__cl.thanSet(self.thanCur.thanGetPathname())   # Update name of current layer

    def thanSetCur(self, *args):
        indexes = self.thanLimain.curselection()
        lays = [self.thanListLayers[int(j)] for j in indexes]
        thanTryCur(self, lays)

    def thanTryCur(self, lays):
        "Try to set current layer one of the given layers (lays)."
  for lay in lays:
      if len(lay.thanChildren) == 0:     # Only leaflayers can be current
          self.thanCur = lay
          self.__cl.thanSet(self.thanCur.thanGetPathname())
    self.thanModified = True
    return True
  return False

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

    def thanCreateButtonsdown(self, master, ir, ic):
        "Creates utilities buttons."
  S = self.thanStub
        fraBut = Frame(master)
  fraBut.grid(row=ir, column=ic, columnspan=len(self.thanAtts), sticky="we")
  for i in (0,1,2,3): fraBut.columnconfigure(i, weight=1)

  but = Button(fraBut, text="Cancel", command=S(self.thanSchedule1, self.thanCancel))
  but.grid(row=0, column=0, sticky="we")
  but = Button(fraBut, text="OK", command=S(self.thanSchedule1, self.thanOK))
  but.grid(row=0, column=3, sticky="we")

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

    def thanCancel(self, *args):
        "What to do when user cancels."
  if self.thanModified:
            ok = p_gtkuti.thanGudAskOkCancel(self,
      message="The layer hierarchy has been modified\nAbandon changes?",
      title="Layers modified")
      if not ok: return
        self.__result = None, None
        self.__state = 0                       # window is dead

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

    def thanOK(self, *args):
        "What to do when user OKs."
        if self.thanClipMovePending(): return
        self.__result = self.thanLeaflayers, self.thanCur
        self.__state = 0                       # window is dead
  print "***tra1"

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

    def thanWait(self, *args):
        "Waits until user finishes."
  while self.__state:
      self.update_idletasks()
  print "***tra2"
#  self.destroy()
        del self.thanCargo
        return self.__result

    def destroy(self):
        "Break circular references."
  print "cur2=", self.thanCur
  del self.thanCur, self.__cl
        ThantkClistHierBare.destroy(self)

    def __del__(self):
        print "clist5 recycled."


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

class ThantkClist6(ThantkClistHierBare, ThanMixinHierUtil1, ThanMixinPartial):
    "Hierarchical partial parallel lists."

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

    def __init__(self, master, objs, current, **kw):
        "Create the parallel lists boxes, bare plus selection buttons."
  self.thanCargo = kw.pop("cargo", None)
  ThantkClistHierBare.__init__(self, master, **kw)
  ThanMixinPartial.__init__(self)
  self.thanCur = current
  print "cur1=", self.thanCur

        self.thanCreateButtonsup(self, 0, 0)
        (nr, nc) = self.thanListsPlace(1, 0)
  self.thanListsFill(objs)
  self.thanMakePartial(hlen=70)
  self.thanLeaflayers = {}

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

    def thanInsert2Lists(self, i, layers, prefix):
        """Inserts lays to the lists.

  This is exactly the same as the overriden function in class ThantkClistHierBare
  with the exception of braces at the values, if the values
  are inherited.
  """
        for lay in layers:
      i += 1
            self.thanListLayers.insert(i, lay)     # layer pointer

            for att in self.thanAtts:
                li = self.thanLists[att]
                if att == self.thanAttmain:
                    li.thanInsert(i, prefix+str(lay.thanAtts[att]))
    elif att == _EXPAND:
                    li.thanInsert(i, lay.thanAtts[att].thanVal)
                else:
        t = str(lay.thanAtts[att])
        if lay.thanAtts[att].thanInher: t = "["+t+"]"
                    li.thanInsert(i, t)

            if lay.thanAtts[_EXPAND].thanVal == "-":
                i = self.thanInsert2Lists(i, lay.thanChildren, prefix+"....")
  return i

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

    def thanCreateButtonsup(self, master, ir, ic):
        "Creates utilities buttons."
  S = lambda x: x
        fraBut = Frame(master)
  fraBut.grid(row=ir, column=ic, columnspan=len(self.thanAtts), sticky="we")
  for i in (0,1,2,3): fraBut.columnconfigure(i, weight=1)

  but = Button(fraBut, text="Previous set", bg="#ffffdc", command=S(self.thanSetPrev))
  but.grid(row=0, column=0, sticky="we")
  but = Button(fraBut, text="Next set", bg="#ffffdc", command=S(self.thanSetNext))
  but.grid(row=1, column=0, sticky="we")

  but = Button(fraBut, text="Select All", bg="#ffdcdc", command=S(self.thanSelAll))
  but.grid(row=0, column=3, sticky="we")
  but = Button(fraBut, text="Deselect All", bg="#ffdcdc", command=S(self.thanSelNone))
  but.grid(row=1, column=3, sticky="we")
  but = Button(fraBut, text="Invert selection", bg="#ffdcdc", command=S(self.thanSelInvert))
  but.grid(row=2, column=3, sticky="we")

  but = Button(fraBut, text="New Top Layer", bg="#dcffdc", command=S(self.thanLayerTopNew1))
  but.grid(row=0, column=1, sticky="we")
  but = Button(fraBut, text="New Child Layer", bg="#dcffdc", command=S(self.thanLayerChildNew1))
  but.grid(row=1, column=1, sticky="we")
  but = Button(fraBut, text="Rename Layer", bg="#dcffdc", command=S(self.thanLayerRen1))
  but.grid(row=2, column=1, sticky="we")
#  but = Button(fraBut, text="Delete Layer", command=S(self.thanSelDelete))
#  but.grid(row=3, column=1, sticky="we")

  but = Button(fraBut, text="Copy", bg="#dcdcff", command=S(self.thanSelCopy))
  but.grid(row=0, column=2, sticky="we")
  but = Button(fraBut, text="Paste", bg="#dcdcff", command=S(self.thanSelPaste))
  but.grid(row=1, column=2, sticky="we")
  but = Button(fraBut, text="Cut", bg="#dcdcff", command=S(self.thanSelCut))
  but.grid(row=2, column=2, sticky="we")

        self.__cl = p_gtkwid.ThanEntry(fraBut, bg="#ffdcff")
  self.__cl.thanSet(self.thanCur.thanGetPathname())
  self.__cl.grid(row=4, column=0, columnspan=3, sticky="we", pady=10)
  but = Button(fraBut, text="Set Current", bg="#ffdcff", command=S(self.thanSetCur))
  but.grid(row=4, column=3, sticky="we", pady=10)

        return 1, 0

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

    def thanLayerRen1(self, *args):
        "Renames the selected layer; updates current layer."
        lay = self.thanLayerRen()
  if lay == Canc: return
  if lay == self.thanCur:             # Rename current layer
      self.__cl.thanSet(self.thanCur.thanGetPathname())


    def thanLayerTopNew1(self, *args):
        "Creates a new top level layer."
  laypar = self.thanListLayers[0]
  name1 = laypar.thanChildUniqName()
  while True:
      name1 = p_gtkuti.thanGudGetText(self, T["Create New Top Level Layer"], name1)
      if name1 == None: return Canc
      self.thanSel1(0)
      self.thanPollForce()      # Force selection now
      try:
          lay1 = self.thanLayerChildNewHouse(name1)
      except ThanLayerError:    # Check if name is valid
          thanGudModalMessage(self, lay1, T["Top Level Layer can not be created"])
      else:
          break


    def thanLayerChildNew1(self, *args):
        "Creates a new child layer."
        (indexes, lays) = self.thanSelGet()
  if len(lays) <= 0:
      i = 0
      laypar = self.thanListLayers[0]
  else:
        i = int(indexes[0])
      laypar = lays[0]
  name1 = laypar.thanChildUniqName()
  while True:
      name1 = p_gtkuti.thanGudGetText(self, T["Create New '%s' Child Layer"]%laypar.thanGetPathname(), name1)
      if name1 == None: return Canc
      lay1 = self.thanLayerChildNewHouse(name1)
      if type(lay1) not in types.StringTypes: break        # Check if name is valid
      thanGudModalMessage(self, lay1, T["Child Layer can not be created"])


    def thanSetCur(self, *args):
        indexes = self.thanLimain.curselection()
        lays = [self.thanListLayers[int(j)] for j in indexes]
        self.thanTryCur(lays)


    def thanTryCur(self, lays):
        "Try to set current layer one of the given layers (lays)."
  for lay in lays:
      if len(lay.thanChildren) == 0:     # Only leaflayers can be current
          self.thanCur = lay
          self.__cl.thanSet(self.thanCur.thanGetPathname())
    self.thanModified = True
    return True
  return False


    def destroy(self):
        "Break circular references."
  print "ThanTkClist detroy: cur2=", self.thanCur
  del self.thanCur, self.__cl
        ThantkClistHierBare.destroy(self)
        ThanMixinHierUtil1.destroy(self)
  ThanMixinPartial.destroy(self)

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

#MODULE LEVEL CODE. IT IS EXECUTED ONLY ONCE

if __name__ == "__main__":
    print __doc__
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.