Possible to add some static data to TreeView within Glade? - gtk

I have seen the existing question but I am not sure if adding actual data in Glade is possible or not.
I have created a TreeView and added two columns. I created a TreeStore and set it to the TreeView. And how can I add some static data like the following within Glade?
Jane 10
Tom 20
Mike 30
Mary 40
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.18"/>
<object class="GtkTreeStore" id="treestore1">
<columns>
<!-- column-name name -->
<column type="string"/>
<!-- column-name age -->
<column type="int"/>
</columns>
</object>
<object class="GtkWindow" id="MainWindow">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Example Window</property>
<property name="default-width">480</property>
<property name="default-height">240</property>
<child>
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">treestore1</property>
<property name="enable-grid-lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="1">
<property name="resizable">True</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">Name</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<property name="sort-indicator">True</property>
<child>
<object class="GtkCellRendererText">
<property name="text">Doge</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="2">
<property name="resizable">True</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">Age</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<property name="sort-indicator">True</property>
<child>
<object class="GtkCellRendererText">
<property name="text">10</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

Data are stored in a store, such as GtkListStore, not in the view. To add them, click the store the widget on the glade.
At the bottom right corner of the image below, there are options to Add and remove rows.
Moreover, to associate the view with the store, the Text option in the cell renderer must be set to the corresponding store column.

Related

GTK paned view scrolling two textviews

I want to build a diff viewer.
For this I have decided to use two text views side by side and have them scroll at the same time.
I mostly have got it working, but I can't get the GTKScrolledWindow scroll while typing. Text view expands out of window. When I scroll with mouse I can see the text.
How to get his working? I want text to scroll when I type past window height.
Example structure stree:
GtkWindow
GtkScrolledWindow
GtkViewport
GtkPaned
Gtk text view 1 << Connected with vertical adjustment1
Gtk text Wiew 2 << Connected with vertical adjustment1
Glade file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkWindow">
<property name="width-request">800</property>
<property name="height-request">800</property>
<property name="can-focus">False</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<property name="propagate-natural-height">True</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<child>
<object class="GtkPaned">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="vexpand">True</property>
<property name="wide-handle">True</property>
<child>
<object class="GtkTextView">
<property name="width-request">300</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="vexpand">True</property>
<property name="vadjustment">adjustment1</property>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="vexpand">True</property>
<property name="vadjustment">adjustment1</property>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

resizing GtkPaned widget in glade

I want to design a Gtk UI in glade.
I need a window which has 3 resizable columns which I used GtkPaned container to create that.
The problem is that resizing left column also resizes the right column (and vice versa). I don't want that, I want to resize a column and the other columned stays fixed. I couldn't find a way to do that in glade.
here is my gladefile content:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child>
<object class="GtkPaned">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkPaned">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>

GTK Glade: Hierarchy Editor

I'm using Glade 3.20. I've created a liststore and a listview. The liststore has three columns; a gint, a gchararray and another gint.
I right-click on my TreeView object and select Edit.... The 'General' tab shows the columns I've defined in the liststore. I select the 'Hierarchy' tab and click the '+' button. This creates a new view column called column. I right click on that and select 'Add child text'. Nothing happens.
Is this a known problem with glade 3.20? Am I doing something daft?
Yes, unfortunately its a bug. I think it was introduced around Glade 3.19.0. Copy pasting a cell renderer from an older glade file will work though or if added manually by editing the xml file:
Example cell renderer pixbuf :
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title">column</property>
<child>
<object class="GtkCellRendererPixbuf" id="cellrendererpixbuf1">
<property name="visible">False</property>
<property name="stock_size">3</property>
</object>
<attributes>
<attribute name="icon-name">0</attribute>
</attributes>
</child>
</object>
I've just prepared a simple glade file containing all the default cell renderers that you can copy paste, inside glade, to your glade file. Just go to the widget hierarchy, copy the renderer, go to your widget hierarchy and under the TreeViewColumn, paste the copied renderer.
cell_renderers.glade:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.19.0 -->
<interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="treeview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="vexpand">True</property>
<property name="headers_visible">False</property>
<property name="search_column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection6"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn8">
<property name="title">column</property>
<child>
<object class="GtkCellRendererProgress" id="cellrendererprogress1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn7">
<property name="title">column</property>
<child>
<object class="GtkCellRendererSpinner" id="cellrendererspinner1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn6">
<property name="title">column</property>
<child>
<object class="GtkCellRendererAccel" id="cellrendereraccel1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="title">column</property>
<child>
<object class="GtkCellRendererSpin" id="cellrendererspin1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="title">column</property>
<child>
<object class="GtkCellRendererCombo" id="cellrenderercombo1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="title">column</property>
<child>
<object class="GtkCellRendererToggle" id="cellrenderertoggle1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title">column</property>
<child>
<object class="GtkCellRendererPixbuf" id="cellrendererpixbuf1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title">column</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1">
<property name="height">44</property>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
This may be solved in upcoming glade versions, though.

