pyqonsole
view pyqonsole/session.py @ 188:f353f5aba78e
copyright update, remove __revision__
| author | "Sylvain <syt@logilab.fr>" |
|---|---|
| date | Fri, 09 Mar 2007 14:05:04 +0100 |
| parents | b1ab95c82600 |
| children |
line source
1 # Copyright (c) 2005-2007 LOGILAB S.A. (Paris, FRANCE).
2 # Copyright (c) 2005-2006 CEA Grenoble
3 # http://www.logilab.fr/ -- mailto:contact@logilab.fr
4 #
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the CECILL license, available at
7 # http://www.inria.fr/valorisation/logiciels/Licence.CeCILL-V2.pdf
8 #
9 """Provides the Session class. Sessions are combinations of PtyProcess and
10 Emulation.
12 The stuff in here does not really belong to the terminal emulation framework. It
13 serves it's duty by providing a single reference to TEPTy/Emulation pairs. In
14 fact, it is only there to demonstrate one of the abilities of the framework:
15 multible sessions.
17 Based on the konsole code from Lars Doelle.
19 @author: Lars Doelle
20 @author: Sylvain Thenault
21 @copyright: 2003, 2005-2007
22 @organization: Logilab
23 @license: CECILL
24 """
26 import os
28 from pyqonsole.qtwrapper import qt, QObject, SIGNAL, QTimer
30 from pyqonsole import Signalable, pty_, emulation, emuVt102
34 class Session(Signalable, QObject):
35 """A Session is a combination of one PTyProcess and one Emulation instances
36 """
38 SILENCE_TIMEOUT = 10000 # milliseconds
40 def __init__(self, gui, pgm, args, term, sessionid='session-1', cwd=None):
41 super(Session, self).__init__()
42 self.monitor_activity = False
43 self._monitor_silence = False # see the property below
44 self.master_mode = False
45 # FIXME: using the indices here is propably very bad. We should use a
46 # persistent reference instead.
47 self.schema_no = 0
48 self.font_no = 3
49 self.app_id = "qonsole"
50 self.icon_name = 'openterm'
51 self.icon_text = 'qonsole'
52 self.state_icon_name = ''
53 self.title = ''
54 self.user_title = ''
55 self.te = gui
56 self.pgm = pgm
57 self.args = args
58 self.term = term
59 self.session_id = sessionid
60 self.cwd = cwd
61 self.sh = pty_.PtyProcess()
62 self.em = emuVt102.EmuVt102(self.te)
63 self.monitor_timer = QTimer(self)
64 self.sh.setSize(self.te.lines, self.te.columns)
65 self.sh.myconnect('block_in', self.em.onRcvBlock)
66 self.sh.myconnect('done', self.done)
67 self.em.myconnect('imageSizeChanged', self.sh.setSize)
68 self.em.myconnect('sndBlock', self.sh.sendBytes)
69 self.em.myconnect('changeTitle', self.setUserTitle)
70 self.em.myconnect('notifySessionState', self.notifySessionState)
71 self.connect(self.monitor_timer, SIGNAL('timeout()'), self.monitorTimerDone)
73 def __del__(self):
74 self.sh.mydisconnect('done', self.done)
76 def setMonitorSilence(self, monitor):
77 if self._monitor_silence == monitor:
78 return
79 self._monitor_silence = monitor
80 if monitor:
81 self.monitor_timer.start(self.SILENCE_TIMEOUT, True)
82 else:
83 self.monitor_timer.stop()
84 def getMonitorSilence(self):
85 return self._monitor_silence
86 monitor_silence = property(getMonitorSilence, setMonitorSilence)
88 def run(self):
89 cwd_save = os.getcwd()
90 if self.cwd:
91 os.chdir(self.cwd)
92 self.sh.run(self.pgm, self.args, self.term, True)
93 if self.cwd:
94 os.chdir(cwd_save)
95 # We are reachable via kwrited XXX not needed by pyqonsole ?
96 self.sh.setWriteable(False)
99 def setUserTitle(self, what, caption):
100 """
101 what=0 changes title and icon
102 what=1 only icon
103 what=2 only title
104 """
105 if what in (0, 2):
106 self.user_title = caption
107 if what in (0, 1):
108 self.icon_text = caption
109 self.myemit('updateTitle', ())
111 def fullTitle(self):
112 if self.user_title:
113 return '%s - %s' % (self.user_title, self.title)
114 return self.title
116 def testAndSetStateIconName(self, newname):
117 if (newname != self.state_icon_name):
118 self.state_icon_name = newname
119 return True
120 return False
122 def monitorTimerDone(self):
123 self.myemit('notifySessionState', (emulation.NOTIFYSILENCE,))
124 self.monitor_timer.start(self.SILENCE_TIMEOUT, True)
126 def notifySessionState(self, state):
127 if state == emulation.NOTIFYACTIVITY:
128 if self.monitor_silence:
129 self.monitor_timer.stop()
130 self.monitor_timer.start(self.SILENCE_TIMEOUT, True)
131 if not self.monitor_activity:
132 return
133 self.myemit('notifySessionState', (state,))
135 def done(self, status):
136 self.myemit('done', (self, status,))
138 def terminate(self):
139 # XXX
140 pass
142 def sendSignal(self, signal):
143 return self.sh.kill(signal)
145 def setConnect(self, connected):
146 self.em.setConnect(connected)
148 def keymap(self):
149 return self.em.keymap()
151 def setKeymap(self, kn):
152 self.em.setKeymap(kn)
154 def setHistory(self, history):
155 self.em.setHistory(history)
157 def history(self):
158 return self.em.history()
