Can someone help me make the SLR dialog do what I want?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Can someone help me make the SLR dialog do what I want?

Tim Wunder (Lists)
So after complaining about the new SLR dialog for the millionth time on IRC, I
was told that I should just send in a patch that makes it do what I want. Not
being a programmer, I said that it's easier to just whine and complain.
Regardless, I've decided to take what brain cells I have left and try to use
them to grok the code behind the SLR dialog. It's not easy. Neither one of my
brain cells are very keen on cooperating, and that makes it hard to
concentrate with all the bickering going on. But that's for me and my
therapist to discuss...

Anyway, what brings me here is the result of some experimenting I did changing
some things in dialog-sx-since-last-run.c.
The easy thing to change was to get rid of a bit of the geek-speak in the
dialog by changing the instance state names here:
static char* gnc_sx_instance_state_names[] = {
    N_("Ignored"),
    N_("Postponed"),
    N_("To be Created"),
    N_("Reminder"),
    N_("Automatically Created"),
    NULL
};
That was easy and I liked the result. Encouraged, I sought to reading more of
the code to see where it builds the list of SXs that get displayed. I want
only SXs that will be in a Reminder, To Be Created, or Automatically Created
state to display. I have a lot of SXs and having those that are neither ready
to be created nor reminders adds unwanted clutter for me.
While I was looking, I found
this: "gtk_tree_view_expand_all(dialog->instance_view);" in
GncSxSinceLastRunDialog*
gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances, GList
*auto_created_txn_guids)

Both my braincells agreed that this must be where all the SXs get expanded. So
I decided to comment that out to see what would happen. The result was as
expected, the dialog displays with none of the SXs expanded. That really
cleans up the dialog for me. So I got to thinking... there must be a way to
only expand a certain subset of SXs (like just expand the To Be Created SXs,
or even just the TBC's that have variables).

I'm guessing that using gtk_tree_view_expand_row () instead of
gtk_tree_view_expand_all() would somehow do it, but that's as far as I've
gotten. My C skills are virtually non-existent, but I'm willing to learn (at
least enough to accomplish what I want). Anybody care to explain to me how I
can attack this? Do I need to create a new function that expands only certain
rows in the list and use that to replace gtk_tree_view_expand_all()? How do I
do that?

A gentle nudge in the right direction would be much appreciated. :)

Thanks,
Tim

P.S. Another thought I had was to display the SXs in a color-coded manner so
that Automatics could be grey'd (I think the State column is grey'd out
already), the Reminders could be yellow, the To Be Created without variables
could be dark green while the To Be Created that have variables could be
displayd light green. (But that's just a crazy idea my left brain cell
had...)
--
Fedora Core release 6 (Zod), Linux 2.6.22.2-42.fc6
KDE: 3.5.7-9.fc6 Fedora
 22:20:01 up 4 days,  7:24,  3 users,  load average: 0.16, 0.15, 0.16
"It's what you learn after you know it all that counts" John Wooden

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can someone help me make the SLR dialog do what I want?

Josh Sled
Tim Wunder <[hidden email]> writes:
> That was easy and I liked the result. Encouraged, I sought to reading more of
> the code to see where it builds the list of SXs that get displayed. I want
> only SXs that will be in a Reminder, To Be Created, or Automatically Created
> state to display. I have a lot of SXs and having those that are neither ready
> to be created nor reminders adds unwanted clutter for me.

Most of the code in dialog-sx-since-last-run.c adapts the GncSxInstances
model into a GtkTreeModel, for direct use in the GtkTreeView which is the
(new) SLR dialog.

You may be better served by using a GtkTreeModelFilter to {dis,en}able the
rows you want.  This could be exposed via a new control in the dialog, maybe
with default settings in preferences ... I'm moderately opposed to user prefs
for this, though maybe we can hide them in an "Advanced" section of SX prefs,
or something.


> P.S. Another thought I had was to display the SXs in a color-coded manner so
> that Automatics could be grey'd (I think the State column is grey'd out
> already), the Reminders could be yellow, the To Be Created without variables
> could be dark green while the To Be Created that have variables could be
> displayd light green. (But that's just a crazy idea my left brain cell
> had...)

Color coding is always tricky ... in cultural significance ... in how it
interacts with custom gtk themes (dark-green on black = unreadable) ... the
HIG.

It might be better if they were instead three distinct super-trees (i.e., up
at the root level).  Or if the dialog could be "pivoted" around the two
display modes (grouped by State vs. integrated by SX).

--
...jsled
http://asynchronous.org/ - a=jsled; b=asynchronous.org; echo ${a}@${b}

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

attachment0 (194 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can someone help me make the SLR dialog do what I want?

Tim Wunder (Lists)
On Friday 24 August 2007 6:54:27 pm Josh Sled wrote:

> Tim Wunder <[hidden email]> writes:
> > That was easy and I liked the result. Encouraged, I sought to reading
> > more of the code to see where it builds the list of SXs that get
> > displayed. I want only SXs that will be in a Reminder, To Be Created, or
> > Automatically Created state to display. I have a lot of SXs and having
> > those that are neither ready to be created nor reminders adds unwanted
> > clutter for me.
>
> Most of the code in dialog-sx-since-last-run.c adapts the GncSxInstances
> model into a GtkTreeModel, for direct use in the GtkTreeView which is the
> (new) SLR dialog.
>
> You may be better served by using a GtkTreeModelFilter to {dis,en}able the
> rows you want.  This could be exposed via a new control in the dialog,
> maybe with default settings in preferences ... I'm moderately opposed to
> user prefs for this, though maybe we can hide them in an "Advanced" section
> of SX prefs, or something.
>
OK... So I :
"Filter specific rows, based on data from a "visible column", a column storing
booleans indicating whether the row should be filtered or not, or based on
the return value of a "visible function", which gets a model, iter and
user_data and returns a boolean indicating whether the row should be filtered
or not."
Where do I do this filtering? I guess I'd need to create some sort of "visible
function" that would make visible that which I want to filter??? And WTF is
an "iter"?

> > P.S. Another thought I had was to display the SXs in a color-coded manner
> > so that Automatics could be grey'd (I think the State column is grey'd
> > out already), the Reminders could be yellow, the To Be Created without
> > variables could be dark green while the To Be Created that have variables
> > could be displayd light green. (But that's just a crazy idea my left
> > brain cell had...)
>
> Color coding is always tricky ... in cultural significance ... in how it
> interacts with custom gtk themes (dark-green on black = unreadable) ... the
> HIG.
>
> It might be better if they were instead three distinct super-trees (i.e.,
> up at the root level).  Or if the dialog could be "pivoted" around the two
> display modes (grouped by State vs. integrated by SX).
Yeah, I know. But it would look purdy if it had colors. ;)

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can someone help me make the SLR dialog do what I want?

Josh Sled
Tim Wunder <[hidden email]> writes:
> OK... So I :
> "Filter specific rows, based on data from a "visible column", a column storing
> booleans indicating whether the row should be filtered or not, or based on
> the return value of a "visible function", which gets a model, iter and
> user_data and returns a boolean indicating whether the row should be filtered
> or not."
> Where do I do this filtering? I guess I'd need to create some sort of "visible
> function" that would make visible that which I want to filter???

Right ... well... you'll want to make that which you want to filter
*invisible*, but... ;)

When you create the GtkTreeModelFilter, you provide a function that fits the
signature of GtkTreeModelFilterVisibleFunc [1].  That is, make a new function
that has the same return value and arguments, and obeys the semantics
defined, then just use it's name to pass a pointer to the function for the
filtering algorithm to invoke later.  Something like:

    static gboolean
    _gnc_sxslr_filter_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
    {
        // filters out even rows
        // (I made up the function name; this is all handwavy... --jsled)
        gboolean is_even_row = gtk_tree_iter_get_row_number(model, iter) % 2 == 0;
        return !is_even_row;
    }

    // [...]

    GtkTreeModel *filtered_model = gtk_tree_model_filter_new(existing_model, NULL);
    gtk_tree_model_filter_set_visible_func(filtered_model, _gnc_sxslr_filter_func, NULL, NULL);


