Advertisement
Guest User

Doesn't Work

a guest
Mar 5th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 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. # Command-Function ist nicht in der Klasse
  29. def Command(cmd, out=1):
  30.     GetBuffer = MainApp()
  31.     # Print Command
  32.     if out == 1:
  33.         TextBufferCommandInput = GetBuffer.TextViewCommandInput.get_buffer()
  34.         TextBufferCommandInput.insert_at_cursor(cmd + "\n")
  35.     # Send Command
  36.     process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
  37.         stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
  38.         close_fds=True, universal_newlines=True)
  39.     output = process.stdout.read()
  40.  
  41.     # Print Command-Output
  42.     if out == 1:
  43.         TextBufferCommandOutput = GetBuffer.TextViewCommandOutput.get_buffer()
  44.         TextBufferCommandOutput.insert_at_cursor(cmd + "\n")
  45.  
  46. def Test():
  47.     cmd = "ls -l"
  48.     Command(cmd)
  49.  
  50.  
  51.  
  52. if __name__ == "__main__":
  53.     StartMainApp = MainApp()
  54.     MainApp.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement