After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 639906 - Printing out more easily readable information
Printing out more easily readable information
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Python Bindings
git-master
Other Linux
: Normal enhancement
: ---
Assigned To: Mark Jenkins
Mark Jenkins
Depends on:
Blocks:
 
 
Reported: 2011-01-18 22:28 UTC by Christoph Holtermann
Modified: 2018-06-29 22:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
This patch adds a __str__ function to GncNumeric (546 bytes, patch)
2011-01-18 22:28 UTC, Christoph Holtermann
needs-work Details | Review
Adding __str__ and __unicode__ methods to GncNumeric (1.23 KB, patch)
2011-01-19 10:58 UTC, Christoph Holtermann
committed Details | Review
This patch adds a __str__ and __unicode__ method to Split and Transaction (2.87 KB, patch)
2011-01-20 21:43 UTC, Christoph Holtermann
committed Details | Review
Changing the way Strings are formatted in Subfunctions Split and Transaction (7.74 KB, patch)
2011-01-23 18:03 UTC, Christoph Holtermann
none Details | Review
Changing the way __format__ works for Split and Transaction (7.74 KB, patch)
2011-01-23 18:09 UTC, Christoph Holtermann
none Details | Review
Changing the way __format__ works for Split and Transaction (8.59 KB, patch)
2011-01-23 23:50 UTC, Christoph Holtermann
accepted-commit_now Details | Review
Changing the way __format__ works for Split and Transaction (8.59 KB, patch)
2011-01-24 11:55 UTC, Christoph Holtermann
committed Details | Review
patch against Revision 20689. str_methods.py improved. (17.19 KB, patch)
2011-05-26 18:35 UTC, Christoph Holtermann
committed Details | Review

Description Christoph Holtermann 2011-01-18 22:28:51 UTC
Created attachment 178675 [details] [review]
This patch adds a __str__ function to GncNumeric

When accessing the objects of the python-bindings i would like to have a nicer
representation of the different objects. I don't know the possibilities very well so I try.

This first patch adds a __str__ function to GncNumeric which makes it possible to have 

>> g=gnucash.GncNumeric(1,2)
>> print g
0.5
>> g
<gnucash.gnucash_core.GncNumeric object at 0xb5168bcc>

This seems very nice to me.

I wonder if this would be useful for the more Complex objects or if there would be a better solution.
Comment 1 Christian Stimming 2011-01-19 09:15:15 UTC
Comment on attachment 178675 [details] [review]
This patch adds a __str__ function to GncNumeric

Please add a special treatment for the error case denom == 0. Otherwise, the patch is fine :-)
Comment 2 Christoph Holtermann 2011-01-19 10:58:17 UTC
Created attachment 178702 [details] [review]
Adding __str__ and __unicode__ methods to GncNumeric

1) I decided to let the methods return "Division by Zero" for denom()==0.
2) As proposed in http://stackoverflow.com/questions/1307014/python-str-versus-unicode i created both __str__ and __unicode__.
3) I use format to fix the decimal places to 2. It would be nice if the number would be configurable.
Comment 3 Christian Stimming 2011-01-20 20:21:38 UTC
Comment on attachment 178702 [details] [review]
Adding __str__ and __unicode__ methods to GncNumeric

r20128, thanks!
Comment 4 Christoph Holtermann 2011-01-20 21:43:16 UTC
Created attachment 178891 [details] [review]
This patch adds a __str__ and __unicode__ method to Split and Transaction

Thanks for committing my patch !

For the more complex financial objects i chose a different approach.

The printing functions are located in one module. Importing this module adds
these functions as methods to the classes defined in gnucash_core.py.

Attention to committing person: This patch introduces a new file "str_methods.py".
Comment 5 Christian Stimming 2011-01-22 14:40:04 UTC
Comment on attachment 178891 [details] [review]
This patch adds a __str__ and __unicode__ method to Split and Transaction

r20145, thanks!
Comment 6 Christoph Holtermann 2011-01-23 18:03:06 UTC
Created attachment 179087 [details] [review]
Changing the way Strings are formatted in Subfunctions Split and Transaction

the __format__ function does not offer a functionality to cut values that are too long.

In this patch i use a Class ClassWithCutting__format__ which is wrapped around every value that should be formatted. It's __format__-function uses the standardsyntax but is changed so that it cuts values.

In this way a list of Splits can be printed out nicely.
Comment 7 Christoph Holtermann 2011-01-23 18:09:33 UTC
Created attachment 179088 [details] [review]
Changing the way __format__ works for Split and Transaction
Comment 8 Christoph Holtermann 2011-01-23 23:50:04 UTC
Created attachment 179111 [details] [review]
Changing the way __format__ works for Split and Transaction

Some small changes.
Comment 9 Christoph Holtermann 2011-01-24 11:55:10 UTC
Created attachment 179149 [details] [review]
Changing the way __format__ works for Split and Transaction

Small bugfix
Comment 10 Christian Stimming 2011-02-10 19:38:00 UTC
Comment on attachment 179149 [details] [review]
Changing the way __format__ works for Split and Transaction

r20263, thanks!
Comment 11 Christoph Holtermann 2011-05-26 18:35:04 UTC
Created attachment 188696 [details] [review]
patch against Revision 20689. str_methods.py improved.
Comment 12 Christoph Holtermann 2011-05-26 18:43:00 UTC
The previous patch:

str_methods.py
- added a flagging system to change the output of the __str__ methods
- added unicode and str-methods to invoice and entry

function_class.py
- added modified add_method and add_classmethods to implement the previous

gnucash_business.py
- add methods_return_instance_lists for method Invoice.GetEntries
Comment 13 Christian Stimming 2011-05-27 06:39:58 UTC
Comment on attachment 188696 [details] [review]
patch against Revision 20689. str_methods.py improved.

r20695, thanks!
Comment 14 John Ralls 2018-06-29 22:52:21 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=639906. Please update any external references or bookmarks.