Created
March 7, 2012 09:04
-
-
Save sh4nks/1992064 to your computer and use it in GitHub Desktop.
Text in einem TextBuffer einfügen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") | |
def onWindowDestroy(self, widget, data=None): | |
Gtk.main_quit() | |
def btnSendclicked(self, button, data=None): | |
self.TestCommand() | |
def main(self): | |
self.window.show_all() | |
Gtk.main() | |
def Command(self, cmd, out=1): | |
# Print Command | |
if out == 1: | |
self.TextBufferCommandInput = self.TextViewCommandInput.get_buffer() | |
self.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: | |
self.TextBufferCommandOutput = self.TextViewCommandOutput.get_buffer() | |
self.TextBufferCommandOutput.insert_at_cursor(output + "\n") | |
def TestCommand(self): | |
cmd = "ls -l" | |
self.Command(cmd) | |
if __name__ == "__main__": | |
StartMainApp = MainApp() | |
StartMainApp.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Not working | |
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") | |
def onWindowDestroy(self, widget, data=None): | |
Gtk.main_quit() | |
def btnSendclicked(self, button, data=None): | |
TestCommand() | |
def main(self): | |
self.window.show_all() | |
Gtk.main() | |
def Command(cmd, out=1): | |
GetBuffer = MainApp() | |
# Print Command | |
if out == 1: | |
GetBuffer.TextBufferCommandInput = GetBuffer.TextViewCommandInput.get_buffer() | |
GetBuffer.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: | |
GetBuffer.TextBufferCommandOutput = GetBuffer.TextViewCommandOutput.get_buffer() | |
GetBuffer.TextBufferCommandOutput.insert_at_cursor(output + "\n") | |
def TestCommand(): | |
cmd = "ls -l" | |
Command(cmd) | |
if __name__ == "__main__": | |
StartMainApp = MainApp() | |
StartMainApp.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<interface> | |
<!-- interface-requires gtk+ 3.0 --> | |
<object class="GtkWindow" id="MainWindow"> | |
<property name="can_focus">False</property> | |
<property name="has_resize_grip">False</property> | |
<signal name="destroy" handler="onWindowDestroy" swapped="no"/> | |
<child> | |
<object class="GtkBox" id="vbox"> | |
<property name="width_request">400</property> | |
<property name="height_request">400</property> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="border_width">5</property> | |
<property name="orientation">vertical</property> | |
<property name="homogeneous">True</property> | |
<child> | |
<object class="GtkScrolledWindow" id="scrolledwindow1"> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="shadow_type">in</property> | |
<child> | |
<object class="GtkTextView" id="TextViewCommandInput"> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="editable">False</property> | |
</object> | |
</child> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">0</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkScrolledWindow" id="scrolledwindow2"> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="shadow_type">in</property> | |
<child> | |
<object class="GtkTextView" id="TextViewCommandOutput"> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="editable">False</property> | |
</object> | |
</child> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">1</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton" id="btnSend"> | |
<property name="label" translatable="yes">Senden</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<property name="use_action_appearance">False</property> | |
<signal name="clicked" handler="btnSendclicked" swapped="no"/> | |
</object> | |
<packing> | |
<property name="expand">False</property> | |
<property name="fill">True</property> | |
<property name="position">2</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</interface> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment