WIP: A button is now in the GtkBox *runlib_objects of windows.c How to associate an action to it ?
This commit is contained in:
parent
d353bf1188
commit
ef0519440e
|
@ -129,4 +129,5 @@ void onTreeViewRowActivated (GtkTreeView *view, GtkTreePath *path,
|
||||||
void tree_c_test(void);
|
void tree_c_test(void);
|
||||||
|
|
||||||
GtkWidget *create_tree_label(void);
|
GtkWidget *create_tree_label(void);
|
||||||
|
GtkWidget *create_tree_button(void);
|
||||||
|
|
||||||
|
|
175
src/ui/tree.c
175
src/ui/tree.c
|
@ -162,12 +162,12 @@ tree_c_test(void)
|
||||||
}
|
}
|
||||||
else g_error("Oops, we should have a first row in the tree store!\n");
|
else g_error("Oops, we should have a first row in the tree store!\n");
|
||||||
|
|
||||||
GtkTreeViewColumn *col;
|
// GtkTreeViewColumn *col;
|
||||||
GtkCellRenderer *renderer;
|
// GtkCellRenderer *renderer;
|
||||||
GtkWidget *view;
|
// GtkWidget *view;
|
||||||
GtkTreeModel *model;
|
// GtkTreeModel *model;
|
||||||
|
|
||||||
GtkWidget *window;
|
// GtkWidget *window;
|
||||||
|
|
||||||
|
|
||||||
tree_c_printing_test();
|
tree_c_printing_test();
|
||||||
|
@ -175,165 +175,20 @@ tree_c_test(void)
|
||||||
|
|
||||||
static void tree_c_printing_test(void)
|
static void tree_c_printing_test(void)
|
||||||
{
|
{
|
||||||
printf("tree_c_printing_test() \
|
printf("tree.c tree_c_printing_test() \
|
||||||
-----------------------------------\n\
|
------------------------------------\n\
|
||||||
Changement de cap : comment mettre un label (puis un arbre)\n\
|
A button is now in the GtkBox *runlib_objects of windows.c (line 61)\n\
|
||||||
dans la GtkBox *runlib_objects; de windows.c (ligne 61)\n\
|
How to associate an action to it\n\
|
||||||
?\n\
|
?\n\
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Tree_Models
|
|
||||||
// https://stackoverflow.com/questions/74556059/how-to-build-a-tree-in-gtk4-4-10
|
|
||||||
//
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
https://docs.gtk.org/gobject/#functions
|
||||||
|
https://docs.gtk.org/gtk4/class.Label.html?q=
|
||||||
|
https://docs.gtk.org/gtk4/ctor.Button.new_with_label.html
|
||||||
|
https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Tree_Models
|
||||||
|
https://stackoverflow.com/questions/74556059/how-to-build-a-tree-in-gtk4-4-10
|
||||||
https://stackoverflow.com/questions/51002454/how-to-list-all-the-rows-of-a-gtk-treeview
|
https://stackoverflow.com/questions/51002454/how-to-list-all-the-rows-of-a-gtk-treeview
|
||||||
|
https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using Gtk;
|
|
||||||
|
|
||||||
public class Actress
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
public string Place;
|
|
||||||
public int Year;
|
|
||||||
|
|
||||||
public Actress(string name, string place, int year)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Place = place;
|
|
||||||
Year = year;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SharpApp : Window
|
|
||||||
{
|
|
||||||
ListStore store;
|
|
||||||
Statusbar statusbar;
|
|
||||||
|
|
||||||
enum Column
|
|
||||||
{
|
|
||||||
Name,
|
|
||||||
Place,
|
|
||||||
Year
|
|
||||||
}
|
|
||||||
|
|
||||||
Actress[] actresses =
|
|
||||||
{
|
|
||||||
new Actress("Jessica Alba", "Pomona", 1981),
|
|
||||||
new Actress("Sigourney Weaver", "New York", 1949),
|
|
||||||
new Actress("Angelina Jolie", "Los Angeles", 1975),
|
|
||||||
new Actress("Natalie Portman", "Jerusalem", 1981),
|
|
||||||
new Actress("Rachel Weissz", "London", 1971),
|
|
||||||
new Actress("Scarlett Johansson", "New York", 1984)
|
|
||||||
};
|
|
||||||
|
|
||||||
public SharpApp() : base ("ListView")
|
|
||||||
{
|
|
||||||
BorderWidth = 8;
|
|
||||||
|
|
||||||
SetDefaultSize(350, 250);
|
|
||||||
SetPosition(WindowPosition.Center);
|
|
||||||
DeleteEvent += delegate { Application.Quit(); };
|
|
||||||
|
|
||||||
VBox vbox = new VBox(false, 8);
|
|
||||||
|
|
||||||
|
|
||||||
ScrolledWindow sw = new ScrolledWindow();
|
|
||||||
sw.ShadowType = ShadowType.EtchedIn;
|
|
||||||
sw.SetPolicy(PolicyType.Automatic, PolicyType.Automatic);
|
|
||||||
vbox.PackStart(sw, true, true, 0);
|
|
||||||
|
|
||||||
store = CreateModel();
|
|
||||||
|
|
||||||
TreeView treeView = new TreeView(store);
|
|
||||||
treeView.RulesHint = true;
|
|
||||||
treeView.RowActivated += OnRowActivated;
|
|
||||||
sw.Add(treeView);
|
|
||||||
|
|
||||||
AddColumns(treeView);
|
|
||||||
|
|
||||||
statusbar = new Statusbar();
|
|
||||||
|
|
||||||
vbox.PackStart(statusbar, false, false, 0);
|
|
||||||
|
|
||||||
Add(vbox);
|
|
||||||
ShowAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnRowActivated (object sender, RowActivatedArgs args) {
|
|
||||||
|
|
||||||
TreeIter iter;
|
|
||||||
TreeView view = (TreeView) sender;
|
|
||||||
|
|
||||||
if (view.Model.GetIter(out iter, args.Path)) {
|
|
||||||
string row = (string) view.Model.GetValue(iter, (int) Column.Name );
|
|
||||||
row += ", " + (string) view.Model.GetValue(iter, (int) Column.Place );
|
|
||||||
row += ", " + view.Model.GetValue(iter, (int) Column.Year );
|
|
||||||
statusbar.Push(0, row);
|
|
||||||
}
|
|
||||||
// *** if I can dump treeview to the console here I'll be happy ***
|
|
||||||
// *** I'd prefer a foreach or do/while ***
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddColumns(TreeView treeView)
|
|
||||||
{
|
|
||||||
CellRendererText rendererText = new CellRendererText();
|
|
||||||
TreeViewColumn column = new TreeViewColumn("Name", rendererText,
|
|
||||||
"text", Column.Name);
|
|
||||||
column.SortColumnId = (int) Column.Name;
|
|
||||||
treeView.AppendColumn(column);
|
|
||||||
|
|
||||||
rendererText = new CellRendererText();
|
|
||||||
column = new TreeViewColumn("Place", rendererText,
|
|
||||||
"text", Column.Place);
|
|
||||||
column.SortColumnId = (int) Column.Place;
|
|
||||||
treeView.AppendColumn(column);
|
|
||||||
|
|
||||||
rendererText = new CellRendererText();
|
|
||||||
column = new TreeViewColumn("Year", rendererText,
|
|
||||||
"text", Column.Year);
|
|
||||||
column.SortColumnId = (int) Column.Year;
|
|
||||||
treeView.AppendColumn(column);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ListStore CreateModel()
|
|
||||||
{
|
|
||||||
ListStore store = new ListStore( typeof(string),
|
|
||||||
typeof(string), typeof(int) );
|
|
||||||
|
|
||||||
foreach (Actress act in actresses) {
|
|
||||||
store.AppendValues(act.Name, act.Place, act.Year );
|
|
||||||
}
|
|
||||||
|
|
||||||
return store;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Main()
|
|
||||||
{
|
|
||||||
Application.Init();
|
|
||||||
new SharpApp();
|
|
||||||
Application.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
(https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer)\n\
|
|
||||||
Trying to adapt the first example of this tuto to display a simple tree view in our window.\n\
|
|
||||||
Can't use :\n\
|
|
||||||
- gtk_init(&argc, &argv);\n\
|
|
||||||
- window = gtk_tree_view_new(GTK_WINDOW_TOPLEVEL);\n\
|
|
||||||
- g_signal_connect(window, 'delete_event', gtk_main_quit, NULL);\n\
|
|
||||||
- tree_c_test(); (or : create_view_and_model() or some equivalent tree description)\n\
|
|
||||||
- gtk_container_add(GTK_CONTAINER(window), view);\n\
|
|
||||||
- gtk_widget_show_all(window);\n\
|
|
||||||
- gtk_main();\n\
|
|
||||||
(see main.c lines 35-44)\n\
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -124,7 +124,8 @@ void ui_set_stack(const char *mode)
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
gtk_menu_button_set_icon_name(window->main_button_mode, "system-run-symbolic");
|
gtk_menu_button_set_icon_name(window->main_button_mode, "system-run-symbolic");
|
||||||
create_tree_label();
|
// create_tree_label();
|
||||||
|
create_tree_button();
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
gtk_menu_button_set_icon_name(window->main_button_mode, "x-office-presentation-symbolic");
|
gtk_menu_button_set_icon_name(window->main_button_mode, "x-office-presentation-symbolic");
|
||||||
|
@ -232,9 +233,8 @@ void ui_toggle_sidebar(void)
|
||||||
|
|
||||||
GtkWidget *create_tree_label(void)
|
GtkWidget *create_tree_label(void)
|
||||||
{
|
{
|
||||||
GtkWidget *label, *slider;
|
GtkWidget *label;
|
||||||
GtkAdjustment *adj;
|
const char *text = "Hello ! I'm the label";
|
||||||
const char *text = "HELLO !";
|
|
||||||
|
|
||||||
label = gtk_label_new(text);
|
label = gtk_label_new(text);
|
||||||
gtk_box_append(GTK_BOX(window->runlib_objects), label);
|
gtk_box_append(GTK_BOX(window->runlib_objects), label);
|
||||||
|
@ -243,3 +243,17 @@ GtkWidget *create_tree_label(void)
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GtkWidget *create_tree_button(void)
|
||||||
|
{
|
||||||
|
GtkWidget *button;
|
||||||
|
const char *text = "Hello ! I'm the button";
|
||||||
|
|
||||||
|
button = gtk_button_new_with_label(text);
|
||||||
|
gtk_box_append(GTK_BOX(window->runlib_objects), button);
|
||||||
|
gtk_widget_show(button);
|
||||||
|
|
||||||
|
tree_c_test();
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue