thanmenus.py :  » Business-Application » ThanCad » thancad-0.0.9 » thantkgui » 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 » thantkgui » thanmenus.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.

This module defines the menus and the mechanism to create and update them.
"""
import p_ggen, p_gtkuti
import thanvers
from thantrans import T,Tmatch


class ThanCadTkMenu:
    "It creates ThanCad menu system and modifies it if necessary."

    def __init__(self, win, main=False):
        "Create the menu system."
        if main: seq, menus = thanMainMenus(win.thanGudCommandBegin)
        else:    seq, menus = thanStandardMenus(win.thanGudCommandBegin)
        ms = []
        for m in seq: ms.extend(menus[m])
        menubar, self.__submenus = p_gtkuti.thanTkCreateThanMenus(win, ms)
        win["menu"] = menubar
        if not main:
            self.__submenus["File"]   = self.__submenus[T["&File"].replace("&", "")]
            self.__submenus["Window"] = self.__submenus[T["&Window"].replace("&", "")]

        self.__irecent = len(menus["File"]) - 3
        self.__recent = []
        self.__iopened = 0
        self.__opened = []


    def thanAddRecent(self, proj, fpath, MAXRECENT):
        "Adds a new recent file to the file menu."
  import thancom
  fmenu = self.__submenus["File"]
  n = len(self.__recent)
  try: i = self.__recent.index(fpath)
  except ValueError: i = -1
  if   i >= 0:         self.__delRecent(i)
  elif n >= MAXRECENT: self.__delRecent(MAXRECENT-1)
  def op():
      thancom.thancomfile.thanFileOpenPath(proj, fpath)
  fmenu.insert_command(self.__irecent, label=fpath.namebase, foreground="blue",
      command=op, help=fpath)
  self.__recent.insert(0, fpath)


    def __delRecent(self, i):
        "Deletes a recent file entry by index."
        assert 0 <= i < len(self.__recent)
        del self.__recent[i]
        fmenu = self.__submenus["File"]
        fmenu.delete(self.__irecent+i)


    def thanAddOpened(self, projnew):
        "Adds a new opened file to the window menu."
        wmenu = self.__submenus["Window"]
        wmenu.add_command(label=projnew[0].namebase,
            command=lambda win=projnew[2]: win.thanTkSetFocus(), help=projnew[0])
        self.__opened.append(str(projnew))


    def thanDelOpened(self, proj):
        "Deletes a previously opened file from the window menu."
  wmenu = self.__submenus["Window"]
  i = self.__opened.index(str(proj))
  wmenu.delete(self.__iopened+i)
  del self.__opened[i]


    def __del__(self): print "ThanCadTkMenu", self, "dies."


def thanStandardMenus(B):
        "Creates a description of the desired menus in a list."
        S = p_ggen.ThanStub
        s = "File Edit View Insert Format Tools Draw Engineering Modify Research Developer Window Help".split()
  m = {}
        m["File"] = \
  [ (None, T["&File"], ""),            # Menu Title
          (S(B, "new"),    T["&New"],  T["Makes an empty drawing"]),
          (S(B, "open"),   T["&Open"], T["Opens an existing drawing"]),
          (S(B, "save"),   T["&Save"], T["Saves drawing into a file"]),
          (S(B, "close"),  T["&Close"],T["Closes current drawing"]),
          (None, "-", "-"),               # Separator
          (S(B, "dxfin"),  T["Import &dxf"], T["Imports a dxf file"]),
          (S(B, "sykin"),  T["&Import syk"], T["Imports a syk file"]),
          (S(B, "brkin"),  T["&Import brk"], T["Imports a brk file"]),
          (S(B, "synin"),  T["Import &syn"], T["Imports points from a syn file"]),
          (S(B, "mhkin"),  T["Import &mhk"], T["Imports a mhk profile file"]),
          (None, "-", "-"),               # Separator
          (S(B, "dxfout"), T["Export &dxf"],   T["Exports a dxf file"]),
          (S(B, "sykout"), T["&Export syk"],   T["Exports a syk file"]),
          (S(B, "brkout"), T["&Export brk"],   T["Exports a brk file"]),
          (S(B, "pilout"), T["Export &Image"], T["Exports a raster image"]),
          (S(B, "pdfout"), T["Plot to PDF"],   T["Plots the drawing to a PDF file"]),
          (None, "-", "-"),
          (S(B, "purge"),  T["&Purge"], T["Removes unused items, such as layers, from drawing"]),
#
#-------recent files
#
#        for w in thanfiles.thanFilGetRecent():
#            m.append((S(self.__menuRecent, w), w, w))
          (None, "-", "-"),               # Separator
          (None, "-", "-"),
          (S(B, "quit"), T["E&xit"], "Terminate "+thanvers.thanCadName, "darkred"),
  ]

        m["Edit"] = \
  [ (None, T["&Edit"], ""),            # Menu Title
          (S(B, "Undo"),      T["&Undo"],                 "Reverses the most recent action: U"),
          (S(B, "Redo"),      T["&Redo"],                 "Reverses the effects of the previous UNDO or U command: REDO"),
          (None, "-", "-"),               # Separator
          (S(B, "cutclip"),   T["Cu&t"],                  "Moves elements to Clipboard"),
          (S(B, "copyclip"),  T["&Copy"],                 "Copies elements to Clipboard"),
          (S(B, "copybase"),  T["C&opy with Base Point"], "Copies elements to Clipboard"),
          (S(B, "pasteclip"), T["&Paste"],                "Pastes elements from Clipboard"),
          (S(B, "pasteorig"), T["P&aste to Original Coordinates"], "Pastes elements from Clipboard"),
          (None, "-", "-"),               # Separator
          (S(B, "select"),    T["&Select"], "Selects elements"),
  ]

        m["View"] = \
        [  (None, T["&View"], ""),           # Menu Title
          (S(B, "zoomwin"),     T["Zoom &Window"],    "Zooms into a window"),
          (S(B, "zoomall"),     T["Zoom &All"],       "Zooms to show entire drawing"),
          (S(B, "zoomsel"),     T["Zoom &Selection"], "Zooms to show all selected elements"),
          (S(B, "zoomrelative"),T["Zoom R&elative"],  "Zooms by factor relative to current window"),
          (S(B, "zoomrealtime"),T["&Zoom real time"], "Zooms dragging the mouse"),
          (None, "-", "-"),               # Separator
          (S(B, "panrelative"), T["P&an Relative"],   "Moves the view window"),
          (S(B, "panrealtime"), T["&Pan real time"],  "Moves dragging the mouse"),
          (None, "-", "-"),               # Separator
          (S(B, "redraw"),      T["&Redraw"],         "Regenerates screen"),
          (S(B, "regen"),       T["Re&gen"],          "Regenerates screen"),
          (None, "-", "-"),               # Separator
          (S(B, "highlight"),   T["&Highlight"],      "Makes small object visible"),
        ]

        m["Insert"] = \
  [ (None, T["&Insert"], ""),          # Menu Title
          (S(B, "imageattach"),  T["Raster &Image"],  "Inserts a new image to the current drawing"),
          (S(B, "Image"),        T["I&mage Manager"], "Manages many images at once"),
  ]

        m["Format"] = \
        [ (None, T["F&ormat"], ""),          # Layer Title
          (S(B, "ddlmodes"), T["&Layer"],      "Manipulates layers"),
          (S(B, "style"),    T["&Text Style"], "Manipulates text styles"),
  ]

        m["Tools"] = \
        [ (None, T["&Tools"], ""),           # Menu Title
          (S(B, "dist"), T["&Distance"],  "Computes and displays the distance and angle between 2 points"),
          (S(B, "area"), T["&Area"],      "Computes and displays the area of a closed polygon defined by points"),
          (S(B, "angle"),T["&Angle"],     "Computes and displays the angle between 2 lines defined by 3 points"),
          (S(B, "id"),   T["&Id Point"],  "Displays the coordinates of a point"),
          (S(B, "list"), T["&List"],      "Displays information about an element"),
          (None, "-", "-"),
          (S(B, "dsettings"), T["Drafting &Settings"],  "Chooses the drafting modes end, mid etc."),
          (S(B, "find"),      T["&Find text"], "Zooms to a text containing user defined text string"),
          (None, "-", "-"),
          (S(B, "centroid"),  T["&Find centroid"], "Finds the centroid of a set of lines"),
          (S(B, "hull"),      T["&Find convex hull"],   "Finds the convex hulls of a set of lines"),
          (S(B, "simplify"),  T["&Simplify line"], "Approximates the lines with fewer points"),
          (None, "-", "-"),
          (S(B, "script"),  T["&Run script"], "Executes ThanCad commands from file"),
        ]

        m["Draw"] = \
        [ (None, T["&Draw"], ""),            # Menu Title
          (S(B, "line"),      T["&Line"],      "Draws a line"),
          (S(B, "rectangle"), T["&Rectangle"], "Draws a closed line in the shape of a rectangle"),
          (S(B, "polygon"),   T["&Polygon"],   "Draws a closed line in the shape of a polygon filled with colour"),
          (S(B, "circle"),    T["&Circle"],    "Draws a circle"),
          (S(B, "arc"),       T["&Arc"],       "Draws a circular arc"),
          (S(B, "point"),     T["&Point"],     "Draws a point"),
          (S(B, "dtext"),     T["&Text"],      "Draws text"),
          (None, "-", "-"),
          (S(B, "pnamed"),    T["&Named Point"],"Draws a point with name"),
          (S(B, "road"),      T["R&oad"],       "Draws a road"),
          (S(B, "hatchopen"), T["Hatch Open"],  T["Create hatch between disjoint lines"]),
          (None, "-", "-"),
          (S(B, "dimali"), T["&Dimension aligned"], "Draws a dimension aligned to coordinates"),
          (None, "-", "-"),
          (S(B, "curve"),     T["&Curve"],     "Transforms a line to a curve"),
        ]

        m["Engineering"] = \
        [ (None, T["&Engineering"], ""),        # Menu Title
          (S(B, "EngGrid"),   T["&Grid"],        "Draws an engineering grid"),
          (S(B, "EngMapRect"),T["&Rectify Map"], "Rectifies a raster topographic map"),
          (S(B, "EngTrace"),  T["&Trace"],       "Traces a curve in a bitmap raster image"),
          (None, "-", "-"),
          (S(B, "dtmmake"),   T["Create &DTM"],   T["Creates a DTM from 3D lines"]),
          (S(B, "dtmz"),      T["DTM &Z"],        T["Computes and shows the z coordinate at an arbitrary point"]),
          (S(B, "dtmpoints"), T["Add Z to &Points"], T["Supplies z coordinates to existing points"]),
          (S(B, "dtmline"),   T["Add Z to &Lines"],  T["Supplies z coordinates to existing polylines"]),
          (S(B, "triangulation"),   T["Triangulation"], T["Creates and manages triangulation from (2D) points and lines."]),
          (None, "-", "-"),
          (S(B, "engprofile"),    T["Line Pro&file"], T["Creates the profile of a (3D) line"]),
        ]

        m["Modify"] = \
        [ (None, T["&Modify"], ""),             # Menu Title
          (S(B, "chprop"),     T["C&hange layer"], T["Changes layer of selected elements"]),
          (None, "-", "-"),
          (S(B, "erase"),      T["&Erase"],        T["Deletes selected elements"]),
          (S(B, "rotate"),     T["&Rotate"],       T["Rotates selected elements"]),
          (S(B, "scale"),      T["Sc&ale"],        T["Scales selected elements"]),
          (S(B, "move"),       T["&Move"],         T["Moves selected elements"]),
          (S(B, "copy"),       T["&Copy"],         T["Copies selected elements"]),
          (S(B, "mirror"),     T["M&irror"],       T["Mirrors selected elements with repect to 2d axis"]),
          (None, "-", "-"),
          (S(B, "offset"),     T["&Offset"],       T["Copies object parallel to itself"]),
          (S(B, "break"),      T["&Break"],        T["Breaks an element into 2 pieces"]),
          (S(B, "trim"),       T["&Trim"],         T["Explode 1 or more elements to smaller objects"]),
          (S(B, "filet"),      T["&Filet"],        T["Cuts elements with other elements being the cutting edges"]),
          (S(B, "Join"),       T["&Join"],         T["Joins 2 or more adjacent lines"]),
          (S(B, "explode"),    T["E&xplode"],      T["Explode 1 or more elements to smaller objects"]),
          (S(B, "reverse"),    T["Re&verse"],      T["Reverses the orientation of direction of lines"]),
          (None, "-", "-"),
          (S(B, "ddedit"),     T["E&dit Text"],    T["Lets the user edit any text interactively"]),
        ]

        m["Research"] = \
        [ (None, T["&Research"], ""),           # Menu Title
          (S(B, "EduRectangle"), T["Mark &Region"],   "Draws a rectangle with comments"),
          (S(B, "EduEdit"),      T["&Edit"],          "Edit the comments"),
        ]

        m["Developer"] = \
        [ (None, T["D&eveloper"], ""),          # Menu Title
          (S(B, "devfont"), T["Show &font"],         "Developer font debugging"),
          (S(B, "devcm"),   T["Show &dimensions"],   "Developer window debugging"),
          (S(B, "devcmd"),  T["&Save CMD text"],     "Save the text of the command window"),
          (S(B, "devtrans"),T["&Translation report"],"Save translation status to a file"),
        ]


        m["Window"] = \
        [ (None, T["&Window"], ""),          # Menu Title
#  m.append((self.thanParent.thanGudSetFocus, thanvers.thanCadName, thanvers.thanCadName+" main window"))
#        for w, f in thanfiles.thanFilGetOpened():
#            m.append((w.thanGudSetFocus, f, f))
        ]

        m["Help"] = \
  [ (None, T["&Help"], "", None, "help"),            # Menu Title
          (S(B, "help"),  T["&Introduction"], "Introduction to "+thanvers.thanCadName),
          (S(B, "gpl"),   T["&GPL"],          "Gnu General Public License"),
          (S(B, "about"), T["&About"],        "Information about "+thanvers.thanCadName)
  ]
        return s, m


def thanMainMenus(B):
        "Creates a description of the main window menus in a list."
        S = p_ggen.ThanStub
        s = "File Window Help".split()
        m = {}
        m["File"] = \
        [ (None, "&File", ""),            # Menu Title
          (S(B, "new"),    "&New",  "Makes an empty drawing"),
#          (S(B, "new"),    u"& ",  "Makes an empty drawing"),
          (S(B, "open"),   "&Open", "Opens an existing drawing"),
          (None, "-", "-"),               # Separator
          (S(B, "sykin"),  "&Import syk", "Imports a syk file"),
          (S(B, "dxfin"),  "Import &dxf", "Imports a dxf file"),
          (S(B, "sykout"), "&Export syk", "Exports a syk file"),
          (S(B, "dxfout"), "Export &dxf", "Exports a dxf file"),
          (None, "-", "-"),               # Separator
#
#-------recent files
#
#        for w in thanfiles.thanFilGetRecent():
#            m.append((S(self.__menuRecent, w), w, w))
          (None, "-", "-"),               # Separator
          (S(B, "quit"), "E&xit", "Terminate "+thanvers.thanCadName, "darkred"),
        ]

        m["Window"] = \
        [ (None, "&Window", ""),          # Menu Title
#       m.append((self.thanParent.thanGudSetFocus, thanvers.thanCadName, thanvers.thanCadName+" main window"))
#        for w, f in thanfiles.thanFilGetOpened():
#            m.append((w.thanGudSetFocus, f, f))
        ]

        m["Help"] = \
        [ (None, "&Help", ""),            # Menu Title
          (S(B, "help"),  "&Introduction", "Introduction to "+thanvers.thanCadName),
          (S(B, "gpl"),   "&GPL",          "Gnu General Public License"),
          (S(B, "about"), "&About",        "Information about "+thanvers.thanCadName)
        ]
        return s, m

if __name__ == "__main__":
    import p_ggen
    thanvers = p_ggen.Struct()
    thanvers.thanCadName = "GREAT ThanCad"
    thanMenusSeq, thanMenus = thanStandardMenus()
    for m in thanMenusSeq: assert m in thanMenus
    for m in thanMenus: assert m in thanMenusSeq
    print thanMenusSeq
    for m in thanMenusSeq:
        print m
        for mm in thanMenus[m]: print "      ", mm
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.