Advertisement
Guest User

Works

a guest
Mar 5th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from gi.repository import Gtk
  5. import subprocess
  6.  
  7. class MainApp:
  8.     def __init__(self):
  9.  
  10.         # Build our Interface from the XML/Glade file
  11.         gladefile = "MainWindow.glade"
  12.         try:
  13.             self.builder = Gtk.Builder()
  14.             self.builder.add_from_file(gladefile)
  15.         except:
  16.             print("Failed to load Glade file: %s" % gladefile)
  17.  
  18.         # Connect signals
  19.         self.builder.connect_signals(self)
  20.  
  21.         # Get the widgets
  22.         self.window = self.builder.get_object("MainWindow")
  23.  
  24.         # TextViews
  25.         self.TextViewCommandInput = self.builder.get_object("TextViewCommandInput")
  26.         self.TextViewCommandOutput = self.builder.get_object("TextViewCommandOutput")
  27.  
  28.     def Command(self, cmd, out=1):
  29.         # Print Command
  30.         if out == 1:
  31.             self.TextBufferCommandInput = self.TextViewCommandInput.get_buffer()
  32.             self.TextBufferCommandInput.insert_at_cursor(cmd + "\n")
  33.         # Send Command
  34.         process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
  35.             stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
  36.             close_fds=True, universal_newlines=True)
  37.         output = process.stdout.read()
  38.  
  39.         # Print Command-Output
  40.         if out == 1:
  41.             self.TextBufferCommandOutput = self.TextViewCommandOutput.get_buffer()
  42.             self.TextBufferCommandOutput.insert_at_cursor(output + "\n")
  43.            
  44.     def Test():
  45.         cmd = "ls -l"
  46.         Command(cmd)
  47.        
  48. if __name__ == "__main__":
  49.     StartMainApp = MainApp()
  50.     MainApp.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement