PyGTK/Quickly Add string to ListStore
- by AllRadioisDead
I'm trying to build an application that will prompt the user for a string, and then add that string to a Scrolling Listview object using quickly and PyGTK.
I've been following this tutorial:
http://developer.ubuntu.com/resources/app-developer-cookbook/multimedia/creating-a-simple-media-player/
When I hit the add button, the prompt comes up properly and I'm able to enter the string. The column appears correctly but the list ends up being blank. What am I doing wrong?
import gettext
from gettext import gettext as _
gettext.textdomain('spiderweb')
from gi.repository import Gtk # pylint: disable=E0611
import logging
logger = logging.getLogger('spiderweb')
from spiderweb_lib import Window
from spiderweb.AboutSpiderwebDialog import AboutSpiderwebDialog
from spiderweb.PreferencesSpiderwebDialog import PreferencesSpiderwebDialog
from quickly import prompts
from quickly.widgets.dictionary_grid import DictionaryGrid
import os
# See spiderweb_lib.Window.py for more details about how this class works
class SpiderwebWindow(Window):
__gtype_name__ = "SpiderwebWindow"
def finish_initializing(self, builder): # pylint: disable=E1002
"""Set up the main window"""
super(SpiderwebWindow, self).finish_initializing(builder)
self.AboutDialog = AboutSpiderwebDialog
self.PreferencesDialog = PreferencesSpiderwebDialog
# Code for other initialization actions should be added here.
self.supported_web_formats = [".net",".html", ".com"]
def on_addbutton_clicked(self, widget, data=None):
#let the user choose a path with the directory chooser
response, string = prompts.string("Enter a string", "Please enter string:", "Sample Text")
#make certain the user said ok before working
if response == Gtk.ResponseType.OK:
#make a list of the supported media files
media_files = Gtk.ListStore(str)
#add a dictionary to the list of media files
media_files.append({"String":string})
#remove any children in scrolled window
for c in self.ui.scrolledwindow1.get_children():
self.ui.scrolledwindow1.remove(c)
#create the grid with list of dictionaries
#only show the File column
media_grid = DictionaryGrid(media_files, keys=["File"])
#show the grid, and add it to the scrolled window
media_grid.show_all()
self.ui.scrolledwindow1.add(media_grid)