Own drag icon with same color and font settings as the default drag icon in a Gtk.TreeView

2018-09-14 Thread c.buhtz--- via gtk-app-devel-list
I have a stackoverflow question with example code open with this:
https://stackoverflow.com/q/52339893/4865723

The Gtk.TreeView implements a default drag icon. It use the background
color of the TreeView, it's font and the complete row-content as string.

I want the same (background-color, font-face, font-size, font-color)
but with a shorter string (only the second of three columns).

How does the TreeView get this values?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


PyGObject: ask for system/theme colors

2018-09-14 Thread c.buhtz--- via gtk-app-devel-list
I don't want to use colors defined by myself e.g. with RGB-values.
I want to use colors from the system (Windows, Linux, ...) and/or the
theme.

For example I need the background color of a highlighted menu or list
item.

Is there a way?

Can I also ask for fonts like this?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Cancel a Drag & Drop for some specific items in a Gtk.TreeView

2018-09-11 Thread c.buhtz--- via gtk-app-devel-list
On 2018-09-11 13:50 Yuri Khan  wrote:
> Reading the “GtkTreeView drag-and-drop”[1] page, I get the impression
> that you’d need to implement a wrapper around GtkTreeStore, or
> possibly a class derived from GtkTreeStore, that also overrides the
> row_draggable method so that it returns False for non-draggable rows.

Thanks for the hint.

It is Gtk.TreeView.do_row_draggable()

https://lazka.github.io/pgi-docs/Gtk-3.0/classes/TreeDragSource.html#Gtk.TreeDragSource.do_row_draggable

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

Re: "draw" icon with string

2018-09-10 Thread c.buhtz--- via gtk-app-devel-list
Dear cecashon,

thanks for your code. This works currently.
I need to improve it in the future to support different plattforms
(fonts) and screen resolutions (scale).

kind
Christian


On 2018-09-10 19:32
 wrote:
>  
> Give this a try. It creates a surface, draws on it and then returns
> the surface so that it can be put in an image widget. 
> 
> 
> import gi
> gi.require_version('Gtk', '3.0')
> from gi.repository import Gtk, Gdk
> import cairo
> 
> class MainWindow(Gtk.Window):
>     def __init__(self):
>     Gtk.Window.__init__(self)
>     self.set_title("Surface")
>     self.set_default_size(400, 400)
>     self.set_position(Gtk.WindowPosition.CENTER)
> 
>     surface = self.get_surface()
> 
>     image = Gtk.Image()
>     image.set_from_surface(surface)
>     image.set_vexpand(True)
>     image.set_hexpand(True)
> 
>     grid = Gtk.Grid()
>     grid.attach(image, 0, 0, 1, 1)
>     self.add(grid)
> 
>     def get_surface(self):
>     surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 200, 200)
>     cr = cairo.Context(surface)
>     
>     cr.set_source_rgb(0.8, 0.8, 0.8)
>     cr.paint()
> 
>     cr.set_source_rgb(0.0, 1.0, 0.0)
>     cr.set_line_width(6)
>     cr.rectangle(0, 0, 200.0, 200.0) 
>     cr.stroke()
>     cr.set_source_rgb(0.0, 0.0, 1.0)
>     cr.set_line_width(3)
>     cr.move_to(0.0, 100.0)
>     cr.line_to(200.0, 100.0)
>     cr.stroke()
>     cr.move_to(100.0, 0.0)
>     cr.line_to(100.0, 200.0)
>     cr.stroke()
> 
>     cr.set_source_rgb(1.0, 0.0, 1.0)
>     cr.select_font_face("Arial", cairo.FONT_SLANT_NORMAL,
> cairo.FONT_WEIGHT_BOLD) cr.set_font_size(40)
>     (x, y, width, height, dx, dy) = cr.text_extents("Cairo")
>     cr.move_to(200/2 - width/2, 200/2 + height/2) 
>     cr.show_text("Cairo")
> 
>     cr.set_source_rgb(0.0, 0.0, 0.0)
>     cr.set_line_width(1)
>     cr.rectangle(200/2-width/2, 200/2 - height/2, width, height)
>     cr.stroke() 
> 
>     return surface
> 
> win = MainWindow()
> win.connect("delete-event", Gtk.main_quit)
> win.show_all()
> Gtk.main()
>    
>  
>  
> -Original Message-
> From: c.buhtz--- via gtk-app-devel-list 
> To: c.buhtz--- via gtk-app-devel-list 
> Cc: c.buhtz 
> Sent: Sun, Sep 9, 2018 2:14 pm
> Subject: Re: "draw" icon with string
> 
> On 2018-09-09 23:01 "c.buhtz--- via gtk-app-devel-list"
>  wrote:
> > It is unclear to me how to create a cairo.Surface instance.
> > <https://pycairo.readthedocs.io/en/latest/reference/surfaces.html#cairo.Surface>
> >   
> 
> And I can not see any text/string drawing methods in the surface
> class. ___
> 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

