~barry/ubuntu/natty/mgltools-viewerframework/bug-685476

« back to all changes in this revision

Viewing changes to ViewerFramework/basicCommand.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2009-05-16 00:51:33 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090516005133-fh1r2uu2fpcb7y2d
Tags: 1.5.4.cvs.20090528-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
   - ResetUndoCommand.
20
20
"""
21
21
 
22
 
# $Header: /opt/cvs/python/packages/share1.5/ViewerFramework/basicCommand.py,v 1.125 2009/04/29 23:10:51 annao Exp $
 
22
# $Header: /opt/cvs/python/packages/share1.5/ViewerFramework/basicCommand.py,v 1.117.2.2 2009/02/26 18:28:23 sargis Exp $
23
23
#
24
 
# $Id: basicCommand.py,v 1.125 2009/04/29 23:10:51 annao Exp $
 
24
# $Id: basicCommand.py,v 1.117.2.2 2009/02/26 18:28:23 sargis Exp $
25
25
#
26
26
import os, sys, subprocess
27
27
 
30
30
from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, \
31
31
     LoadButton, kbScrolledListBox
32
32
from mglutil.util.packageFilePath import findFilePath, \
33
 
     findModulesInPackage, getResourceFolderWithVersion
 
33
     findModulesInPackage,findAllPmvPackages, getResourceFolderWithVersion
34
34
 
35
35
import types, Tkinter, Pmw, os, sys, traceback
36
36
from string import join
40
40
import string
41
41
commandslist=[]
42
42
cmd_docslist={}
43
 
 
44
 
def findAllVFPackages():
45
 
    """Returns a list of package names found in sys.path"""
46
 
    packages = {}
47
 
    for p in ['.']+sys.path:
48
 
        flagline = []
49
 
        if not os.path.exists(p) or not os.path.isdir(p):
50
 
            continue
51
 
        files = os.listdir(p)
52
 
        for f in files:
53
 
            pdir = os.path.join(p, f)
54
 
            if not os.path.isdir(pdir):
55
 
                continue
56
 
            if os.path.exists( os.path.join( pdir, '__init__.py')) :
57
 
            
58
 
                fptr =open("%s/__init__.py" %pdir)
59
 
                Lines = fptr.readlines()
60
 
                flagline =filter(lambda x:x.startswith("packageContainsVFCommands"),Lines)
61
 
                if not flagline ==[]:
62
 
                    if not packages.has_key(f):
63
 
                        packages[f] = pdir
64
 
    return packages
65
 
 
66
43
class  UndoCommand(Command):
67
44
    """pops undo string from the stack and executes it in the ViewerFrameworks
68
45
    scope
494
471
        self.vf.GUI.ROOT.config(cursor='watch')
495
472
        self.vf.GUI.ROOT.update()
496
473
        if self.allPack == {}:
497
 
            self.allPack = findAllVFPackages()
 
474
            self.allPack = findAllPmvPackages()
498
475
        val = self.showForm('loadCmds', force=1,modal=0,blocking=0)
499
476
        ebn = self.cmdForms['loadCmds'].descr.entryByName
500
477
#        docb=ebn['docbutton']['widget']
887
864
        doc = []
888
865
        self.filenames={}
889
866
        self.allPack={}
890
 
        self.allPack=findAllVFPackages()
 
867
        self.allPack=findAllPmvPackages()
891
868
        if package is None: return [], []
892
869
        if not self.filenames.has_key(package):
893
870
            pack=self.allPack[package]
1700
1677
        if self.vf.logMode == 'no':
1701
1678
            self.vf.warningMsg("No log information because logMode was set to no.")
1702
1679
            return
1703
 
        newfile = self.vf.askFileSave(types = [('all files','*.py')],
 
1680
        newfile = self.vf.askFileSave(types = [('all files','*.*')],
1704
1681
                                      title = 'Save Session in File:')
1705
1682
        if not newfile is None:
1706
1683
            self.doitWrapper(newfile, redraw=0)
2030
2007
                self.vf.GUI.ROOT.after(10,self.vf.GUI.quit_cb)
2031
2008
 
2032
2009
 
2033
 
 
2034
 
class customAnimationCommand(Command):
2035
 
    """Command to start Custom Animation notebook widget
2036
 
    """
2037
 
 
2038
 
    def __init__(self, func=None):
2039
 
        Command.__init__(self, func)
2040
 
        self.root = None
2041
 
        self.animNB = None
2042
 
        
 
2010
class ScenarioCommand(Command):
 
2011
 
 
2012
    """Command to start scenario application """
2043
2013
    def guiCallback(self):
2044
 
        self.startCustomAnim_cb()
 
2014
        self.startScenario_cb()
2045
2015
 
2046
2016
 
2047
2017
    def __call__(self, **kw):
2048
 
        """None <- customAnimation"""
 
2018
        """None <- addScenario"""
2049
2019
        add = kw.get('add', None)
2050
2020
        if add is None:
2051
2021
            add = 1
2052
2022
        else: assert add in (0, 1)
2053
 
        if self.vf.GUI.toolbarCheckbuttons.has_key('customAnimation'):
2054
 
            self.vf.GUI.toolbarCheckbuttons['customAnimation']['Variable'].set(add)
2055
 
        self.startCustomAnim_cb()
2056
 
 
2057
 
 
2058
 
    def startCustomAnim_cb(self):
2059
 
        on = self.vf.GUI.toolbarCheckbuttons['customAnimation']['Variable'].get()
2060
 
        if on:
2061
 
            if not self.animNB:
2062
 
                from Pmv.scenarioInterface.animationGUI import AnimationNotebook
2063
 
                self.root = Tkinter.Toplevel()
2064
 
                self.root.title('Custom Animation')
2065
 
                self.root.protocol("WM_DELETE_WINDOW", self.hide_cb)
2066
 
                vi = self.vf.GUI.VIEWER
2067
 
                self.animNB = AnimationNotebook(self.vf, self.root)
 
2023
        if self.vf.GUI.toolbarCheckbuttons.has_key('scenario'):
 
2024
            self.vf.GUI.toolbarCheckbuttons['scenario']['Variable'].set(add)
 
2025
        self.startScenario_cb()
 
2026
 
 
2027
 
 
2028
    def startScenario_cb(self):
 
2029
        if hasattr(self.vf, "director"):
 
2030
            on = self.vf.GUI.toolbarCheckbuttons['scenario']['Variable'].get()
 
2031
            if on:
 
2032
                self.vf.director.start()
 
2033
                if self.vf.director.scenarios.has_key("DejaVuScenario"):
 
2034
                    if not self.vf.GUI.VIEWER.GUI.shown:
 
2035
                        self.vf.GUI.showHideDejaVuGUI()
 
2036
                        if self.vf.director.gui is not None:
 
2037
                            self.vf.director.gui.root.lift()
2068
2038
            else:
2069
 
                self.show_cb()
2070
 
        else:
2071
 
            self.hide_cb()
2072
 
 
2073
 
    def hide_cb(self):
2074
 
        if self.root:
2075
 
            self.root.withdraw()
2076
 
            self.vf.GUI.toolbarCheckbuttons['customAnimation']['Variable'].set(0) 
2077
 
 
2078
 
    def show_cb(self, event=None):
2079
 
        if self.root:
2080
 
            self.root.deiconify()
2081
 
            self.vf.GUI.toolbarCheckbuttons['customAnimation']['Variable'].set(1)
 
2039
                if self.vf.director.gui:
 
2040
                    self.vf.director.gui.root.withdraw()
 
2041
 
2082
2042
 
2083
2043
    def onAddCmdToViewer(self):
2084
 
        pass
2085
 
 
2086
 
    
 
2044
        from scenario.director import Director
 
2045
        director = self.vf.director = Director()
 
2046
        if self.vf.hasGui:
 
2047
            import DejaVu
 
2048
            if DejaVu.enableScenario:
 
2049
                from DejaVu.scenarioInterface import DejaVuScenario
 
2050
                scenario = DejaVuScenario(self.vf.GUI.VIEWER, director)
 
2051
                director.addScenario("DejaVuScenario", scenario)
 
2052
 
 
2053
 
 
2054
sceanrioCommandGuiDescr = {'widgetType':'Menu', 'barName':'Toolbar',
 
2055
                        'buttonName':'scenario'}
 
2056
 
2087
2057