GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Jul 26, 2014 3:07 am

All times are UTC




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

Joined: Mon Mar 31, 2014 9:59 pm
Posts: 12
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?

Code:
#!/usr/bin/python3

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)
        self.box = Gtk.Box()
        self.window.add(self.box)

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

        self.canvas = FigureCanvas(self.fig)
        self.box.pack_start(self.canvas, True, True, 0)
       
        self.liststore = Gtk.ListStore(float, float)
        self.treeview = Gtk.TreeView(model=self.liststore)
        self.box.pack_start(self.treeview, 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.treeview.append_column(self.column_text)
       
        self.yrenderer = Gtk.CellRendererText()
        self.yrenderer.set_property("editable", True)
        self.column_editabletext = Gtk.TreeViewColumn("y-Value", self.yrenderer, text=1)
        self.treeview.append_column(self.column_editabletext)

        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])
        self.liststore.append()

    def resetplot(self):
        self.ax.cla()
        self.ax.set_xlim(0,10)
        self.ax.set_ylim(0,10)
        self.ax.grid(True)

    def plotpoints(self):
        self.resetplot()
        for row in self.liststore:
            self.ax.scatter(row[:1], row[1:], marker='o', s=50)
        self.fig.canvas.draw()

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

db = DataBase()
db.resetplot()
db.plotpoints()

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

_________________
My development setup: Ubuntu 14.04 (64bit), Glade 3.16.1, GTK+ 3.10, Python 3.4.0


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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