Cancel a Drag & Drop for some specific items in a Gtk.TreeView

2018-09-10 Thread c.buhtz--- via gtk-app-devel-list
I also opened this question on
https://stackoverflow.com/q/51974845/4865723

I have a Gtk.TreeView here. Most but not all of the items should be
able to be dragged & dropped. For example the first item should not be
able to be dragged & dropped but it should be selectable.

How can I realize this? Maybe I have to use the drag-begin signal and
stop the drag in there. But I don't know how.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: "draw" icon with string

2018-09-10 Thread c.buhtz--- via gtk-app-devel-list
Thanks Chris for your example code.

But I am not able to map your C code to Pycairo.
Even the doc of Pycairo is not helpfull. No examples, no class trees.
I still don't know how to draw text to a cairo surface. It is also
unclear to me which surface I should use.


On 2018-09-09 18:22 Chris Moller  wrote:
> Here's a sample I came across some time ago.. Basically, you need to
> do all the drawing using cairo primitives.
> 
> 
> /*
>      Test drawing on a toggle button.
> 
>      gcc -Wall cairobutton.c -o cairobutton `pkg-config --cflags
> --libs gtk+-3.0`
> 
>      C. Eric Cashon
> */
> 
> #include 
> 
> gboolean
> draw_button1 (GtkWidget *widget, cairo_t *cr, gpointer user_data)
> {
>    guint width = gtk_widget_get_allocated_width(GTK_WIDGET(widget));
>    guint height = gtk_widget_get_allocated_height(GTK_WIDGET(widget));
> 
>    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
>      cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
>      cairo_paint (cr);
>    }
>    else {
>      cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
>      cairo_paint (cr);
>    }
> 
>    //Draw rectangle around the button.
>    cairo_set_line_width (cr, 10.0);
>    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
>    cairo_rectangle (cr, 0, 0, width, height);
>    cairo_stroke (cr);
> 
>    //Add the text.
>    cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
>    cairo_text_extents_t extents;
>    cairo_select_font_face (cr, "Courier", CAIRO_FONT_SLANT_NORMAL,
>                CAIRO_FONT_WEIGHT_BOLD);
>    cairo_set_font_size (cr, 20);
>    cairo_text_extents (cr, "Cairo Toggle!", );
>    cairo_move_to (cr, width/2 - extents.width/2, height/2 + 
> extents.height/2);
>    cairo_show_text (cr, "Cairo Toggle!");
> 
>    return TRUE;
> }
> 
> int
> main (int argc, char **argv)
> {
>    gtk_init (, );
> 
>    GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>    gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER);
>    gtk_window_set_default_size (GTK_WINDOW (window), 200, 100);
>    gtk_window_set_title (GTK_WINDOW (window), "Toggle Button");
>    g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit),
> NULL);
> 
>    GtkWidget *button1 = gtk_toggle_button_new ();
>    gtk_widget_set_app_paintable (button1, TRUE);
>    gtk_widget_set_hexpand (button1, TRUE);
>    gtk_widget_set_vexpand (button1, TRUE);
>    g_signal_connect (button1, "draw", G_CALLBACK (draw_button1),
> NULL);
> 
>    GtkWidget *grid = gtk_grid_new ();
>    gtk_container_set_border_width (GTK_CONTAINER (grid), 10);
>    gtk_grid_attach (GTK_GRID (grid), button1, 0, 0, 1, 1);
> 
>    gtk_container_add (GTK_CONTAINER (window), grid);
> 
>    gtk_widget_show_all (window);
>    gtk_main ();
>    return 0;
> }
> 
> 
> On 09/09/18 17:14, c.buhtz--- via gtk-app-devel-list wrote:
> > On 2018-09-09 23:01 "c.buhtz--- via gtk-app-devel-list"
> >  wrote:  
> >> It is unclear to me how to create a cairo.Surface instance.
> >> <https://pycairo.readthedocs.io/en/latest/reference/surfaces.html#cairo.Surface>
> >>   
> > And I can not see any text/string drawing methods in the surface
> > class. ___
> > 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
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: "draw" icon with string

