/usr/share/pyshared/InterfaceTK/Interp.py is in eficas 2.0.3-1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | # -*- coding: utf-8 -*-
# CONFIGURATION MANAGEMENT OF EDF VERSION
# ======================================================================
# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
# 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.
#
# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
#
#
# ======================================================================
import Tkinter,ScrolledText
import os, sys, string, traceback
import code
sys.ps1 = ">>> "
sys.ps2 = "... "
class PythonInterpreter( code.InteractiveConsole):
def __init__( self, text, namespace = None):
code.InteractiveConsole.__init__( self, namespace)
self.text = text
def showtraceback( self):
start = self.text.pos + " - 1 lines"
code.InteractiveConsole.showtraceback( self)
end = self.text.pos
self.text.tag_add( "exception", start, end)
class InterpWindow(Tkinter.Toplevel):
def __init__(self,namespace, parent=None):
Tkinter.Toplevel.__init__(self,parent)
self._initTkWidgets()
self.stdout = self.stderr = self
self.pos = '1.0'
self.history = [ '' ]
self.hpos = 0
self.tabCount = 0
self.shell = PythonInterpreter( self,namespace)
self.write("Python %s on %s\n%s\n(%s)\n" %
(sys.version, sys.platform, sys.copyright,
self.__class__.__name__))
self.write( sys.ps1)
self.text.focus_set()
def _initTkWidgets( self):
self.text = ScrolledText.ScrolledText( self, bg = "white",fg="black", wrap="word")
self.text.pack( fill='both', expand = 1)
self.text.bind( '<KeyPress>', self.clearMsg)
self.text.bind( '<Return>', self.inputhandler)
self.text.bind( '<KP_Enter>', self.inputhandler)
self.text.bind( '<Up>', self.uphistory)
self.text.bind( '<Down>', self.downhistory)
self.text.bind( '<Control-a>', self.goto_sol)
self.text.bind( '<Control-d>', self.sendeof)
self.text.tag_config("exception", foreground = "red")
def swapStdFiles(self):
sys.stdout,self.stdout = self.stdout,sys.stdout
sys.stderr,self.stderr = self.stderr,sys.stderr
def write(self, data):
self.text.insert("end", data)
self.pos = self.text.index("end - 1 char")
self.text.yview_pickplace("end")
def tag_add( self, tag, start, end):
self.text.tag_add( tag, start, end)
def inputhandler(self, *args):
# Remove any extraneous stuff
self.text.delete( self.pos + " lineend", "end")
# Now get the line
line = self.text.get(self.pos, "end - 1 char")
self.text.insert("end", "\n")
self.pos = self.text.index("end")
self.addHistory( line)
self.swapStdFiles()
if self.shell.push( line):
self.write(sys.ps2)
else:
self.write(sys.ps1)
self.swapStdFiles()
self.text.mark_set("insert", "end")
return "break"
def addHistory( self, line):
if line:
self.history.insert( len( self.history) - 1, line)
self.hpos = len( self.history) - 1
def sendeof(self, *args):
self.destroy()
return "break"
def uphistory(self, event=None):
if not self.history: return "break"
if self.hpos > 0:
self.hpos = self.hpos - 1
line = self.history[ self.hpos]
self.text.delete( self.pos, "end")
self.text.insert( self.pos, line)
return "break"
def downhistory( self, event=None):
if not self.history: return "break"
if self.hpos < (len( self.history) - 1):
self.hpos = self.hpos + 1
line = self.history[ self.hpos]
self.text.delete( self.pos, "end")
self.text.insert( self.pos, line)
return "break"
def goto_sol( self, event=None):
"""
Met en mode edition la ligne courante
"""
self.text.mark_set( 'insert', 'insert linestart + 4 chars')
return "break"
def clearMsg( self, event=None):
index = self.text.index( "insert")
self.text.delete( "insert lineend", "end")
self.tabCount = 0
if __name__ == "__main__":
app = Tkinter.Tk()
d={'a':1}
def go():
InterpWindow(d,parent=app)
Tkinter.Button(app,text="Interp",command=go).pack()
Tkinter.Button(app,text="Quit",command=app.destroy).pack()
app.mainloop()
|