Re: Searching for text in PDF files is wrong

2018-12-19 Thread Osmo Antero via gtk-app-devel-list
Re-hi,

I think the mark_text(...) function can be simplified.
Check also open_page(...).

Ref: https://pastebin.com/52dU2kv8

Feliz Natal
Moma

Osmo Antero  escreveu no dia quarta, 19/12/2018 à(s)
20:08:

> Hello,
>
> This code might work even you resize the window.
> Please see: https://pastebin.com/GJMPwLU3
>
> It draws the selected text in the "draw" event.
>
> ps. I hard coded the PDF_DOC and FIND_TEXT values.
>
> Feliz Natal,
>   moma, Portugal
>
> Marius Gedminas  escreveu no dia segunda, 3/12/2018
> à(s) 17:12:
>
>> On Fri, Nov 30, 2018 at 09:56:12PM +0100, Радомир Хаџић via
>> gtk-app-devel-list wrote:
>> > I use poppler_page_find_text() to find text in PDF files. This returns
>> > GList of pointers to PopplerRectangles. Then I use
>> > poppler_page_render_selection() to mark the found text.
>> >
>> > What is wrong is that PopplerRectangles returned by
>> > poppler_page_find_text() are incompatible with those that
>> > poppler_page_render_selection() requests, which is why the wrong text
>> > is selected.
>> >
>> > I have found that to make those two compatible, I have to do the
>> > following to PopplerRectangles returned by poppler_page_find_text():
>> > 1) SWAP(rectangle.x1, rectangle.x2);
>> > 2) SWAP(rectangle.y1, rectangle.y2);
>> > 3) rectangle.y1 = page_height - rectangle.y1;
>> > 4) rectangle.y2 = page_height - rectangle.y2;
>> > But this does not solve the problem because the marked text cycles
>> > between right and wrong again while resizing the window.
>>
>> > is: https://pastebin.com/h3F56Yv7
>>
>> You're doing in-place coordinate conversions in your drawing code.
>> Every expose event will change the coordinates event, which is why
>> you're seeing the flip-flopping.
>>
>> Do the conversion only once, or use a local temporary PopplerRectangle
>> variable and avoid in-place conversions.
>>
>> (I'm not familiar with poppler's APIs and cannot say if your conversion
>> code is correct.)
>>
>> HTH,
>> Marius Gedminas
>> --
>> Lutetium is the heaviest and hardest of the rare earth metals, and is
>> used in
>> the production of umlauts and other fraktur font features.
>> -- Charles Stross
>> ___
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
>
>
> --
> Sent from my PC, laptop or phone with Ubuntu-Linux.
>


-- 
Sent from my PC, laptop or phone with Ubuntu-Linux.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Searching for text in PDF files is wrong

2018-12-19 Thread Osmo Antero via gtk-app-devel-list
Hello,

This code might work even you resize the window.
Please see: https://pastebin.com/GJMPwLU3

It draws the selected text in the "draw" event.

ps. I hard coded the PDF_DOC and FIND_TEXT values.

Feliz Natal,
  moma, Portugal

Marius Gedminas  escreveu no dia segunda, 3/12/2018 à(s)
17:12:

> On Fri, Nov 30, 2018 at 09:56:12PM +0100, Радомир Хаџић via
> gtk-app-devel-list wrote:
> > I use poppler_page_find_text() to find text in PDF files. This returns
> > GList of pointers to PopplerRectangles. Then I use
> > poppler_page_render_selection() to mark the found text.
> >
> > What is wrong is that PopplerRectangles returned by
> > poppler_page_find_text() are incompatible with those that
> > poppler_page_render_selection() requests, which is why the wrong text
> > is selected.
> >
> > I have found that to make those two compatible, I have to do the
> > following to PopplerRectangles returned by poppler_page_find_text():
> > 1) SWAP(rectangle.x1, rectangle.x2);
> > 2) SWAP(rectangle.y1, rectangle.y2);
> > 3) rectangle.y1 = page_height - rectangle.y1;
> > 4) rectangle.y2 = page_height - rectangle.y2;
> > But this does not solve the problem because the marked text cycles
> > between right and wrong again while resizing the window.
>
> > is: https://pastebin.com/h3F56Yv7
>
> You're doing in-place coordinate conversions in your drawing code.
> Every expose event will change the coordinates event, which is why
> you're seeing the flip-flopping.
>
> Do the conversion only once, or use a local temporary PopplerRectangle
> variable and avoid in-place conversions.
>
> (I'm not familiar with poppler's APIs and cannot say if your conversion
> code is correct.)
>
> HTH,
> Marius Gedminas
> --
> Lutetium is the heaviest and hardest of the rare earth metals, and is used
> in
> the production of umlauts and other fraktur font features.
> -- Charles Stross
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



-- 
Sent from my PC, laptop or phone with Ubuntu-Linux.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Python3, GObject objects & models

2018-12-19 Thread Marius Gedminas
On Tue, Dec 18, 2018 at 01:01:45PM -0500, Adam Tauno Williams wrote:
> I have created, and registered, a custom GObject type [an object].  I
> can place that type into a ListModel: aka model =
> Gtk.ListModel(MyClass).
> 
> One of the advantages of creating a GObject is the whole property
> system - - - and most notably change signals.
> 
> What I have not been able to find is how to connect/map something like
> a Gtk.CellRendererText to a property, such that having a type in a
> model has some advantage [vs. a model like (int, str, str)].  ???

I think you have to use Gtk.TreeViewColumn.set_cell_data_func(), but I
also fail to see any advantages you'd get of doing that instead of using
plain data types in the model.

Marius Gedminas
-- 
Remember the... the... uhh.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Python3, GObject objects & models

2018-12-19 Thread Reuben Rissler
So I am assuming that you are looking for a discussion and not for a 
specific problem to be solved. If this is not the case, please post the 
code that is not working for you, delete my email and forgive me.



On 12/18/2018 01:01 PM, Adam Tauno Williams wrote:

I have created, and registered, a custom GObject type [an object].  I
can place that type into a ListModel: aka model =
Gtk.ListModel(MyClass).

One of the advantages of creating a GObject is the whole property
system - - - and most notably change signals.
And how exactly does that improve on the /model.connect("row-changed")/, 
and the signal family already in place?


What I have not been able to find is how to connect/map something like
a Gtk.CellRendererText to a property, such that having a type in a
model has some advantage [vs. a model like (int, str, str)].  ???
For myself, I use Glade for all the Treeviews I can as I would rather 
see the Treeview I build than try to memorize the construction of code. 
My few attempts in trying to subclass Treeview components got more messy 
than just hooking into their signal system and tweaking the data as it 
goes from point A to point B.


In the case I have in mind, I was trying to add a autocomplete feature 
to a Gtk.CellRendererCombo. I finally discovered that Gtk already has a 
provision for that by providing a /editing-started/ signal to add the 
autocomplete object to the entry inside the combo.


With that said, I have tens of Treeviews in my accounting system, and am 
always on the lookout for more fluent/better ways of showing data.


One other case worth mentioning was trying to get a Decimal column to 
play nicely in a Treeview (floats are not acceptable in accounting). I 
could use a PyObject type and display it using cell renderer display 
functions. However, when filtering and sorting, all manner of extra code 
had to be added to work with the Decimals. In the end it was faster and 
easier to use a two column approach, a /str/ for display and an /float/ 
for sorting. Then all the calculations are done in SQL, server side.


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