This is very similar to the use of an Interface in object-oriented languages
... the function pointer can be thought of as a functional interface.


> And WTF is
> an "iter"?

It represents a particular row in a particular model.  The 4th paragraph of
[2] has a bit more color.

Generally, you'll want to read [3] to get a sense of how the TreeModel and
TreeView (and the rest of the related classes/types) interact.  The design is
non-trival, but I don't really consider it overly complex, either.

[1] http://library.gnome.org/devel/gtk/unstable/GtkTreeModelFilter.html#GtkTreeModelFilterVisibleFunc
[2] http://library.gnome.org/devel/gtk/unstable/GtkTreeModel.html#id3511622
[3] http://library.gnome.org/devel/gtk/unstable/TreeWidget.html

(All this is in your local devhelp, too.)


>> Color coding is always tricky ... in cultural significance ... in how it
[...]
> Yeah, I know. But it would look purdy if it had colors. ;)

Heh. :)

--
...jsled
http://asynchronous.org/ - a=jsled; b=asynchronous.org; echo ${a}@${b}

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

attachment0 (194 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can someone help me make the SLR dialog do what I want?

Tim Wunder (Lists)
On Friday 24 August 2007 7:57:00 pm Josh Sled wrote:
<snip>
>     GtkTreeModel *filtered_model =
> gtk_tree_model_filter_new(existing_model, NULL);
> gtk_tree_model_filter_set_visible_func(filtered_model,
> _gnc_sxslr_filter_func, NULL, NULL);
>
>
> This is very similar to the use of an Interface in object-oriented
> languages ... the function pointer can be thought of as a functional
> interface.

Ugh... I appreciate your responding to my plea for help, but I really need
more basic and fundamental help than that. Assume I know /nothing/ about C
programming, and especially gtk+ programming.

I did some messing around to see if I could grok even a little of what you
told me (and what I read). Without much success, as indicated by:
dialog-sx-since-last-run.c:981: warning: ISO C90 forbids mixed declarations
and code
dialog-sx-since-last-run.c:982: warning: passing argument 1
of 'gtk_tree_model_filter_set_visible_func' from incompatible pointe

I did this:
_gnc_slr_filter(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{
    // just playing around with a function call
    gboolean SX_filter = 1;
    return !SX_filter;
}

and then...
//        gtk_tree_view_expand_all(dialog->instance_view);
        GtkTreeModel *filtered_model =
gtk_tree_model_filter_new(GTK_TREE_MODEL(dialog->editing_model), NULL);
        gtk_tree_model_filter_set_visible_func(filtered_model,_gnc_slr_filter,
NULL, NULL);

I'm sure what I've done isn't even close to what's supposed to be done, but
I'm old, so choose your clue bat with care. ;)  Don't I need to pass
variables when calling functions or something?

Also, how do I query the model (?) to determine its state (autocreate,
to-create, reminder, etc...)?

Thanks,
Tim
--
Fedora Core release 6 (Zod), Linux 2.6.22.2-42.fc6
KDE: 3.5.7-9.fc6 Fedora
 21:05:01 up 9 days,  6:09,  3 users,  load average: 0.24, 0.18, 0.11
"It's what you learn after you know it all that counts" John Wooden

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can someone help me make the SLR dialog do what I want?

Derek Atkins
Quoting Tim Wunder <[hidden email]>:

> I did some messing around to see if I could grok even a little of what you
> told me (and what I read). Without much success, as indicated by:
> dialog-sx-since-last-run.c:981: warning: ISO C90 forbids mixed declarations
> and code
> dialog-sx-since-last-run.c:982: warning: passing argument 1
> of 'gtk_tree_model_filter_set_visible_func' from incompatible pointe

This means that you declared a variable in the middle of the code.  E.g.
you did something like:

RetType fcn(FooType1 arg1, FooType2 arg2)
{
   FooType* var1;

   ... // some real code here

   BarType var2;    <===  This is the error.

   ... //
}

The fix is to move the declaration of "BarType var2" to the top of the
function.

> I did this:
[snip]
> and then...
> //        gtk_tree_view_expand_all(dialog->instance_view);
>        GtkTreeModel *filtered_model =
> gtk_tree_model_filter_new(GTK_TREE_MODEL(dialog->editing_model), NULL);

This is probably your BarType...

-derek

--
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       [hidden email]                        PGP key available

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel
Reply | Threaded
Open this post in threaded view
|

Re: Can someone help me make the SLR dialog do what I want?

Josh Sled
In reply to this post by Tim Wunder (Lists)
Sorry for the delay in response.

Tim Wunder <[hidden email]> writes:
> Ugh... I appreciate your responding to my plea for help, but I really need
> more basic and fundamental help than that. Assume I know /nothing/ about C
> programming, and especially gtk+ programming.

I hope that you didn't find all this too discouraging, and if you did, you'll
feel motivated to try again.


> I did some messing around to see if I could grok even a little of what you
> told me (and what I read). Without much success, as indicated by:
> dialog-sx-since-last-run.c:981: warning: ISO C90 forbids mixed declarations
> and code
> dialog-sx-since-last-run.c:982: warning: passing argument 1
> of 'gtk_tree_model_filter_set_visible_func' from incompatible pointe
>
> I did this:
> _gnc_slr_filter(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
> {
>     // just playing around with a function call
>     gboolean SX_filter = 1;
>     return !SX_filter;
> }
>
> and then...
> //        gtk_tree_view_expand_all(dialog->instance_view);
>         GtkTreeModel *filtered_model =
> gtk_tree_model_filter_new(GTK_TREE_MODEL(dialog->editing_model), NULL);
>         gtk_tree_model_filter_set_visible_func(filtered_model,_gnc_slr_filter,
> NULL, NULL);
>
> I'm sure what I've done isn't even close to what's supposed to be done, but
> I'm old, so choose your clue bat with care. ;)  Don't I need to pass
> variables when calling functions or something?
When you use a function pointer like this, you're not actually calling the
function ... you're just passing the pointer to the function for something
else (the GtkTreeModel, in this case) to invoke.  When it does eventually
call the function, it do need to pass arguments ... and it's going to pass
exactly the parameters that are expected of functions that fit the
"visible_func" signature.


> Also, how do I query the model (?) to determine its state (autocreate,
> to-create, reminder, etc...)?

The filter function only has access to its parameters; its "model" param is
generically a GtkTreeModel, but you (and the code) can assume it's actually a
GncSxSlrTreeModelAdapter.  This class has the GncSxInstanceModel that it's
adapting as the field "instances".

From a GtkIter one can get a GtkPath, which has specific indices; these
indices can then be used as list indices into the GncSxInstanceModel (and its
contained objects), to get the specific GncSxInstance that the GtkIter for a
row in the tree model corresponds to.

There is a convenience method in this file to do just those steps, taking the
model and an iter and translating it into the instance :)

    GncSxInstance*
    gnc_sx_slr_model_get_instance(GncSxSlrTreeModelAdapter *model, GtkTreeIter *iter)


Once you have the relevant GncSxInstance*, the creation state is in the
fields:

    GncSxInstanceState orig_state;
    GncSxInstanceState state;

...on the GncSxInstance class/struct
(see src/app-util/gnc-sx-instance-model.h:98).

--
...jsled
http://asynchronous.org/ - a=jsled; b=asynchronous.org; echo ${a}@${b}

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

attachment0 (194 bytes) Download Attachment