Kindelabra
Kindelabra copied to clipboard
Something wrong with GTK library and Ubuntu 13.04
The filechooser is not working: on self.load the code 'self.filechooser.get_current_folder()' returns None. I tried to replicate this and it seems problem lies somewhere else than the code itself, since also simple example
import os
import datetime
import json
import re
import gtk
VERSION = '0.2'
class KindleUI:
'''Interface for manipulating a Kindle collection JSON file
'''
def __init__(self):
self.root = "/"
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Kindelabra v%s" % VERSION)
self.window.set_default_size(1000, 700)
self.window.connect("destroy", gtk.main_quit)
self.accel_group = gtk.AccelGroup()
self.window.add_accel_group(self.accel_group)
vbox_main = gtk.VBox()
filechooserdiag = gtk.FileChooserDialog("Select your Kindle folder", self.window,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
filechooserdiag.set_current_folder(os.path.join(self.root, 'system'))
self.filechooser = gtk.FileChooserButton(filechooserdiag)
self.filechooser.connect("current-folder-changed", self.load)
file_toolbar = gtk.HBox()
file_toolbar.pack_start(self.filechooser, True, True, 2)
self.window.add(file_toolbar)
self.window.show_all()
gtk.main()
def load(self, widget):
current = self.filechooser.get_current_folder()
if current == None:
print "ERROR: Got None from current_folder()\n"
current = self.root
print "LOADING " + current + "\n";
if __name__ == "__main__":
KindleUI()
returns always 'Got None'.
This seems to fix the issue:
diff --git a/Kindelabra.py b/Kindelabra.py
index 902916e..2849f13 100755
--- a/Kindelabra.py
+++ b/Kindelabra.py
@@ -38,6 +38,7 @@ class KindleUI:
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
filechooserdiag.set_current_folder(os.path.join(self.root, 'system'))
+ self.filechooserdiag = filechooserdiag
self.filechooser = gtk.FileChooserButton(filechooserdiag)
self.filechooser.connect("current-folder-changed", self.load)
@@ -95,7 +96,12 @@ class KindleUI:
self.statusbar.push(1, message)
def load(self, widget):
- current = self.filechooser.get_current_folder()
+ current = self.filechooserdiag.get_filename()
+
+ if current == None:
+ print "GOT NONE!"
+ return
+
if not self.root == current:
self.status("Loading... please wait")
self.root = current