Python Forum
[PyGTK] Creating Book Table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGTK] Creating Book Table
#1
Hello;

I writed this codes for creating book table:

import os
import gi

def get_all_books():
    """
    Structure:

        (
            [isbn, name, author, page_number],
            [isbn, name, author, page_number],
            [isbn, name, author, page_number],
            ...
        )
    """
    
    return (
        ["039103948", "Name", "John Doe", "923"],
        ["039103948", "Name", "John Doe", "923"],
        ["039103948", "Name", "John Doe", "923"],
        ["039103948", "Name", "John Doe", "923"],

    )

UI_FILE = os.path.join(os.getcwd(), "window.ui")

gi.require_version("Gtk", "3.0")

from gi.repository import Gtk

class SignalHandler:
    def selection_changed(self, selection):
        ...

def create_treeview():
    store = Gtk.ListStore(int, str, str, int)
    books = get_all_books()

    map(lambda b: store.append(b), books) # Add books to store

    tree = Gtk.TreeView(store)

    isbn_col   = Gtk.TreeViewColumn("ISBN")
    name_col   = Gtk.TreeViewColumn("Name")
    author_col = Gtk.TreeViewColumn("Author")
    page_n_col = Gtk.TreeViewColumn("P. Number")

    isbn_r, name_r, author_r, page_n_r = Gtk.CellRendererText(), Gtk.CellRendererText(), Gtk.CellRendererText(), Gtk.CellRendererText()   

    l = [
        (isbn_col, isbn_r),
        (name_col, name_r),
        (author_col, author_r),
        (page_n_col, page_n_r),
    ]

    for i in l:
        i[0].pack_start(i[1], True)
        i[0].add_attribute(i[1], "text", l.index(i))
    
    map(
        lambda i: tree.append_column(i[0]),
        l,
    )

    select = tree.get_selection()
    select.connect("changed", SignalHandler().selection_changed)

    return tree

builder = Gtk.Builder()
builder.add_from_file(UI_FILE)
builder.connect_signals(SignalHandler())

if __name__ == "__main__":
    window = builder.get_object("main_window")
    box = builder.get_object("all_books_box")
    box.pack_end(create_treeview(), True, True, 0)

    window.show_all()

    Gtk.main()
When i run this codes, opening a blank window.

Console outputs:
~/LibraryManagement ยป python3 src/main.py                                                                        emre@emre-mint
src/main.py:71: PyGTKDeprecationWarning: Using positional arguments with the GObject constructor has been deprecated. Please specify keyword(s) for "model" or use a class specific constructor. See: https://wiki.gnome.org/PyGObject/InitializerDeprecations
  tree = Gtk.TreeView(store)
Why it doesn't working?
Reply
#2
Quote:If you want, all of my codes is ...
Please post all of your code needed to solve here, we don't like to follow links.
Reply
#3
(Oct-27-2020, 04:34 PM)Larz60+ Wrote: Please post all of your code needed to solve here

I edited my post.
Reply
#4
window.ui is mising
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] Creating hot spots in PyGTK DrakeSoft 1 1,562 Aug-01-2022, 04:35 PM
Last Post: Axel_Erfurt
  [PyGTK] How to center text on multi-line buttons? Lomax 3 4,159 Jan-23-2021, 03:23 PM
Last Post: Lomax
  [pygtk] fixed.move not working as expected DennisT 4 6,050 Nov-10-2016, 11:36 PM
Last Post: DennisT

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020