GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 6:54 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Automatic empty row in GTKTreeView? (PyGObject)
PostPosted: Wed Jul 02, 2014 11:18 am 
Familiar Face

Joined: Mon Mar 31, 2014 9:59 pm
Posts: 18
I have difficulty with GTKTreeView. I would like to always have an empty row at the bottom of the table, so the user can create a new entry. But the new row always defaults to 0,000 which then produces a data-point at the coordinates (0|0). Is there any way to just have an empty row at the bottom?


from gi.repository import Gtk
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

class DataBase():
    def __init__(self):
        self.window = Gtk.Window()
        self.window.set_default_size(800, 500) = Gtk.Box()

        self.fig = Figure(figsize=(10,10), dpi=80) = self.fig.add_subplot(111)

        self.canvas = FigureCanvas(self.fig), True, True, 0)
        self.liststore = Gtk.ListStore(float, float)
        self.treeview = Gtk.TreeView(model=self.liststore), False, True, 0)

        self.xrenderer = Gtk.CellRendererText()
        self.xrenderer.set_property("editable", True)
        self.column_text = Gtk.TreeViewColumn("x-Value", self.xrenderer, text=0)
        self.yrenderer = Gtk.CellRendererText()
        self.yrenderer.set_property("editable", True)
        self.column_editabletext = Gtk.TreeViewColumn("y-Value", self.yrenderer, text=1)

        self.xrenderer.connect("edited", self.xedited)
        self.yrenderer.connect("edited", self.yedited)

        self.liststore.append([2.35, 2.40])
        self.liststore.append([3.45, 4.70])

    def resetplot(self):,10),10)

    def plotpoints(self):
        for row in self.liststore:
  [:1], row[1:], marker='o', s=50)

    def xedited(self, widget, path, number):
        self.liststore[path][0] = float(number.replace(',', '.'))
    def yedited(self, widget, path, number):
        self.liststore[path][1] = float(number.replace(',', '.'))

db = DataBase()

db.window.connect("delete-event", Gtk.main_quit)

Setup: GTK 3.12, Python 3.4, Glade 3.18, Matplotlib 1.4, Ubuntu 14.10 (64bit) and Gedit. (

 Post subject: Re: Automatic empty row in GTKTreeView? (PyGObject)
PostPosted: Tue Aug 05, 2014 12:04 am 

Joined: Mon Aug 04, 2014 1:20 am
Posts: 2
When using treeviews I usually store all displayed data in the model as strings, mainly because the data retrieved from a database table may include Null values. Inserting the data as string will allow you to insert empty strings to create an empty row like you want.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group