xterm_widget.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2012, Dorian Scholz
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of Willow Garage, Inc. nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 import os
36 
37 from python_qt_binding.QtCore import QProcess, QTimer, Signal
38 from python_qt_binding.QtGui import QX11EmbedContainer
39 
40 
41 class XTermWidget(QX11EmbedContainer):
42  xterm_cmd = '/usr/bin/xterm'
43  close_signal = Signal()
44 
45  def __init__(self, parent=None, script_path=None):
46  # possible use os to do better justice to script path??
47  if script_path:
48  xterm_cmd += " -e $SHELL -c 'source %s; $SHELL'" % os.path.abspath(script_path)
49  super(XTermWidget, self).__init__(parent)
50  self.setObjectName('XTermWidget')
51  self._process = QProcess(self)
52  self._process.finished.connect(self.close_signal)
53  # let the widget finish init before embedding xterm
54  QTimer.singleShot(100, self._embed_xterm)
55 
56  def _embed_xterm(self):
57  args = ['-into', str(self.winId())]
58  self._process.start(self.xterm_cmd, args)
59  if self._process.error() == QProcess.FailedToStart:
60  print("failed to execute '%s'" % self.xterm_cmd)
61 
62  def shutdown(self):
63  self._process.kill()
64  self._process.waitForFinished()
65 
66 
68  return os.path.isfile(XTermWidget.xterm_cmd)
69 
70 if __name__ == '__main__':
71  from PyQt4.QtGui import QApplication
72  app = QApplication([])
73  xt = XTermWidget()
74  app.exec_()
def __init__(self, parent=None, script_path=None)
Definition: xterm_widget.py:45


rqt_shell
Author(s): Dorian Scholz, Kunal Tyagi
autogenerated on Fri Apr 23 2021 02:35:36