###############################################################################
# File:        guMoneyTransactionsListView.py
# Appointment: List of Sciences
# Project:     GalaxyU
# Author:      AR
# History:
# 18.01.2014 Created
###############################################################################
import wxTools
import guObjects
import guApp
import guListView

import wx


#===============================================================================
# List control
#===============================================================================
class CMoneyTransactionsViewCtrl(guListView.CListViewCtrlWithBuilder):
    #---------------------------------------------------------------------------
    def __init__(self, parent, aListCreator):
        guListView.CListViewCtrlWithBuilder.__init__(self, parent, aListCreator)
        
        
    #---------------------------------------------------------------------------
    # Redefined virtual
    def PrepareBuilder(self, aBuilder):
        # Add columns
        aBuilder.AddColumn("Nation", lambda data: data.NationName)
        aBuilder.AddColumn("Delta", lambda data: "{0:.2f}".format(data.Delta), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Result", lambda data: "{0:.2f}".format(data.Result), wx.LIST_FORMAT_RIGHT, True)
        aBuilder.AddColumn("Comment", lambda data: data.Text)

        # Colour attributes
        self.__attrDeltaPositive = wx.ListItemAttr()
        self.__attrDeltaPositive.SetTextColour((0,0,200))
        self.__attrDeltaNegative = wx.ListItemAttr()
        self.__attrDeltaNegative.SetTextColour((200,0,0))
        self.__attrDeltaZero = wx.ListItemAttr()
        self.__attrDeltaZero.SetTextColour((0,100,0))

    #---------------------------------------------------------------------------
    def OnGetItemAttr(self, item):
        d = self.GetItems()[self.RowToItem(item)].Delta
        return self.__attrDeltaPositive if d > 0 else\
            (self.__attrDeltaNegative if d < 0 else self.__attrDeltaZero)

#-------------------------------------------------------------------------------

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Shows a list of Sciences
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def ShowMoneyTransactionsList():
    return guApp.Application.WindowsCollection.RegisterAndShow(\
        lambda: guListView.CListViewFrame(\
            guApp.Application.GetMainWindow(),
            lambda: guApp.Application.GetReport().MoneyTransactions,
            lambda panel, aListCreator: CMoneyTransactionsViewCtrl(panel, aListCreator),
            "CMoneyTransactionsViewCtrl", 
            "Money Transactions"))
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