2018-09-09 Thread c.buhtz--- via gtk-app-devel-list
On 2018-09-04 00:26 Emmanuele Bassi  wrote:
> this means you need to create a Cairo
> surface and render on it using the Cairo API.

It is unclear to me how to create a cairo.Surface instance.


Also help(cairo.Surface) doesn't help here.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject: modify drag icon in TreeView

2018-09-09 Thread c.buhtz--- via gtk-app-devel-list
There is a problem with documentation.
https://gitlab.gnome.org/GNOME/pygobject/issues/251

The answer can be found here.
https://stackoverflow.com/a/52248549/4865723
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: "draw" icon with string

2018-09-03 Thread c.buhtz--- via gtk-app-devel-list
Dear Emmanuele,

you describe how to set a drag icon. I know how to do this.
https://stackoverflow.com/q/51975256/4865723

But the question is how do I create my icon?

e.g. TreeView create it's own one, too. It is based on the row content.
I can I do the same? e.g. I only want the content of the second
column/cell and not the complete row?

 On 2018-09-02 02:33 Emmanuele Bassi
 wrote:
> On Sat, 1 Sep 2018 at 22:20, c.buhtz--- via gtk-app-devel-list <
> gtk-app-devel-list@gnome.org> wrote:
> 
> > I want to use my own drag-icon in a Gtk.TreeView where this is set
> > as an instance of GdkPixbuf.Pixbuf.
> >
> > I can I create/draw a pixbuf and create Text, background and border
> > color in it?
> >  
> 
> Typically, GtkTreeView will call gtk_tree_view_create_row_drag_icon()
> for the default drag surface — a box with the contents of the row.
> 
> https://developer.gnome.org/gtk3/stable/GtkTreeView.html#gtk-tree-view-create-row-drag-icon
> 
> If you want to override that, you should call
> gtk_drag_set_icon_surface(), using a Cairo surface you created:
> 
> https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-set-icon-surface
> 
> The GtkTreeView uses the default handler of the GtkWidget::drag-begin
> signal to set the drag icon; you want your own handler to be called
> after that, so you can override the drag icon with your own. To do
> that, you can:
> 
>  - call gtk_tree_view_unset_model_drag_source() or
> gtk_tree_view_unset_model_drag_dest() and implement your own drag and
> drop handling
>  - call g_signal_stop_emission_by_name() in your drag-begin callback
> to stop the signal emission chain, and prevent the default handler
> from running
>  - use g_signal_connect_after() to connect your callback, and have
> your handler run after the default one
>  - subclass GtkTreeView and override the drag_begin() virtual function
> without chaining up, to implement your own handler
> 
> Ciao,
>  Emmanuele.
> 

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

"draw" icon with string

2018-09-01 Thread c.buhtz--- via gtk-app-devel-list
I want to use my own drag-icon in a Gtk.TreeView where this is set as
an instance of GdkPixbuf.Pixbuf.

I can I create/draw a pixbuf and create Text, background and border
color in it?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject: modify drag icon in TreeView

2018-08-28 Thread c.buhtz--- via gtk-app-devel-list
On 2018-08-22 23:17  wrote:
> I opened a stackoverflow question with a MWE for this
> 
> https://stackoverflow.com/q/51975256/4865723

There is still no answer. Does anyone of you have a hint where I could
ask such questions, too?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


PyGObject: Cancel a Drag & Drop in Gtk.TreeView

2018-08-22 Thread c.buhtz--- via gtk-app-devel-list
Here on stackoverflow I am asking how do I cancel a Drag & Drop for
some specific items in a Gtk.TreeView.

https://stackoverflow.com/q/51974845/4865723
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject: modify drag icon in TreeView

2018-08-16 Thread c.buhtz--- via gtk-app-devel-list
I can not find a "drag-begin" example on the internet.

On 2018-08-14 00:02 "c.buhtz--- via gtk-app-devel-list"
 wrote:
> I want to use the "drag-begin" event to show an individual drag-icon.
> <https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/Widget.html#Gtk.Widget.signals.drag_begin>
> 
> But it has no effect in my Gtk.TreeView
>  - I tested with connect() and connect_after()
>  - the events are called (tested by print-call)
>  - I created a GdkPixbuf.Pixbuf.new_from_file() which returns a valid
>object and not None
> 
> Any idea?
> ___
> 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


PyGObject: modify drag icon in TreeView

2018-08-13 Thread c.buhtz--- via gtk-app-devel-list
I want to use the "drag-begin" event to show an individual drag-icon.


But it has no effect in my Gtk.TreeView
 - I tested with connect() and connect_after()
 - the events are called (tested by print-call)
 - I created a GdkPixbuf.Pixbuf.new_from_file() which returns a valid
   object and not None

Any idea?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


make Gtk.TreeViewColumn always visibel

2018-08-12 Thread c.buhtz--- via gtk-app-devel-list
I have a tree view with 3 columns.

Sometimes the first column has a quite huge width what causes the right
column (number 3) disapear.

Is there a way to make such a column never disapear?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


PyGObject: FileChooserDialog and transient parent

2018-08-12 Thread c.buhtz--- via gtk-app-devel-list
Below you see a minimal working example using Gtk.FileChooserNative as
a file-open dialog. While running with Python 3.6.6 I recieve
this warning message

"GtkDialog mapped without a transient parent. This is discouraged."

I understand the logic behind it but can not find a solution BECAUSE
the docu is IMO inusfficient. Please see



This docu is about PyGObject which is Python, isn't it!? But there is C
code in the example. Also with my C experience this doesn't help.

What IMO is missing in that documentation and what would help me to
understand and solve the problem by myself without contacting the list
or issue tracker is
 - Description of the Constructor or new()
 - all possible parameters accepted by this constructor (I have no idea
   where and how to put a parent to it)
 - I minimal Python3 example describing how this dialog should be used.
   What I mean is using run() after construction, get_filename() and a
   destroy() at the end.

This is the MWE

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


class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.connect("delete-event", Gtk.main_quit)
self.set_default_size(300, 200)

dlg = Gtk.FileChooserNative(
title='Title',
action=Gtk.FileChooserAction.OPEN
)
dlg.run()
dlg.destroy()

win = MainWindow()
win.show_all()
Gtk.main()
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [PyGObject] Drag & Drop in a TreeView

2018-07-28 Thread c.buhtz--- via gtk-app-devel-list
Dear Colomban,

thanks for your great hint.

> You get inserted/deleted signals for moved rows so you can know
> when and how things changed if needed

This signals are also emited when I manually insert and delete data in
the model. How do I know if a insert/delete signal was caused by a drag
and drop "event"?

One workaround in my mind would be to do
Gtk.TreeView.set_reordable(False) when manipulating the model manualy
(without drag and drop).

Do you see another more elegant way?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [PyGObject] Drag & Drop in a TreeView

2018-07-27 Thread c.buhtz--- via gtk-app-devel-list
Dear Reuben

On 2018-07-23 08:03 Reuben Rissler  wrote:
> This is how I have done it in the past. Note, I do not proclaim 
> spectacular or Pythonic code, and would humbly accept any corrections 
> and/or better ways to accomplish this. It seems to me there should be
> a way to let the TreeView do this work itself, but alas, I have not
> found it yet.

Your code works for me - thank you very much. But I also have the
question if anyone here could improve it or show a more easier and
elegant way.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [PyGObject] Drag & Drop in a TreeView

2018-07-22 Thread c.buhtz--- via gtk-app-devel-list
I see attachments are removed
This is the code


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


class MainWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="TreeView Drag and Drop")
self.connect("delete-event", Gtk.main_quit)
self.set_default_size(400, 300)

# "model" with dummy data
self.store = Gtk.TreeStore(str, str)
for i in range(5):
self.store.append(None, ['Item {}'.format(i),
'{}'.format(i*100)]) # treeview
self.view = Gtk.TreeView(model=self.store)
self.add(self.view)

# build columsn
colA = Gtk.TreeViewColumn('Col A', Gtk.CellRendererText(),
text=0) self.view.append_column(colA)
colB = Gtk.TreeViewColumn('Col B', Gtk.CellRendererText(),
text=1) self.view.append_column(colB)

# DnD events
self.view.connect("drag-begin", self.drag_begin)
self.view.connect("drag-data-get", self.drag_data_get)
self.view.connect("drag-drop", self.drag_drop)
self.view.connect("drag-data-delete", self.drag_data_delete)
self.view.connect("drag-data-received", self.drag_data_received)
self.view.connect("drag-end", self.drag_end)

target_entry = Gtk.TargetEntry.new('text/uri-list', 2, 0)
self.view.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[target_entry], Gdk.DragAction.DEFAULT|Gdk.DragAction.MOVE)
self.view.enable_model_drag_dest([target_entry],
Gdk.DragAction.DEFAULT|Gdk.DragAction.MOVE)

def drag_begin(self, treeview, context):
print('== Drag started')

def drag_data_get(self, treeview, context, data, info, time):
print('== Drag data requested by destination')

def drag_drop(self, treeview, context, selection, info, time):
print('== Drag data droped')

def drag_data_received(self, treeview, context, x, y, selection,
info, time): print('== Drag data received')

def drag_end(self, treeview, context):
print('== Drag data end')

def drag_data_delete(self, treeview, context):
print('== Drag data delete')

win = MainWindow()
win.show_all()
Gtk.main()
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


[PyGObject] Drag & Drop in a TreeView

2018-07-22 Thread c.buhtz--- via gtk-app-devel-list
I am totally confused about this topic. I think I miss some fundamental
understanding on how PyGObject works here.

I want to drag & drop items of one TreeView inside itself. Not other
widgets or applications. I just want to drag item 2 and drop it between
item 4 and 5.

I found some resources about this topic

This states that DnD in a TreeView is different from the rest of
PyGObject concept.
https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html

Some incomplete, out-dated, not working or to complex examples
http://jcoppens.com/soft/howto/pygtk_dnd/index.en.php
https://stackoverflow.com/q/29673495/4865723
https://stackoverflow.com/q/13882076/4865723

I even don't know which one of the events I really need. There are to
much. I attached a minimal example with a two column (str, str)
treeview.

Can you give me a hint and a direction on which points I should focus
on?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: clear() on TreeView causes select-events

2018-07-15 Thread c.buhtz--- via gtk-app-devel-list
Dear Reuben,

thanks for your answer.

> And after you study the MVC pattern, you will see why the whole
> Treeview stack works the way it does. Google MVC and Gtk MVC. It is
> worthwhile reading if you plan on constructing treeviews. It may not
> make sense immediately, but eventually you may see the light like I
> did.

This is an often made misunderstanding.
Gtk (and every other GUI-lib) only implements the V (and sometimes the
C) in the MVC-Pattern. Gtk.ListStore is not a model in the meaning of
the MVC pattern!
One advantage of the MVC is that you can replace each layer/component
with another one. This is not possible when all components of the MVC
pattern are impelmented with the same lib (e.g. Gtk).

For example imagine: You want to replace the Gtk-View (Gtk.TreeCtr) with
another GUI-lib, or with a VirtualReality view or just a audio-view
(speak the content of the Tree).
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: clear() on TreeView causes select-events

2018-07-06 Thread c.buhtz--- via gtk-app-devel-list
Dear Reuben,

thanks for your hint.

On 2018-07-03 21:19 Reuben Rissler  wrote:
> I have had very similar experiences with liststore.clear() in
> Python3.5 and Mint 18. To work around this I do:
> 
> store = treeview.get_model()  #may not be necessary in your code
> treeview.set_model(None)
> store.clear()
> store.append('my string or etc')
> treeview.set_model(store)

This works. Disconnecting the "model" from the "view" before doing
clear is the key. But very uncomfortable.

What not worked was to unselect before doing clear. I don't understand
why.

This all sounds to me like a mystic behaviour what could be a bug. But
I am not deep enough into Gtk so I won't open an official report about
this. It is on the core devs and experts in that list to decide if this
is an serious issue or not.

kind
Christian
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


clear() on TreeView causes select-events

2018-07-03 Thread c.buhtz--- via gtk-app-devel-list
Hello

I observer an interesting behavior (PyGObject, Gtk3.0, Python3.6,
Debian unstable with XFCE desktop):

An item (row) in a TreeView is selected (highlighted).
Then calling .clear() on the TreeView causes an select-event for each
item (row) below that selected item (row).

Am I right here?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Link Gtk.ListStore to the real data

2018-06-02 Thread c.buhtz
On 2018-06-02 20:07 '-'  wrote:
> Can you make the data_list a field on your class? It's a list
> with indices, right? Then, on the iter you get from your selection,
> use gtk_tree_model_get_path and gtk_tree_path_get_indices. Finally
> get the item from your data_list by that index.

You mean e. g. if the first row in the view is selected then it must be
the first item in the 'data_list'?

In that case I have to take care about that the order of the data
items is the same then in the view. This is impossible because
 - the view can modify the ordering based on the columns
 - the view use more then one data_list at the same time.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Link Gtk.ListStore to the real data

2018-06-02 Thread c.buhtz
Does no one has an idea?
Am I the only one facing such problems?

https://stackoverflow.com/q/50643938/4865723

On 2018-05-31 23:59  wrote:
> I am looking for an elegant and pythonic way to connect the model of a
> Gtk.ListStore (the content container for a Gtk.TreeView) to the real
> data.
> 
> Thinking the C-way I would store a pointer as a hidden column linking
> to the data structure in each entry of Gtk.ListStore. But I don't see
> a way to do this.
> 
> The data is just one or more lists of dictionaries. The point is that
> the Gtk.ListStore can represent on complete data list or only a
> selection of some entries of multiple data lists. It is important to
> know that the entries doesn't have a unique key. A data list could
> look like this:
> 
> data_list = [
> {
> 'title': 'A title',
> 'read_status': False
> },
> {
> 'title': 
> }]
> 
> Imagine news or mail messages. The font is bold if 'read_status' is
> False and otherwise. When I click on an entry in the Gtk.TreeView the
> font is modified from bold to normal. But the entry in the data list
> should know this also! But how does the Gtk.TreeView or the
> Gtk.ListStore entry know the real data?
> 
> How do you solve such problems?
> 
> I could create unique keys for each data list entry and store this
> keys in a hidden column in the Gtk.ListStore. But this would blow up
> the (real) code and would cause some other problems I need to deal
> with. What is about pythons id() function? Or is there any other
> solution? ___
> 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


Link Gtk.ListStore to the real data

2018-05-31 Thread c.buhtz
I am looking for an elegant and pythonic way to connect the model of a
Gtk.ListStore (the content container for a Gtk.TreeView) to the real
data.

Thinking the C-way I would store a pointer as a hidden column linking to
the data structure in each entry of Gtk.ListStore. But I don't see a
way to do this.

The data is just one or more lists of dictionaries. The point is that
the Gtk.ListStore can represent on complete data list or only a
selection of some entries of multiple data lists. It is important to
know that the entries doesn't have a unique key. A data list could look
like this:

data_list = [
{
'title': 'A title',
'read_status': False
},
{
'title': 
}]

Imagine news or mail messages. The font is bold if 'read_status' is
False and otherwise. When I click on an entry in the Gtk.TreeView the
font is modified from bold to normal. But the entry in the data list
should know this also! But how does the Gtk.TreeView or the
Gtk.ListStore entry know the real data?

How do you solve such problems?

I could create unique keys for each data list entry and store this keys
in a hidden column in the Gtk.ListStore. But this would blow up the
(real) code and would cause some other problems I need to deal with.
What is about pythons id() function? Or is there any other solution?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject Maybe bug with alternate row colors in a Gt.TreeView

2018-05-15 Thread c.buhtz
Thank you for the link.

On 2018-05-15 15:01 Emmanuele Bassi  wrote:
>  - the CSS "regions" were problematic for the whole theming system,
> so they were removed before we made the CSS selectors stable
>  - GtkTreeView does not use widgets, so CSS selectors do not
> typically work properly (that's why "regions" had to be introduced in
> the first place)

I have no idea what you are talking about. ;)

What does it mean? I can do stripping or not?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject Maybe bug with alternate row colors in a Gt.TreeView

2018-05-15 Thread c.buhtz
Does know one of you have an idea about it or more detailed
informations.

I also don't know if it is a bug or if I am doing something wrong.
My problem is I don't know to much about CSS.

On 2018-05-11 22:57  wrote:
> Please see this StackOverflow question.
> https://stackoverflow.com/q/50281987/4865723
> 
> Is there an official bug about setup alternate (even & odd) row colors
> with CSS in a Gtk.TreeView?
> 
> Can someone give a link to the bug ticket?
> ___
> 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


PyGObject Maybe bug with alternate row colors in a Gt.TreeView

2018-05-11 Thread c.buhtz
Please see this StackOverflow question.
https://stackoverflow.com/q/50281987/4865723

Is there an official bug about setup alternate (even & odd) row colors
with CSS in a Gtk.TreeView?

Can someone give a link to the bug ticket?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject: cell_data_func or own Renderer for date column?

2018-05-11 Thread c.buhtz
>     do_render(self, cr, widget, bg_area, cell_area, flags):
>     # implement your own rendering here

How do I "render"? I have no idea about it.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: PyGObject: Which types accepted in a Gtk.ListStore

2018-05-11 Thread c.buhtz
> However, if I remember correctly, in the bindings several native
> python types like int, float and str are mapped to GObject types
> automatically.

What exactly is "mapped" to GObject here?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


PyGObject: remove a renderer from a TreeViewColumn

2018-05-10 Thread c.buhtz
I add multiple Gtk.CellRenderer to one Gtk.TreeViewColumn with its
pack_start() method.

But how can I remove one of the renderers?

Currently I do Gtk.TreeViewColumn.clear() and rebuild the column again
with all renderers except the one I want to be removed. But this is a
workaround.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


PyGObject: cell_data_func or own Renderer for date column?

2018-05-09 Thread c.buhtz
I want to have a date column in a Gtk.ListView. The field in the model
is a real "datetime.date". Based on that the content of the column
could display this:

  "2018-05-07"
  "2 days ago"
  "this week"
  "7th May"
  "7. Mai '18"

This is all based on the same "datetime.date" instance. The user decide
how to display. So I need maximum flexibility.

A cell_data_function is an option here to implement this. Is it a good
choice?

What is about deriving from Gtk.CellRendererText?
But I don't see how to do this. May I only overload the render()
function? But how can I read from datetime.date object and convert it
to a string?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


PyGObject: Which types accepted in a Gtk.ListStore

2018-05-09 Thread c.buhtz
>From the api-reference here


it is unclear for me what types are accepted for the columns.
The parameter "*column_types" is not explained.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: PyGObject: Spinner as content of a TreeView cell

2018-05-09 Thread c.buhtz
On 2018-05-09 22:52  wrote:
> Does anyone see a way to draw/insert a Gtk.Spinner (or any other
> Gtk.Widget) in a cell of a Gtk.TreeView?

Oh, there is a CellRendererSpinner for it! :)
An example can be found here


But I don't get it and opened a StackOverflow question for it because
my spinner doesn't spin.

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


PyGObject: Spinner as content of a TreeView cell

2018-05-09 Thread c.buhtz
Does anyone see a way to draw/insert a Gtk.Spinner (or any other
Gtk.Widget) in a cell of a Gtk.TreeView?

I want to use a Spinner to indicate to the user that currently there is
work (e. g. ongoing download) or activity with a specific item.
___
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 c.buhtz
On 2018-05-08 14:20 Luca Bacci  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


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

2018-05-06 Thread c.buhtz
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


Re: Using Gtk.Builder to create a menubar.

2018-04-26 Thread c.buhtz
On 2018-04-26 18:10 Luca Bacci  wrote:
> Hi, I did test it out, here's a working version:

I used your code to create an answer to my StackOverflow question
https://stackoverflow.com/a/50051155/4865723
___
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 c.buhtz
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?
___
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-25 Thread c.buhtz
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


Using Gtk.Builder to create a menubar.

2018-04-25 Thread c.buhtz
X-Post: I was redirected from
https://mail.gnome.org/archives/python-hackers-list/2018-April/msg4.html
to here.

I try to use Gtk.Builder to create a menubar. It is not working
because the documentation is not clear for me. There is no exmple for
a IMO usual thing like a menubar.

To improve documentation and the help other new users I created a
question with example code on StackOverflow.
https://stackoverflow.com/q/49964906/4865723

Currently I can put the XML-string and the Gio.Action together. Not
sure if this is the correct way!? But the next step is the main
problem. I don't know how to create a menubar widget out of it.

btw: I don't want to use Gtk.Application.set_menubar(). Because there
is no Gtk.Application.set_toolbar() and currently I see no advantage on
having a Gtk-based application object.

This is the code

#!/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
  

  

"""

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)

menubar = builder.get_object('TheMenu')

# 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, widget):
print(widget)

if __name__ == '__main__':
win = Window()
Gtk.main()
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list