gtk/glade expandable toolbar

I guess I have a unique problem.
I am trying to create a horizontal toolbar like widget that can can hold labels, buttons, and other gtk widgets. I want to pack as much info as I can but I also need it to work for various screen sizes.
Ultimately I'm trying to anticipate the GUI being ran on smaller screens so most of the widgets I want to use cannot actually fit because they take too much space all together.
But I still want to make them available to the user so I figured I could have two or three rows of widgets. Putting the most used at the top.
Ultimately, I'd like the user to be able to add different widgets at runtime depending on what they want(sort of like how you can sometimes customize headers for lists in some programs... e.g., windows explorer's file lists).
Now, I want some widgets to take up a lot of space if it is available and some are fixed in size. This way, the space is optimally used. If a person is running the app on a large LCD monitor, they could pack more widgets and if it is not, they could remove them.
Basically it sorta like a flow control but different. I was using a horizontal box but realized the limitations of this quickly. Mainly that I could not resize my window smaller than what the total width which might make the app too large to fit on a smaller window.
I'm trying to minimize the amount of work as I don't wanna reimplement glade in to the program. OTH, I suppose I could create different glade interfaces for different devices... probably be the easiest thing. If the user really wants to customize the interface they could do it manually. It requires extra programming work since I have to worry about missing widgets and all that but should be less worrying.
I'd rather have a more useful method though. Any ideas?
The widgets that make up my "toolbar" are images, buttons, labels, drawing areas, and a few other standard gtk widgets. Some will need to take up as much horizontal space as they can while others will be fixed in size. All will have the same vertical size.
Some elements will have fixed positions such as the far right and left and not change.
I should probably be a bit more clear
X Y Z * * * * A B C
* * * * * * * * * *
XYZ and ABC are going to be fixed widgets that must show up and to the far left and right resp.
are widgets I want to be configurable. Some will need to expand to use the maximum size they can(And share with others that also need to expand) and some will be fixed. Ultimately the user should be able to add and remove the * widgets without issue and reorder them if they want. They add to many they should flow down so that the X Y Z and A B C widgets always are shown.
Not sure about your goals but to get something similar to your drawing, an approach, would be, to use some GtkToolbar/Gtk.Toolbar packed on a GtkGrid/Gtk.Grid or GtkBox/Gtk.Box.
The first and the last Toolbars would have the show_arrow property set to False while the one(s) in the middle would have it set as True.
With a setup like this, the toolbar(s) in the middle would shrink and show an arrow that allows the user to select the packed widgets.
GtkToolbar/Gtk.Toolbar allows the use of all kinds of widgets even custom ones.
Here's a simple example:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_arrow">False</property>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_7</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-about</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_8</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-add</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_9</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-go-back</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToolbar" id="10297 927030981 28.68">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">buttonOrWidget</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">AnotherButton</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">YetAnotherButton</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_arrow">False</property>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_10</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-justify-center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_11</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-clear</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">__glade_unnamed_12</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-connect</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
The result (with the middle toolbar totally shrinked):
Growing the application window will permit some of the widgets to start showing and if there are more, unshown, widgets then the expander sign will still show:
Resizing the window the window to full extent and beyond will spermit to show all the widgets and the expander will disappear:
You can pack Toolbars as needed to achieve your goals.
Not sure this is what you're after though.

Shift-Tab to focus previous Entry field

I am using Glade to design a GUI. When I insert GtkEntry fields, I can navigate to the next one using the Tab Key (this ability is given "for free" in Glade). However, it seems that I cannot use Shift-Tab to focus the previous tab entry.
When I have instead two buttons, both Tab and Shift-Tab works out of the box.
So: is there a way to have Shift-Tab to focus the previous GtkEntry in Glade?
The Glade code is below; one with two entry fields, one with two buttons.
Two entries:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Two buttons:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>