Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from gi.repository import Gtk
- import subprocess
- class MainApp:
- def __init__(self):
- # Build our Interface from the XML/Glade file
- gladefile = "MainWindow.glade"
- try:
- self.builder = Gtk.Builder()
- self.builder.add_from_file(gladefile)
- except:
- print("Failed to load Glade file: %s" % gladefile)
- # Connect signals
- self.builder.connect_signals(self)
- # Get the widgets
- self.window = self.builder.get_object("MainWindow")
- # TextViews
- self.TextViewCommandInput = self.builder.get_object("TextViewCommandInput")
- self.TextViewCommandOutput = self.builder.get_object("TextViewCommandOutput")
- # Command-Function ist nicht in der Klasse
- def Command(cmd, out=1):
- GetBuffer = MainApp()
- # Print Command
- if out == 1:
- TextBufferCommandInput = GetBuffer.TextViewCommandInput.get_buffer()
- TextBufferCommandInput.insert_at_cursor(cmd + "\n")
- # Send Command
- process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- close_fds=True, universal_newlines=True)
- output = process.stdout.read()
- # Print Command-Output
- if out == 1:
- TextBufferCommandOutput = GetBuffer.TextViewCommandOutput.get_buffer()
- TextBufferCommandOutput.insert_at_cursor(cmd + "\n")
- def Test():
- cmd = "ls -l"
- Command(cmd)
- if __name__ == "__main__":
- StartMainApp = MainApp()
- MainApp.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement