Share and Money Management  0.16
Classes | Functions | Variables
gui.helper Namespace Reference

Functions to support GUI functions e.g. More...

Classes

class  ReverseDict
 A dictionary which can lookup values by key, and keys by value. More...
 

Functions

def formatShareNotesShort (share, max_len=25)
 Returns additional note to a share - short formatted. More...
 
def formatShareNotesLong (share)
 Returns additional note to a share - long formatted. More...
 
def formatCurrencySign (currency)
 Returns the sign of a currency or an empty string. More...
 
def formatCurrencyShort (currency)
 Returns the currency sign or code or an empty string. More...
 
def formatCurrencyLong (currency)
 Returns the formatted currency or an empty string. More...
 
def formatDate (date, fmt='%d.%m.%Y')
 Returns the formatted date or an empty string. More...
 
def formatDecimal (value, places=2, grouping=True)
 Returns the formatted decimal value or an empty string. More...
 
def formatDuration (duration)
 Returns the given duration formatted. More...
 
def formatDailyQuoteEvent (quote)
 Returns the DailyQuote.event formatted. More...
 
def formatExchange (exchange)
 Returns the formatted exchange or an empty string. More...
 
def formatMoney (value, currency, places=3, grouping=True)
 Returns the formatted decimal value incl. More...
 
def formatPercent (value, places=3)
 Returns the formatted decimal value incl. More...
 
def formatPosition (pos)
 Returns the formatted position or an empty string. More...
 
def formatShare (share)
 Returns the formatted share or an empty string. More...
 
def formatShareShort (share)
 Returns the formatted share or an empty string. More...
 
def formatShareKind (share)
 Returns the type of the share or an empty string. More...
 
def formatTransactionKind (transaction)
 Returns the transaction type as a string or an empty string. More...
 
def moneyfmt (value, places=2, curr='', sep=', dp='.', pos='', neg='-', trailneg='')
 Convert Decimal to a money formatted string. More...
 
def wxdate2pydate (wxdate)
 Convert a date from wxDateTime to Python datetime.date. More...
 
def pydate2wxdate (pydate)
 Convert a date from Python datetime.date to wxDateTime. More...
 
def formatTransactionElements (transaction)
 Format all attributes of a Transaction for showing and sorting. More...
 

Variables

 RE_WHITESPACES = re.compile(r'\s{2,}|[\r\n]')
 Precompiled RE pattern to match two or more white spaces or single linebreak characters. More...
 
 DAYS_PER_YEAR = decimal.Decimal('365')
 Number of days in a year. More...
 

Detailed Description

Functions to support GUI functions e.g.

to format values

Author
Carsten Grohmann <mail (at) carstengrohmann (dot) de>
License:
GPL version 2.0

Function Documentation

◆ formatCurrencyLong()

def gui.helper.formatCurrencyLong (   currency)

Returns the formatted currency or an empty string.

See also
smm.objects.Currency
formatCurrencySign()
formatCurrencyShort()

◆ formatCurrencyShort()

def gui.helper.formatCurrencyShort (   currency)

Returns the currency sign or code or an empty string.

See also
smm.objects.Currency.sign
formatCurrencySign()
formatCurrencyLong()

Referenced by gui.helper.formatMoney().

Here is the caller graph for this function:

◆ formatCurrencySign()

def gui.helper.formatCurrencySign (   currency)

Returns the sign of a currency or an empty string.

See also
smm.objects.Currency.sign
formatCurrencyShort()
formatCurrencyLong()

◆ formatDailyQuoteEvent()

def gui.helper.formatDailyQuoteEvent (   quote)

Returns the DailyQuote.event formatted.

◆ formatDate()

def gui.helper.formatDate (   date,
  fmt = '%d.%m.%Y' 
)

Returns the formatted date or an empty string.

Referenced by gui.helper.formatPosition(), and gui.helper.formatTransactionElements().

Here is the caller graph for this function:

◆ formatDecimal()

def gui.helper.formatDecimal (   value,
  places = 2,
  grouping = True 
)

Returns the formatted decimal value or an empty string.

Formatting will be done automatically using the database of the local conventions

Parameters
valueThe decimal value
placesRequired number of places after the decimal point
groupingGrouping part before decimal point
Returns
Formatted decimal values or an empty Unicode string for non-decimal values

References gui.helper.moneyfmt().

Referenced by gui.helper.formatTransactionElements().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ formatDuration()

def gui.helper.formatDuration (   duration)

Returns the given duration formatted.

Parameters
durationDuration in days as a decimal.Decimal.
See also
DAYS_PER_YEAR

Referenced by gui.helper.formatTransactionElements().

Here is the caller graph for this function:

◆ formatExchange()

def gui.helper.formatExchange (   exchange)

Returns the formatted exchange or an empty string.

Referenced by gui.helper.formatTransactionElements().

Here is the caller graph for this function:

◆ formatMoney()

def gui.helper.formatMoney (   value,
  currency,
  places = 3,
  grouping = True 
)

Returns the formatted decimal value incl.

the currency or an empty string

Formatting will be done automatically using the database of the local conventions

Parameters
valueThe decimal value
currencyA smm.objects.Currency instance
placesRequired number of places after the decimal point
groupingGrouping part before decimal point
Returns
Formatted decimal values or an empty Unicode string for non-decimal values

References gui.helper.formatCurrencyShort(), and gui.helper.moneyfmt().

Referenced by gui.helper.formatTransactionElements().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ formatPercent()

def gui.helper.formatPercent (   value,
  places = 3 
)

Returns the formatted decimal value incl.

percent sign or an empty string

Parameters
valueThe decimal value
placesRequired number of places after the decimal point

References gui.helper.moneyfmt().

Here is the call graph for this function:

◆ formatPosition()

def gui.helper.formatPosition (   pos)

Returns the formatted position or an empty string.

See also
smm.objects.Position

References gui.helper.formatDate(), and gui.helper.formatShare().

Here is the call graph for this function:

◆ formatShare()

def gui.helper.formatShare (   share)

Returns the formatted share or an empty string.

See also
smm.objects.Share
formatShareKind()

Referenced by gui.helper.formatPosition(), gui.helper.formatTransactionElements(), and gui.helper.formatTransactionKind().

Here is the caller graph for this function:

◆ formatShareKind()

def gui.helper.formatShareKind (   share)

Returns the type of the share or an empty string.

See also
smm.objects.Share.kind
formatShare()

◆ formatShareNotesLong()

def gui.helper.formatShareNotesLong (   share)

Returns additional note to a share - long formatted.

See also
smm.objects.Share.notes
formatShareNotesShort()

◆ formatShareNotesShort()

def gui.helper.formatShareNotesShort (   share,
  max_len = 25 
)

Returns additional note to a share - short formatted.

Parameters
shareThe smm.objects.Share object
max_lenLength of the note
See also
smm.objects.Share.notes
formatShareNotesLong()

◆ formatShareShort()

def gui.helper.formatShareShort (   share)

Returns the formatted share or an empty string.

See also
smm.objects.Share
formatShareKind()

◆ formatTransactionElements()

def gui.helper.formatTransactionElements (   transaction)

Format all attributes of a Transaction for showing and sorting.

Example:
>>> tr
<Transaction object at 0xa3445ec -- #1 (date: 2007-06-15, count: -90, ...>
>>> import pprint
>>> pprint.pprint(res)
{'count_show': u'90.000',
'count_sort': Decimal('-90'),
'date_show': u'15.06.2007',
'date_sort': '2007-06-15',
'exchange_show': u'XETRA, Germany',
'exchange_sort': u'xetra, germany',
'fee_show': u'5,19 \u20ac',
'fee_sort': Decimal('5.19'),
'holding_period_show': u'',
'holding_period_sort': -1,
'kind_show': u'Verkauf',
'kind_sort': u'verkauf',
'share_show': u'Ahlers Vz',
'share_sort': u'ahlers vz',
'value_show': u'13,300 \u20ac',
'value_sort': Decimal('13.30'),
'volume_show': u'1197,000 \u20ac',
'volume_sort': Decimal('-1197.00')}
Returns
Dictionary with formatted elements

References gui.helper.formatDate(), gui.helper.formatDecimal(), gui.helper.formatDuration(), gui.helper.formatExchange(), gui.helper.formatMoney(), gui.helper.formatShare(), and gui.helper.formatTransactionKind().

Here is the call graph for this function:

◆ formatTransactionKind()

def gui.helper.formatTransactionKind (   transaction)

Returns the transaction type as a string or an empty string.

See also
smm.objects.Transaction.kind

References gui.helper.formatShare(), and gui.helper.moneyfmt().

Referenced by gui.helper.formatTransactionElements().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moneyfmt()

def gui.helper.moneyfmt (   value,
  places = 2,
  curr = '',
  sep = ',
  dp = '.',
  pos = '',
  neg = '-',
  trailneg = '' 
)

Convert Decimal to a money formatted string.

Parameters
valuethe decimal value
placesrequired number of places after the decimal point
curroptional currency symbol before the sign (may be blank)
sepoptional grouping separator (comma, period, space, or blank)
dpdecimal point indicator (comma or period) only specify as blank when places is zero
posoptional sign for positive numbers: '+', space or blank
negoptional sign for negative numbers: '-', '(', space or blank
trailnegoptional trailing minus indicator: '-', ')', space or blank
Example:
>>> d = Decimal('-1234567.8901')
>>> moneyfmt(d, curr='$')
'-$1,234,567.89'
>>> moneyfmt(d, places=0, sep='.', dp='', neg='', trailneg='-')
'1.234.568-'
>>> moneyfmt(d, curr='$', neg='(', trailneg=')')
'($1,234,567.89)'
>>> moneyfmt(Decimal(123456789), sep=' ')
'123 456 789.00'
>>> moneyfmt(Decimal('-0.02'), neg='<', trailneg='>')
'<0.02>'
Source:
Receipes of the Python decimal module

Referenced by gui.helper.formatDecimal(), gui.helper.formatMoney(), gui.helper.formatPercent(), and gui.helper.formatTransactionKind().

Here is the caller graph for this function:

◆ pydate2wxdate()

def gui.helper.pydate2wxdate (   pydate)

Convert a date from Python datetime.date to wxDateTime.

See also
wxdate2pydate()

◆ wxdate2pydate()

def gui.helper.wxdate2pydate (   wxdate)

Convert a date from wxDateTime to Python datetime.date.

See also
pydate2wxdate()

Variable Documentation

◆ DAYS_PER_YEAR

gui.helper.DAYS_PER_YEAR = decimal.Decimal('365')

Number of days in a year.

See also
formatDuration()

◆ RE_WHITESPACES

gui.helper.RE_WHITESPACES = re.compile(r'\s{2,}|[\r\n]')

Precompiled RE pattern to match two or more white spaces or single linebreak characters.