[gtkclient] Updated layout

This commit is contained in:
Joar Wandborg 2013-12-17 06:00:21 +01:00
parent d63c8107d8
commit f443e37d8c

View file

@ -19,41 +19,102 @@ class Accounting(Gtk.Window):
self.client = Client() self.client = Client()
self.set_border_width(3) self.set_border_width(0)
# Table self.set_default_geometry(640, 360)
self.table = Gtk.Table(3, 2, True) # Controls
self.add(self.table)
# Button
self.btn_load_transactions = Gtk.Button(label='Load transactions') self.btn_load_transactions = Gtk.Button(label='Load transactions')
self.btn_load_transactions.connect('clicked', self.on_button_clicked) self.btn_load_transactions.connect('clicked', self.on_button_clicked)
self.spinner = Gtk.Spinner() self.spinner = Gtk.Spinner()
renderer = Gtk.CellRendererText()
# Transaction stuff # Transaction stuff
self.transaction_store = Gtk.ListStore(str, str) self.transaction_data = None
self.transaction_store = Gtk.ListStore(str, str, str)
self.transaction_view = Gtk.TreeView(self.transaction_store) self.transaction_view = Gtk.TreeView(self.transaction_store)
renderer = Gtk.CellRendererText() self.id_column = Gtk.TreeViewColumn('ID', renderer, text=0)
date_column = Gtk.TreeViewColumn('Date', renderer, text=0) self.date_column = Gtk.TreeViewColumn('Date', renderer, text=1)
payee_column = Gtk.TreeViewColumn('Payee', renderer, text=1) self.payee_column = Gtk.TreeViewColumn('Payee', renderer, text=2)
self.transaction_view.append_column(date_column) self.transaction_view.append_column(self.date_column)
self.transaction_view.append_column(payee_column) self.transaction_view.append_column(self.payee_column)
# Layout self.transaction_view.connect('cursor-changed',
self.table.attach(self.btn_load_transactions, 0, 1, 0, 1) self.on_transaction_selected)
self.table.attach(self.spinner, 1, 2, 0, 1)
self.table.attach(self.transaction_view, 0, 2, 1, 3) # Postings
self.posting_store = Gtk.ListStore(str, str, str)
self.posting_view = Gtk.TreeView(self.posting_store)
self.account_column = Gtk.TreeViewColumn('Account', renderer, text=0)
self.amount_column = Gtk.TreeViewColumn('Amount', renderer, text=1)
self.symbol_column = Gtk.TreeViewColumn('Symbol', renderer, text=2)
self.posting_view.append_column(self.account_column)
self.posting_view.append_column(self.amount_column)
self.posting_view.append_column(self.symbol_column)
# The transaction detail view
self.lbl_payee = Gtk.Label()
# Layout setting
self.menu = Gtk.MenuBar.new()
self.ctrl_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
self.ctrl_box.pack_start(self.btn_load_transactions, False, False, 0)
self.ctrl_box.pack_start(self.spinner, False, False, 5)
self.detail_view = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
self.detail_view.pack_start(self.lbl_payee, False, True, 0)
self.detail_view.pack_start(self.posting_view, True, True, 0)
self.vertical = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
self.vertical.pack_start(self.ctrl_box, False, True, 0)
self.vertical.pack_start(self.transaction_view, True, True, 0)
self.paned = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
self.add(self.paned)
self.paned.add1(self.vertical)
self.paned.add2(self.detail_view)
# Show # Show
self.show_all() self.show_all()
self.spinner.hide() self.spinner.hide()
self.detail_view.hide()
def on_transaction_selected(self, widget):
selection = self.transaction_view.get_selection()
selection.set_mode(Gtk.SelectionMode.SINGLE)
xact_store, xact_iter = selection.get_selected()
xact_id = xact_store.get_value(xact_iter, 0)
_log.debug('selection: %s', xact_id)
for transaction in self.transaction_data:
if transaction.id == xact_id:
self.lbl_payee.set_text(transaction.payee)
self.posting_store.clear()
for posting in transaction.postings:
self.posting_store.append([
posting.account,
str(posting.amount.amount),
posting.amount.symbol
])
self.detail_view.show()
break
def on_button_clicked(self, widget): def on_button_clicked(self, widget):
def load_transactions(): def load_transactions():
@ -70,10 +131,12 @@ class Accounting(Gtk.Window):
self.spinner.hide() self.spinner.hide()
_log.debug('transactions: %s', transactions) _log.debug('transactions: %s', transactions)
self.transaction_data = transactions
self.transaction_store.clear() self.transaction_store.clear()
for transaction in transactions: for transaction in transactions:
self.transaction_store.append([ self.transaction_store.append([
transaction.id,
transaction.date.strftime('%Y-%m-%d'), transaction.date.strftime('%Y-%m-%d'),
transaction.payee transaction.payee
]) ])