Skip to content

Instantly share code, notes, and snippets.

@killown
Last active April 2, 2017 17:00
Show Gist options
  • Save killown/0702025c783e6cb7bada0da507ee49a7 to your computer and use it in GitHub Desktop.
Save killown/0702025c783e6cb7bada0da507ee49a7 to your computer and use it in GitHub Desktop.
Send to gist using gtk
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
import subprocess
import os
def run_gist(description, file_content, filename):
file_path = os.path.join("/tmp/", filename)
with open(filename, 'w') as f:
f.writelines(file_content)
f.close()
outputCMD = subprocess.Popen(
['gist', '-d', description, filename], stdout=subprocess.PIPE)
class send_to_gist(Gtk.Window):
def __init__(self):
super(ThumbGen, self).__init__()
self.set_size_request(250, 200)
self.set_position(Gtk.WindowPosition.CENTER)
self.connect("destroy", Gtk.main_quit)
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.set_title("Send to Gist")
self.description = Gtk.Entry()
self.description.set_text("Description")
self.description_label = Gtk.Label('Gist Description')
self.filename = Gtk.Entry()
self.filename.set_text("filename.py")
self.filename_label = Gtk.Label('File name .ext')
self.settext = Gtk.Button("Send to Gist")
self.settext.connect("clicked", self.on_gist_description)
self.entry = Gtk.Entry()
self.entry.set_text("Hello World")
# adjust position
fix = Gtk.Fixed()
fix.put(self.description_label, 5, 5)
fix.put(self.description, 5, 25)
fix.put(self.filename_label, 5, 60)
fix.put(self.filename, 5, 80)
fix.put(self.settext, 5, 120)
fix.set_halign(Gtk.Align.CENTER)
fix.set_valign(Gtk.Align.CENTER)
self.add(fix)
self.show_all()
def on_gist_description(self, entry):
description = self.description.get_text()
filename = self.filename.get_text()
file_content = self.clipboard.wait_for_text()
run_gist(description, file_content, filename)
send_to_gist()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment