Simple Python Text-Entry

Recently for my biogen project I needed a way to create pop-up text entries for users using virtualenv. Sadly, neither wxPython nor TkInter would work easily without ugly hacks involving symlinking to system directories. Eventually I worked out that Gtk would work via pip. However, I couldn't find sample code anywhere that ran synchronously(not via signals), so I could wait to grab the users input before proceeding along execution. So I cooked up some sample code that might help others.
from pgi.repository import Gtk, GObject
class EntryWindow(Gtk.Window):
def __init__(self, ask_title="Title", ask_body="Body", message="Message"):
Gtk.Window.__init__(self, title=ask_title)
self.set_size_request(200, 100)
self.timeout_id = None
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
label = Gtk.Label(message)
vbox.pack_start(label, True, True, 0)
self.entry = Gtk.Entry()
self.entry.set_text(ask_body)
vbox.pack_start(self.entry, True, True, 0)
hbox = Gtk.Box(spacing=6)
vbox.pack_start(hbox, True, True, 0)
button = Gtk.Button(label="OK")
button.connect("clicked",self.on_ok_button_clicked)
vbox.pack_start(button, True, True, 0)
def on_ok_button_clicked(self,button):
Gtk.main_quit()
def run(self):
self.show_all()
Gtk.main()
result = self.entry.get_text()
self.destroy()
return result
The import uses pgi.repositories not gi.repositories as I needed it to be compatible with PyPy for speed.
To then run this code(and grab it's input), use something like this.
win = EntryWindow("My Title", "Enter Some Text", "Some message")
response_text = win.run()
comments
Bioinformatics/Rosalind - Skeleton Generator
Working through part 4 of my Cousera Bioinformatics specialisation, I decided to write a generator that creates a standardised approach to structure, write and test your algorithmic code. It also works for Rosalind problems.
Explanations are in the README. If you have any issues or are confused by anything, feel …
comments
Read More
Tiddlywiki to Org-Mode

Okay, I swear this is the last document conversion script I’m writing this year. I’ve been on a bit of a rampage to move all of my life in Emacs Org-Mode and converting all of my Tiddlywiki notes into Org mode has been on my list for a …
comments
Read More
OSQA to Tiddlywiki

Recently I've been trying out Tiddlywiki
as an alternative to Evernote. I decided to
try convert my existing OSQA install to
Tiddlywiki as I'm travelling a lot and
don't always have access to my servers via the internet. Here's a python
script I wrote that might help anyones trying to …
comments
Read More
Find My Run - My first iPhone app

It's a pretty basic app that lists the ten nearest running events in
your area. There was a few new pieces of tech(for me) involved. The app
was built with Appcelerator's Alloy
framework, which I must
admit I quite like for rapid development of cross platform mobile
apps(hopefully …
comments
Read More
OfflineImap to Thunderbird
Last week I moved from Debian to Linux Mint and setup Thunderbird as my
new mail client(replacing mutt). Sadly for some reason Thunderbird
started tanking and wiped all the mails from my mailserver without
actually downloading anything.
I could've restored the mails from a backup but instead I figured …
comments
Read More
Unit-testing unmanaged Django models
Say you have an app with a set of models that aren't being managed by
Django, you're going to run into trouble when it comes time to run
unit-tests against these. What I mean is if in the model meta you have
something like this
class MyClass:
....
class Meta:
app_label …
comments
Read More
Suppling test data to django-cities

Django-Cities, is an
awesome project that supplies easy to import worldwide location data and
a set of very neat location models that you should really be using for
any django project needing location information. I've been using it
lately but ran into problems when I tried to run unit tests …
comments
Read More
Writing Django tests for PostGis

PostGis is awesome, I think I already established this in this
post. However when you
start writing django tests you might start getting errors complaining
that certain postgres libs cannot be found. This is because you've
failed to create a proper postgres_template database for your test
database to work with …
comments
Read More
Octopress back to Wordpress
I've been using Octopress for the last while
and it felt good having a nice fast static blog as opposed to heavy-old
Wordpress. After time passed however, I
noticed I wrote less. Having to grab my laptop and pull up vim to write
something, then play around with git or …
comments
Read More