Re: Detecting the gdk backend

2019-02-07 Thread Luca Bacci via gtk-app-devel-list
Hi! There is some reference code here:
https://developer.gnome.org/gdk3/stable/gdk3-Wayland-Interaction.html
https://developer.gnome.org/gdk3/stable/gdk3-X-Window-System-Interaction.html

   - Include the backend specific headers: gdk/gdkx.h, gdk/gdkwayland.h
   - Link with backend specific libs: gdk-x11-3.0.pc, gdk-wayland-3.0.pc
   - Check the backend for the default display: if
   (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { /*...*/ }

Here is an example:

/* compile with
cc -o print-gdk-backend print-gdk-backend.c \
$(pkg-config --cflags --libs gtk+-3.0 gdk-x11-3.0 gdk-wayland-3.0)
*/

#include 
#ifdef GDK_WINDOWING_X11
#include 
#endif
#ifdef GDK_WINDOWING_WAYLAND
#include 
#endif
/*
   GDK_WINDOWING macros are defined in header
   /usr/include/gtk-3.0/gdk/gdkconfig.h
*/

int main() {
  gtk_init(NULL, NULL);

#ifdef GDK_WINDOWING_X11
  if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
g_print("X11 backend\n");
  }
#endif
#ifdef GDK_WINDOWING_WAYLAND
  if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
g_print("Wayland backend\n");
  }
#endif

  return 0;
}


Il giorno gio 7 feb 2019 alle ore 06:28 Daniel Kasak via gtk-app-devel-list
 ha scritto:

> Hi all. Is there a way to detect the gdk backend an app is using? I know
> about the environment variable - GDK_BACKEND. But often this is not set,
> and gtk just picks whatever's available. I need ever-so-slightly different
> app behaviour, depending on the backend. Any ideas?
>
> Dan
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How to replace gtk_widget_modify_text() with CSS?

2018-12-18 Thread Luca Bacci via gtk-app-devel-list
Hi Nate,
based on my experience, you have 3 ways:

1) First, see if there are standard CSS classes provided by the theme for
your use case. For example, GtkButton
 has the
*.suggegsted-action* and *.destructive-action* CSS classes, which all
themes shall provide. GtkEntry has *.warning* and *.error* CSS classes.
This blends nicely with every theme you may use.

You use gtk_widget_get_style_context() and gtk_style_context_add_class().
In one line it is:
gtk_style_context_add_class(gtk_widget_get_style_context(button),
"suggested-action");

See:
https://stackoverflow.com/a/37628324
https://wiki.gnome.org/HowDoI/Buttons.

2) Create one CSS where you define *your own* CSS classes. It can be either
a string in your source file, an external .css file that you load at
runtime, or a .css file embedded as a GResource
). Load your custom
CSS at startup:

void setup_application_css() {
  const gchar *css_string = ".red_text { color: red; }";

  GtkCssProvider *css = gtk_css_provider_new();
  gtk_css_provider_load_from_data(css, css_string, -1, NULL);
  gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER(css),

GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
  g_object_unref(css);
}

int main(int argc, char **argv) {
  gtk_init(, );
  setup_application_css();

  init();
  gtk_main();
  return 0;
}

then apply the class to any widget you want:
GtkEntry *entry = gtk_entry_new();
gtk_style_context_add_class(gtk_widget_get_style_context(entry),
"red_text");

NOTE: if you want to work with CSS id, just change the css string to:

const gchar *css_string = "#myentry1 { color: red; }";

then set the CSS id to the entry:
GtkEntry *entry = gtk_entry_new();
gtk_widget_set_name(entry, "myentry1");

3) If you have to style just a few widgets, it's best to style them
directly at creation site, without loading a CSS globally:

GtkEntry* create_entry() {
  GtkEntry *entry = gtk_entry_new();

  const gchar *css_string = "entry { color: red; }";
  GtkCssProvider *css = gtk_css_provider_new();
  gtk_css_provider_load_from_data(css, css_string, -1, NULL);
  gtk_style_context_add_provider(gtk_widget_get_style_context(entry),
 GTK_STYLE_PROVIDER(css),
 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
  g_object_unref(css);

  return entry;
}

I suggest you use the Gtk Inspector
 to
experiment with all that at runtime. You can write live CSS and you can
also set properties of your widgets like name, classes. See also
https://blog.gtk.org/2017/04/05/the-gtk-inspector/

I have attached examples for all three points.
Luca

Il giorno lun 17 dic 2018 alle ore 15:46 Nate Bargmann  ha
scritto:

> Greetings to the list.
>
> Several years ago I took over maintainership of a useful amateur radio
> application written for GTK+ 2.  As a winter project I've decided to
> port it to GTK+ 3 and have used the transition guide to accomplish
> much.  I set the build system to generate warnings for deprecated
> constructs and one of the things that has me stumped is how to replace a
> call to GTK+ 2's gtk_widget_modify_text() with CSS in GTK+ 3.  Now, I'm
> not a complete newcomer to CSS having used it with HTML years back so
> that is not the issue.
>
> In the program source there are lines like this which merely set the
> foreground color of some text based on a default or some later user
> preference:
>
> gtk_widget_modify_text(highentry1, GTK_STATE_NORMAL,
> );
>
> Building now generates this warning (I have a lot of these):
>
>   CC   main.o
> ../../xdx/src/main.c: In function ‘main’:
> ../../xdx/src/main.c:332:5: warning: ‘gtk_widget_modify_text’ is
> deprecated: Use 'CSS style classes' instead [-Wdeprecated-declarations]
>  gtk_widget_modify_text(highentry1, GTK_STATE_NORMAL,
> );
>  ^~
>
> I have been looking through the reference documentation and various
> examples to find something relatively simple to change the foreground
> color of the text.  Right now what I am looking for is a clue of how to
> get from "here" to "there".  What I am finding seems to be rather
> complicated and involved.  Hopefully my impression is incorrect.
>
> Is there a function that I've missed that can apply CSS inline similar
> to this deprecated function?
>
> TIA
>
> - Nate
>
> --
>
> "The optimist proclaims that we live in the best of all
> possible worlds.  The pessimist fears this is true."
>
> Web: http://www.n0nb.us  GPG key: D55A8819  GitHub: N0NB
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
#include 

void load_application_css() {
  const gchar *css_string = ".red_text { color: red; }";

  

Re: Issue using the "gtk_widget_get_allocated_height" instruction

2018-11-26 Thread Luca Bacci via gtk-app-devel-list
Hi Sébastien!
It's not simple, but you may try with combinations of

GtkStyleContext *style = gtk_widget_get_style_context(widget);
GValue value = G_VALUE_INIT;
gtk_style_context_get_style_property(style, "prop-name", );
//or
gtk_style_context_get_property(style, "prop-name", );
/*
...
*/
g_value_unset() //free memory

Unfortunately, that's all I can say, I'm not expert in this area.
Probably it's going to be rather complicated.

Luca

Il giorno lun 26 nov 2018 alle ore 16:34 Sébastien Le Roux <
sebastien.ler...@ipcms.unistra.fr> ha scritto:

> Le 24/11/2018 à 15:59, Luca Bacci a écrit :
>
> Probably it's a consequence of this work for porting GtkMenuBar to use css
> gadgets internally:
> https://gitlab.gnome.org/GNOME/gtk/commit/700286c6
>
> You should be able to get the appropriate size if you add menu items to
> the bar, i.e. as long as the
> menubar is not empty you get the appropriate height with
> gtk_widget_get_allocated_height().
>
> Luca
>
> Thank you very much for your reply, it works nicely with the "invisible"
> item.
>
> I do have in my code objects (GtkColorBar, GtkButtton) for which I created
> css
> properties my self to match some specifics using:
>
>
> void provide_gtk_css (gchar * css)
> {
>   GtkCssProvider * provider = gtk_css_provider_new ();
>   gtk_css_provider_load_from_data (provider, css, -1, NULL);
>   gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
>  GTK_STYLE_PROVIDER(provider),
>  
> GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
>   g_object_unref (provider);
> }
>
>
> About what I understand this is now automatic (somewhat) for many (all ?)
> widgets,
>
> Out of curiosity do you think that there is anyway to get that heigh value
> from
> a query to the css properties of that menu bar ? is there anyway to send
> query to the css ?
>
>
> Best
>
>
> Sébastien
>
> --
> ===
> Dr. Sébastien Le Roux
> Ingénieur de Recherche CNRS
> Institut de Physique et Chimie des Matériaux de Strasbourg
> Département des Matériaux Organiques
> 23, rue du Loess
> BP 43
> F-67034 Strasbourg Cedex 2, France
> E-mail: sebastien.ler...@ipcms.unistra.fr
> Webpage: http://www-ipcms.u-strasbg.fr/spip.php?article1771
> RINGS project: http://rings-code.sourceforge.net/
> ISAACS project: http://isaacs.sourceforge.net/
> Fax:   +33 3 88 10 72 46
> Phone: +33 3 88 10 71 62
> ===
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Issue using the "gtk_widget_get_allocated_height" instruction

2018-11-24 Thread Luca Bacci via gtk-app-devel-list
If you really need, you can fake it by adding a menuitem with empty text
and setting it to invisible with gtk_widget_set_visible(menuitem, false);

Il giorno sab 24 nov 2018 alle ore 15:59 Luca Bacci 
ha scritto:

> Probably it's a consequence of this work for porting GtkMenuBar to use css
> gadgets internally:
> https://gitlab.gnome.org/GNOME/gtk/commit/700286c6
>
> You should be able to get the appropriate size if you add menu items to
> the bar, i.e. as long as the
> menubar is not empty you get the appropriate height with
> gtk_widget_get_allocated_height().
>
> Luca
>
> Il giorno ven 23 nov 2018 alle ore 16:23 Sébastien Le Roux <
> sebastien.ler...@ipcms.unistra.fr> ha scritto:
>
>> Dear all, thanks for reading this,
>> I recently updated GTK from 3.22.24 to 3.22.30 (Fedora 27 to Fedora 28
>> update),
>> doing so something changed in behaviour of the program I am working on
>> (C code) at runtime.
>>
>> In my program I create a GtkMenuBar widget, using the code:
>>
>> GtkWidget * win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>> GtkWidget * gl_vbox =  gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
>> gtk_container_add (GTK_CONTAINER (win), gl_vbox);
>> GtkWidget * menu_bar = gtk_menu_bar_new ();
>> gtk_box_pack_start (GTK_BOX (gl_box), menu_bar, FALSE, FALSE, 0);
>> GtkWidget * gl_area = gtk_gl_area_new ();
>> gtk_widget_set_size_request (gl_area, 100, 100);
>> gtk_box_pack_start (GTK_BOX (gl_box), gl_area, FALSE, FALSE, 0);
>>
>> Before my update I could get the height of the menu bar after drawing
>> using:
>>
>> int size = gtk_widget_get_allocated_height (menu_bar);
>>
>> After my update the value of size is always 1, before the update it was
>> around 15,
>> obviously this new 1 value is messing with my program, not to mention
>> that it is not
>> what I see on the my computer screen, could anyone explain to me what to
>> do the get
>> the proper size of the GtkMenuBar ? (the gtk_widget_get_size_request is
>> useless).
>>
>> Thanks for your help in the matter.
>>
>> Best regards.
>>
>> Sébastien Le Roux
>>
>> --
>> ===
>> Dr. Sébastien Le Roux
>> Ingénieur de Recherche CNRS
>> Institut de Physique et Chimie des Matériaux de Strasbourg
>> Département des Matériaux Organiques
>> 23, rue du Loess
>> BP 43
>> F-67034 Strasbourg Cedex 2, France
>> E-mail: sebastien.ler...@ipcms.unistra.fr
>> Webpage: http://www-ipcms.u-strasbg.fr/spip.php?article1771
>> RINGS project: http://rings-code.sourceforge.net/
>> ISAACS project: http://isaacs.sourceforge.net/
>> Fax:   +33 3 88 10 72 46
>> Phone: +33 3 88 10 71 62
>> ===
>>
>> ___
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Issue using the "gtk_widget_get_allocated_height" instruction

2018-11-24 Thread Luca Bacci via gtk-app-devel-list
Probably it's a consequence of this work for porting GtkMenuBar to use css
gadgets internally:
https://gitlab.gnome.org/GNOME/gtk/commit/700286c6

You should be able to get the appropriate size if you add menu items to the
bar, i.e. as long as the
menubar is not empty you get the appropriate height with
gtk_widget_get_allocated_height().

Luca

Il giorno ven 23 nov 2018 alle ore 16:23 Sébastien Le Roux <
sebastien.ler...@ipcms.unistra.fr> ha scritto:

> Dear all, thanks for reading this,
> I recently updated GTK from 3.22.24 to 3.22.30 (Fedora 27 to Fedora 28
> update),
> doing so something changed in behaviour of the program I am working on
> (C code) at runtime.
>
> In my program I create a GtkMenuBar widget, using the code:
>
> GtkWidget * win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> GtkWidget * gl_vbox =  gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
> gtk_container_add (GTK_CONTAINER (win), gl_vbox);
> GtkWidget * menu_bar = gtk_menu_bar_new ();
> gtk_box_pack_start (GTK_BOX (gl_box), menu_bar, FALSE, FALSE, 0);
> GtkWidget * gl_area = gtk_gl_area_new ();
> gtk_widget_set_size_request (gl_area, 100, 100);
> gtk_box_pack_start (GTK_BOX (gl_box), gl_area, FALSE, FALSE, 0);
>
> Before my update I could get the height of the menu bar after drawing
> using:
>
> int size = gtk_widget_get_allocated_height (menu_bar);
>
> After my update the value of size is always 1, before the update it was
> around 15,
> obviously this new 1 value is messing with my program, not to mention
> that it is not
> what I see on the my computer screen, could anyone explain to me what to
> do the get
> the proper size of the GtkMenuBar ? (the gtk_widget_get_size_request is
> useless).
>
> Thanks for your help in the matter.
>
> Best regards.
>
> Sébastien Le Roux
>
> --
> ===
> Dr. Sébastien Le Roux
> Ingénieur de Recherche CNRS
> Institut de Physique et Chimie des Matériaux de Strasbourg
> Département des Matériaux Organiques
> 23, rue du Loess
> BP 43
> F-67034 Strasbourg Cedex 2, France
> E-mail: sebastien.ler...@ipcms.unistra.fr
> Webpage: http://www-ipcms.u-strasbg.fr/spip.php?article1771
> RINGS project: http://rings-code.sourceforge.net/
> ISAACS project: http://isaacs.sourceforge.net/
> Fax:   +33 3 88 10 72 46
> Phone: +33 3 88 10 71 62
> ===
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: return value from expose event / draw signal of GtkDrawingArea

2018-08-14 Thread Luca Bacci via gtk-app-devel-list
All right, I missed that!
Thank you!
Luca

2018-08-14 18:56 GMT+02:00 Emmanuele Bassi :

> Hi;
>
> On Tue, 14 Aug 2018 at 17:30, Luca Bacci via gtk-app-devel-list <
> gtk-app-devel-list@gnome.org> wrote:
>
>> Hi, does anyone know what meaning has the return value from expose event
>> handler (for gtk2) and draw signal (for gtk3) of GtkDrawingArea?
>>
>> When one should return TRUE, and when FALSE?
>>
>> I can't find any information in the reference manual
>>
>
> The "expose-event" signal in GTK+ 2.x comes from GtkWidget:
>
>   https://developer.gnome.org/gtk2/stable/GtkWidget.html#
> GtkWidget-expose-event
>
> The "draw" signal in GTK+ 3.x comes from GtkWidget:
>
>   https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-draw
>
> They have similar semantics as other signals in GTK+, like the
> input-related ones: returning TRUE means "I handled this signal emission,
> so do not propagate it further to other signal handlers"; returning FALSE
> means "I did not handle this signal emission, so propagate it further to
> other signal handlers".
>
> What "handling" means it depends on what you want to achieve.
>
> When using GTK+ 3.x, you're strongly encouraged to use the symbolic
> constants "GDK_EVENT_PROPAGATE" and "GDK_EVENT_STOP", instead, as they make
> the code easier to read.
>
> Ciao,
>  Emmanuele.
>
> --
> https://www.bassi.io
> [@] ebassi [@gmail.com]
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


return value from expose event / draw signal of GtkDrawingArea

2018-08-14 Thread Luca Bacci via gtk-app-devel-list
Hi, does anyone know what meaning has the return value from expose event
handler (for gtk2) and draw signal (for gtk3) of GtkDrawingArea?

When one should return TRUE, and when FALSE?

I can't find any information in the reference manual

Thank you!
Luca
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using SVG for icons (and scaling)

2018-07-18 Thread Luca Bacci via gtk-app-devel-list
SVG are supported in Gtk (and Glade)

Support for image formats is modularized in form of plugins, you just need
to get the plugin for SVG. In many distros you have to install 'librsvg' to
get the SVG loader.

As for scaling goes, GtkImage can scale images only when using icon-name
source and not from sources like files, resources, stock icons (this can
even be seen in Glade).
There has been some discussion on that: bug 728476


Currently, the solution is to use: gtk_icon_theme_add_resource_path ()

to augment the system theme with your icons and then use icon-name in
GtkImage to load your SVGs.
Then you can set 'icon-size' property of GtkImage to something you want to
(Menu, Small Toolbar, Large Toolbar, Button, Drag and Drop, Dialog - those
should take DPI in account) or set
'pixel-size' property to set the size you want in pixel.

But I think there is no way to display them when editing in glade

Luca


2018-07-18 4:32 GMT+02:00 Benjamin Summerton via gtk-app-devel-list <
gtk-app-devel-list@gnome.org>:

> I'm currently developing an application (using the Gtk 3.x series).  I've
> got some icons I'd like to use (for buttons n' stuff) and they are in SVG
> format.
>
> It's pretty trivial to turn these into a PNG, and then into my .glade
> file.  But I'm a bit concerned about how much smaller bitmap images will
> look on high DPI displays.
>
> I've been trying to search for the information on how to achieve this, but
> I haven't found much of anything.  So to summerize:
>
> How do I use an SVG as an Icon where I can scale it based on the DPI?
>
> And if I can't do this in Glade, how would I do this in code?
>
> Thanks,
> ~Ben
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_file_chooser_dialog in windows - hot to enable network places

2018-05-11 Thread Luca Bacci
Anyway GtkFileChooser uses GIO and GVFS
<https://wiki.gnome.org/Projects/gvfs>, which supports many protocols
<https://wiki.gnome.org/Projects/gvfs/backends>, including SMB.
It's very likely that GtkFileChooser is able to browse network shares on
Windows.
Do you use MSYS2 or vcpkg?

2018-05-11 14:05 GMT+02:00 Luca Bacci <luca.bacci...@gmail.com>:

> Maybe you can try GtkFileChooserNative
> <https://developer.gnome.org/gtk3/stable/gtk3-GtkFileChooserNative.html>
> You should be able to select network locations with that.
>
> Luca
>
> 2018-05-11 13:16 GMT+02:00 Wojciech Puchar <w.puc...@digitalsystems.pl>:
>
>> nobody program for windows?
>>
>>
>>
>>
>>  Forwarded Message 
>> Subject:gtk_file_chooser_dialog in windows - hot to enable
>> network places
>> Date:   Wed, 9 May 2018 09:39:34 +0200
>> From:   Wojciech Puchar <w.puc...@digitalsystems.pl>
>> To: gtk-app-devel-list list <gtk-app-devel-list@gnome.org>
>>
>>
>>
>> tried gtk_file_chooser_set_local_only to false and it doesn't change
>> anything.
>>
>>
>> Is it possible for gtk_file_chooser under windows to be able to browse
>> network locations?
>>
>> ___
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>>
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_file_chooser_dialog in windows - hot to enable network places

2018-05-11 Thread Luca Bacci
 Maybe you can try GtkFileChooserNative

You should be able to select network locations with that.

Luca

2018-05-11 13:16 GMT+02:00 Wojciech Puchar :

> nobody program for windows?
>
>
>
>
>  Forwarded Message 
> Subject:gtk_file_chooser_dialog in windows - hot to enable network
> places
> Date:   Wed, 9 May 2018 09:39:34 +0200
> From:   Wojciech Puchar 
> To: gtk-app-devel-list list 
>
>
>
> tried gtk_file_chooser_set_local_only to false and it doesn't change
> anything.
>
>
> Is it possible for gtk_file_chooser under windows to be able to browse
> network locations?
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [PyGObject] TreeView: Empty integer field or right aligned string

2018-05-09 Thread Luca Bacci
in python you can do

def cell_data_func(self, tree_column, cell, tree_model, iter, data):
if tree_column is self.col_a:
# code
else if tree_column is self.col_b:
# code

see How do I check if two variables reference the same object in Python?
<https://stackoverflow.com/questions/3647546/how-do-i-check-if-two-variables-reference-the-same-object-in-python>
you have make col_a and col_b class members


But I think it's better to just write two functions:

#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Pango

class TreeView(Gtk.TreeView):
def __init__(self, model):
Gtk.TreeView.__init__(self, model)

cell_a = Gtk.CellRendererText()
col_a = Gtk.TreeViewColumn('int',
   cell_a)
col_a.set_cell_data_func(cell_a, self.func_a, None)
self.append_column(col_a)

cell_b = Gtk.CellRendererText()
col_b = Gtk.TreeViewColumn('str',
   cell_b)
col_b.set_cell_data_func(cell_b, self.func_b, None)
self.append_column(col_b)

def func_a(self, tree_column, cell, tree_model, tree_iter, data):
cur_value = tree_model[tree_iter][0]
if cur_value == 0:
cell.set_property('text', '')
else:
cell.set_property('text', str(cur_value))

def func_b(self, tree_column, cell, tree_model, tree_iter, data):
cell.set_property('text', tree_model[tree_iter][1])

class TreeModel(Gtk.ListStore):
def __init__(self):
Gtk.ListStore.__init__(self, int, str)

# int and string
self.append([1, '111'])

# first column "empty" but displayed as "0"
# second column "empty" (but a workaround)
self.append([0, 'Hi!'])

# RIGHT alignment (second column) not working
self.append([3, '3'])


class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='Mein Gtk-Fenster')
self.set_default_size(400, 300)

self.model = TreeModel()
self.view = TreeView(self.model)

# layout
self.layout = Gtk.Grid()
self.add(self.layout)
self.layout.attach(self.view, 0, 1, 1, 1)

self.connect('destroy', Gtk.main_quit)
self.show_all()

if __name__ == '__main__':
win = Window()
Gtk.main()



2018-05-08 22:09 GMT+02:00 <c.bu...@posteo.jp>:

> On 2018-05-08 14:20 Luca Bacci <luca.bacci...@gmail.com> wrote:
> >- Use Cell Data Func for ultimate flexibility
>
> That is the signature
>  Gtk.TreeCellDataFunc(tree_column, cell, tree_model, iter, data)
>
> But how do I know which cell (row and column) is affected?
> I can extrat the row with tree_model[iter] but not the column.
>
> "tree_column" is of type Gtk.TreeViewColumn but doesn't even know its
> position (first, second, ... column). There is no integer indicating
> that.
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [PyGObject] TreeView: Empty integer field or right aligned string

2018-05-08 Thread Luca Bacci
To have empty int cells, you can either

   - use strings, instead of ints, in ListStore as you said
   - make place for a third value in ListStore, of type bool, and control
   the "visible" property of the first Cell Renderer with it (see code below)
   - Use Cell Data Func for ultimate flexibility

And here's the code

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class TreeView(Gtk.TreeView):
def __init__(self, model):
Gtk.TreeView.__init__(self, model)
col_a = Gtk.TreeViewColumn('int',
   Gtk.CellRendererText(),
   text=0,
   visible=2)
self.append_column(col_a)
col_b = Gtk.TreeViewColumn('str',
   Gtk.CellRendererText(),
   text=1)
self.append_column(col_b)


class TreeModel(Gtk.ListStore):
def __init__(self):
Gtk.ListStore.__init__(self, int, str, bool)

self.append([1, '111', True])
self.append([0, 'Hi!', False])
self.append([3, '3',   True])


class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='Mein Gtk-Fenster')
self.set_default_size(400, 300)

self.model = TreeModel()
self.view = TreeView(self.model)

# layout
self.layout = Gtk.Grid()
self.add(self.layout)
self.layout.attach(self.view, 0, 1, 1, 1)

self.connect('destroy', Gtk.main_quit)
self.show_all()

if __name__ == '__main__':
win = Window()
Gtk.main()

Luca

2018-05-08 12:08 GMT+02:00 Luca Bacci <luca.bacci...@gmail.com>:

> Hello!
>
> You can achieve what you want with the "xalign" property of CellRenderers
>
> col_b = Gtk.TreeViewColumn('str',
>Gtk.CellRendererText(xalign=1),
>text=1)
>
> xalign takes a value between 0 and 1.
> xalign=0 -> left-justified
> xalign=1 -> right-justified
>
> Luca
>
>
> 2018-05-06 12:01 GMT+02:00 <c.bu...@posteo.jp>:
>
>> X-Post: https://stackoverflow.com/q/50194505/4865723
>>
>> I want to have in a Gtk.TreeView
>>
>> - empty cells in a "int row" of a TreeView
>> - or (as a workaround) a right aligned "string row"
>>
>> There is a screenshot and example code in the StackOverflow question
>> linked in the first line of this post.
>>
>> The problem is
>>
>> - When I give 'None' to a 'int row' a '0' is displayed. I would
>>   expect an empty cell. I want that cell to be
>>   absolute empty.
>>
>> - A workaround is to use strings instead of int and just display the
>>   numbers as strings doing str(int).
>>   But then the content of each cell is left aligned by default.
>>   I tried to modify that. But this also has no effect.
>>
>> I attached the full example.
>> ___
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>>
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [PyGObject] TreeView: Empty integer field or right aligned string

2018-05-08 Thread Luca Bacci
Hello!

You can achieve what you want with the "xalign" property of CellRenderers

col_b = Gtk.TreeViewColumn('str',
   Gtk.CellRendererText(xalign=1),
   text=1)

xalign takes a value between 0 and 1.
xalign=0 -> left-justified
xalign=1 -> right-justified

Luca


2018-05-06 12:01 GMT+02:00 :

> X-Post: https://stackoverflow.com/q/50194505/4865723
>
> I want to have in a Gtk.TreeView
>
> - empty cells in a "int row" of a TreeView
> - or (as a workaround) a right aligned "string row"
>
> There is a screenshot and example code in the StackOverflow question
> linked in the first line of this post.
>
> The problem is
>
> - When I give 'None' to a 'int row' a '0' is displayed. I would
>   expect an empty cell. I want that cell to be
>   absolute empty.
>
> - A workaround is to use strings instead of int and just display the
>   numbers as strings doing str(int).
>   But then the content of each cell is left aligned by default.
>   I tried to modify that. But this also has no effect.
>
> I attached the full example.
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using Gtk.Builder to create a menubar.

2018-04-27 Thread Luca Bacci
Yes, actions get a prefix depending on where you put them. Every "action
container" has a prefix. In your case you add_action() to
GtkApplicationWindow and its prefix is "win"

I used your code to create an answer to my StackOverflow question
> https://stackoverflow.com/a/50051155/4865723
>

great!

Luca

2018-04-27 12:24 GMT+02:00 Marius Gedminas :

> On Thu, Apr 26, 2018 at 09:46:57PM +0200, c.bu...@posteo.jp wrote:
> > Thank you very much. Your example works for me but I don't understand
> > why. ;)
> >
> > > win.bar
> >
> > > action_bar = Gio.SimpleAction.new('bar', None)
> >
> > The name of the action in the XML and the code is different. Why? What
> > is the system behind it?
>
> "bar" is the name of the action.  "win" describes the action's scope.
>
> Check out the "Action scopes" section in https://developer.gnome.org/
> GAction/
> and a brief discussion on "quit" vs "app.quit" in the GActionMap
> section.
>
> Marius Gedminas
> --
> My own take on it as a writer is that I am passing my story across to Ms.
> Average Reader, who works all day (or night) as a nurse in a children's
> cancer
> hospice. She doesn't need some writer lecturing her about the human
> condition.
> She needs someone to hand her a drink.
> -- Lois McMaster Bujold's take on grimdark fiction
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using Gtk.Builder to create a menubar.

2018-04-26 Thread Luca Bacci
Hi, I did test it out, here's a working version:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio

class Window(Gtk.ApplicationWindow):
def __init__(self):
Gtk.Window.__init__(self)
self.set_default_size(200, 100)

#
self.interface_info = """

  

  Foo
  
Bar
win.bar
  

  

"""

builder = Gtk.Builder.new_from_string(self.interface_info, -1)

action_bar = Gio.SimpleAction.new('bar', None)
action_bar.connect('activate', self.on_menu)
self.add_action(action_bar)

menumodel = builder.get_object('TheMenuModel')
menubar = Gtk.MenuBar.new_from_model(menumodel)

# layout
self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.layout.pack_start(menubar, False, False, 0)
self.add(self.layout)

self.connect('destroy', Gtk.main_quit)
self.show_all()

def on_menu(self, action, value):
print('on_menu')

if __name__ == '__main__':
win = Window()
Gtk.main()


2018-04-26 11:01 GMT+02:00 Luca Bacci <luca.bacci...@gmail.com>:

> it should be like that (I can't test it right now, try yourself)
>
> #!/usr/bin/env python3
> import gi
> gi.require_version('Gtk', '3.0')
> from gi.repository import Gtk
> from gi.repository import Gio
>
> class Window(Gtk.ApplicationWindow):
> def __init__(self):
> Gtk.Window.__init__(self)
> self.set_default_size(200, 100)
>
> #
> self.interface_info = """
> 
>   
> 
>   Foo
>   
> Bar
> win.bar
>   
> 
>   
> 
> """
>
> builder = Gtk.Builder.new_from_string(self.interface_info, -1)
>
> action_bar = Gio.SimpleAction.new('bar', None)
> action_bar.connect('activate', self.on_menu)
> self.add_action(action_bar)
>
> menumodel = builder.get_object('TheMenuModel')
> menubar = Gtk.MenuBar.new_from_model(menumodel)
>
> # layout
> self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
> self.layout.pack_start(menubar, True, True, 0)
> self.add(self.layout)
>
> self.connect('destroy', Gtk.main_quit)
>     self.show_all()
>
> def on_menu(self, action, value):
> print('on_menu')
>
> if __name__ == '__main__':
> win = Window()
> Gtk.main()
>
>
> 2018-04-26 10:44 GMT+02:00 Luca Bacci <luca.bacci...@gmail.com>:
>
>> see here:
>>
>> https://wiki.gnome.org/HowDoI/GMenu
>> https://wiki.gnome.org/HowDoI/GAction
>>
>> self.interface_info = """
>>> 
>>>   
>>> 
>>>   Foo
>>>   
>>> Bar
>>>   
>>> 
>>>   
>>> 
>>> """
>>
>>
>> for every  you want to set at least two attributes: "name" and
>> "action". it should be
>>
>> self.interface_info = """
>> 
>>   
>> 
>>   Foo
>>   
>> Bar
>> win.bar
>>   
>> 
>>   
>> 
>> """
>>
>> you get the GMenuModel from the builder
>> menumodel = builder.get_object('TheMenuModel')
>> and you create a menubar widget from the menumodel:
>>
>> menubar = Gtk.MenuBar.new_from_model(menumodel)
>>
>>
>> 2018-04-26 7:10 GMT+02:00 <c.bu...@posteo.jp>:
>>
>>> Dear Eric,
>>>
>>> thank you for your quick reply.
>>>
>>> > There is a basic setup for the Gtk Application in Python here
>>> > https://developer.gnome.org/gnome-devel-demos/stable/hello-w
>>> orld.py.html.en
>>>
>>> Nice to know. Very helpful.
>>>
>>> > For C you can check
>>> > https://github.com/cecashon/OrderedSetVelociRaptor/blob/mast
>>> er/Misc/Csamples/gtk_app1.c
>>> > which has a menu but doesn't use builder with an application. Maybe
>>> > partial help.
>>>
>>> This code doesn't help me with my problem but brings up two questions.
>>>
>>&

Re: Using Gtk.Builder to create a menubar.

2018-04-26 Thread Luca Bacci
it should be like that (I can't test it right now, try yourself)

#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio

class Window(Gtk.ApplicationWindow):
def __init__(self):
Gtk.Window.__init__(self)
self.set_default_size(200, 100)

#
self.interface_info = """

  

  Foo
  
Bar
win.bar
  

  

"""

builder = Gtk.Builder.new_from_string(self.interface_info, -1)

action_bar = Gio.SimpleAction.new('bar', None)
action_bar.connect('activate', self.on_menu)
self.add_action(action_bar)

menumodel = builder.get_object('TheMenuModel')
menubar = Gtk.MenuBar.new_from_model(menumodel)

# layout
self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.layout.pack_start(menubar, True, True, 0)
self.add(self.layout)

self.connect('destroy', Gtk.main_quit)
self.show_all()

def on_menu(self, action, value):
print('on_menu')

if __name__ == '__main__':
win = Window()
Gtk.main()

2018-04-26 10:44 GMT+02:00 Luca Bacci <luca.bacci...@gmail.com>:

> see here:
>
> https://wiki.gnome.org/HowDoI/GMenu
> https://wiki.gnome.org/HowDoI/GAction
>
> self.interface_info = """
>> 
>>   
>> 
>>   Foo
>>   
>> Bar
>>   
>> 
>>   
>> 
>> """
>
>
> for every  you want to set at least two attributes: "name" and
> "action". it should be
>
> self.interface_info = """
> 
>   
> 
>   Foo
>   
> Bar
> win.bar
>   
> 
>   
> 
> """
>
> you get the GMenuModel from the builder
> menumodel = builder.get_object('TheMenuModel')
> and you create a menubar widget from the menumodel:
>
> menubar = Gtk.MenuBar.new_from_model(menumodel)
>
>
> 2018-04-26 7:10 GMT+02:00 <c.bu...@posteo.jp>:
>
>> Dear Eric,
>>
>> thank you for your quick reply.
>>
>> > There is a basic setup for the Gtk Application in Python here
>> > https://developer.gnome.org/gnome-devel-demos/stable/hello-w
>> orld.py.html.en
>>
>> Nice to know. Very helpful.
>>
>> > For C you can check
>> > https://github.com/cecashon/OrderedSetVelociRaptor/blob/mast
>> er/Misc/Csamples/gtk_app1.c
>> > which has a menu but doesn't use builder with an application. Maybe
>> > partial help.
>>
>> This code doesn't help me with my problem but brings up two questions.
>>
>> 1.
>> It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would
>> prefere this way instead of an XML string. It should be possible
>> in Python, too? Gtk.Menu or Gio.Menu?
>>
>> 2.
>> It uses " gtk_application_set_menubar()" which I don't want to use.
>> Because there is no "gtk_application_set_TOOLBAR()"! I need the menubar
>> and the toolbar as a widget to add them myself to the main window.
>> Or a " gtk_application_set_toolbar()" - don't understand why there
>> isn't one.
>>
>> It couldn't be so hard to create a menubar and a toolbar with
>> PyGObject?! Am I the first one who tries this? ;)
>> ___
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>>
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using Gtk.Builder to create a menubar.

2018-04-26 Thread Luca Bacci
see here:

https://wiki.gnome.org/HowDoI/GMenu
https://wiki.gnome.org/HowDoI/GAction

self.interface_info = """
> 
>   
> 
>   Foo
>   
> Bar
>   
> 
>   
> 
> """


for every  you want to set at least two attributes: "name" and
"action". it should be

self.interface_info = """

  

  Foo
  
Bar
win.bar
  

  

"""

you get the GMenuModel from the builder
menumodel = builder.get_object('TheMenuModel')
and you create a menubar widget from the menumodel:

menubar = Gtk.MenuBar.new_from_model(menumodel)


2018-04-26 7:10 GMT+02:00 :

> Dear Eric,
>
> thank you for your quick reply.
>
> > There is a basic setup for the Gtk Application in Python here
> > https://developer.gnome.org/gnome-devel-demos/stable/
> hello-world.py.html.en
>
> Nice to know. Very helpful.
>
> > For C you can check
> > https://github.com/cecashon/OrderedSetVelociRaptor/blob/
> master/Misc/Csamples/gtk_app1.c
> > which has a menu but doesn't use builder with an application. Maybe
> > partial help.
>
> This code doesn't help me with my problem but brings up two questions.
>
> 1.
> It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would
> prefere this way instead of an XML string. It should be possible
> in Python, too? Gtk.Menu or Gio.Menu?
>
> 2.
> It uses " gtk_application_set_menubar()" which I don't want to use.
> Because there is no "gtk_application_set_TOOLBAR()"! I need the menubar
> and the toolbar as a widget to add them myself to the main window.
> Or a " gtk_application_set_toolbar()" - don't understand why there
> isn't one.
>
> It couldn't be so hard to create a menubar and a toolbar with
> PyGObject?! Am I the first one who tries this? ;)
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: background color for GtkTreeView

2018-03-10 Thread Luca Bacci
try with

treeview:selected {
  background-color: white;
}

Luca

2018-03-10 14:26 GMT+01:00 :

> Hi there,
>
> I'm trying to change the background-color of a GtkTreeView by adding a
> css provider with the following style set:
>
> treeview { background-color: #fffae1; }
>
> Unfortunately this has the effect that the row selection color changes
> from the default blue to this particular background color as well.
>
> Note that I'm aware that I can change the background color of
> individual rows. However, I want to change the color of the entire
> widget including the whitespace.
>
> I can't figure out how to prevent the row selection color from changing
> as well.
>
> Any help would be greatly appreciated.
>
> Tilo
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list