247 lines
No EOL
24 KiB
HTML
247 lines
No EOL
24 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>accounting.gtkclient — Accounting API 0.1-beta documentation</title>
|
|
|
|
<link rel="stylesheet" href="../../_static/pydoctheme.css" type="text/css" />
|
|
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../../',
|
|
VERSION: '0.1-beta',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../../_static/doctools.js"></script>
|
|
<link rel="top" title="Accounting API 0.1-beta documentation" href="../../index.html" />
|
|
<link rel="up" title="accounting" href="../accounting.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../../genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="../../http-routingtable.html" title="HTTP Routing Table"
|
|
>routing table</a> |</li>
|
|
<li class="right" >
|
|
<a href="../../py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li><a href="../../index.html">Accounting API 0.1-beta documentation</a> »</li>
|
|
<li><a href="../index.html" >Module code</a> »</li>
|
|
<li><a href="../accounting.html" accesskey="U">accounting</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<h1>Source code for accounting.gtkclient</h1><div class="highlight"><pre>
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="kn">import</span> <span class="nn">logging</span>
|
|
<span class="kn">import</span> <span class="nn">threading</span>
|
|
<span class="kn">import</span> <span class="nn">pkg_resources</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span>
|
|
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">gi.repository</span> <span class="kn">import</span> <span class="n">Gtk</span>
|
|
<span class="kn">from</span> <span class="nn">gi.repository</span> <span class="kn">import</span> <span class="n">GLib</span>
|
|
<span class="kn">from</span> <span class="nn">gi.repository</span> <span class="kn">import</span> <span class="n">GObject</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">accounting.client</span> <span class="kn">import</span> <span class="n">Client</span>
|
|
|
|
<span class="n">_log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
|
|
|
|
|
|
<div class="viewcode-block" id="indicate_activity"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.indicate_activity">[docs]</a><span class="k">def</span> <span class="nf">indicate_activity</span><span class="p">(</span><span class="n">func_or_str</span><span class="p">):</span>
|
|
<span class="n">description</span> <span class="o">=</span> <span class="bp">None</span>
|
|
|
|
<span class="k">def</span> <span class="nf">decorator</span><span class="p">(</span><span class="n">func</span><span class="p">):</span>
|
|
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">wrapper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">status_description</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="n">description</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">activity_indicator</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">activity_indicator</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
|
|
|
<span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
|
|
|
|
<span class="k">return</span> <span class="n">wrapper</span>
|
|
|
|
<span class="k">if</span> <span class="nb">callable</span><span class="p">(</span><span class="n">func_or_str</span><span class="p">):</span>
|
|
<span class="n">description</span> <span class="o">=</span> <span class="s">'Working'</span>
|
|
<span class="k">return</span> <span class="n">decorator</span><span class="p">(</span><span class="n">func_or_str</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">description</span> <span class="o">=</span> <span class="n">func_or_str</span>
|
|
<span class="k">return</span> <span class="n">decorator</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="indicate_activity_done"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.indicate_activity_done">[docs]</a><span class="k">def</span> <span class="nf">indicate_activity_done</span><span class="p">(</span><span class="n">func</span><span class="p">):</span>
|
|
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">wrapper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">status_description</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="s">''</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">activity_indicator</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">activity_indicator</span><span class="o">.</span><span class="n">hide</span><span class="p">()</span>
|
|
|
|
<span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
|
|
|
|
<span class="k">return</span> <span class="n">wrapper</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="AccountingApplication"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication">[docs]</a><span class="k">class</span> <span class="nc">AccountingApplication</span><span class="p">:</span>
|
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="c">#Gtk.Window.__init__(self, title='Accounting Client')</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">client</span> <span class="o">=</span> <span class="n">Client</span><span class="p">()</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">load_ui</span><span class="p">(</span><span class="n">pkg_resources</span><span class="o">.</span><span class="n">resource_filename</span><span class="p">(</span>
|
|
<span class="s">'accounting'</span><span class="p">,</span> <span class="s">'res/client-ui.glade'</span><span class="p">))</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">aboutdialog</span><span class="o">.</span><span class="n">set_transient_for</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">accounting_window</span><span class="p">)</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">accounting_window</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s">'delete-event'</span><span class="p">,</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">main_quit</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">accounting_window</span><span class="o">.</span><span class="n">set_border_width</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">accounting_window</span><span class="o">.</span><span class="n">set_default_geometry</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span> <span class="mi">360</span><span class="p">)</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">accounting_window</span><span class="o">.</span><span class="n">show_all</span><span class="p">()</span>
|
|
|
|
<div class="viewcode-block" id="AccountingApplication.load_ui"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication.load_ui">[docs]</a> <span class="k">def</span> <span class="nf">load_ui</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'Loading UI...'</span><span class="p">)</span>
|
|
<span class="n">builder</span> <span class="o">=</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">Builder</span><span class="p">()</span>
|
|
<span class="n">builder</span><span class="o">.</span><span class="n">add_from_file</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
|
|
<span class="n">builder</span><span class="o">.</span><span class="n">connect_signals</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
|
|
|
|
<span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">builder</span><span class="o">.</span><span class="n">get_objects</span><span class="p">():</span>
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'Loaded </span><span class="si">%s</span><span class="s">'</span><span class="p">,</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">Buildable</span><span class="o">.</span><span class="n">get_name</span><span class="p">(</span><span class="n">element</span><span class="p">))</span>
|
|
<span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Gtk</span><span class="o">.</span><span class="n">Buildable</span><span class="o">.</span><span class="n">get_name</span><span class="p">(</span><span class="n">element</span><span class="p">),</span> <span class="n">element</span><span class="p">)</span>
|
|
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'UI loaded'</span><span class="p">)</span>
|
|
</div>
|
|
<div class="viewcode-block" id="AccountingApplication.on_transaction_selected"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication.on_transaction_selected">[docs]</a> <span class="k">def</span> <span class="nf">on_transaction_selected</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">widget</span><span class="p">):</span>
|
|
<span class="n">selection</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transaction_view</span><span class="o">.</span><span class="n">get_selection</span><span class="p">()</span>
|
|
<span class="n">selection</span><span class="o">.</span><span class="n">set_mode</span><span class="p">(</span><span class="n">Gtk</span><span class="o">.</span><span class="n">SelectionMode</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">)</span>
|
|
<span class="n">xact_store</span><span class="p">,</span> <span class="n">xact_iter</span> <span class="o">=</span> <span class="n">selection</span><span class="o">.</span><span class="n">get_selected</span><span class="p">()</span>
|
|
|
|
<span class="n">xact_id</span> <span class="o">=</span> <span class="n">xact_store</span><span class="o">.</span><span class="n">get_value</span><span class="p">(</span><span class="n">xact_iter</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'selection: </span><span class="si">%s</span><span class="s">'</span><span class="p">,</span> <span class="n">xact_id</span><span class="p">)</span>
|
|
|
|
<span class="k">for</span> <span class="n">transaction</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">transaction_data</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">transaction</span><span class="o">.</span><span class="n">id</span> <span class="o">==</span> <span class="n">xact_id</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">lbl_payee</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="n">transaction</span><span class="o">.</span><span class="n">payee</span><span class="p">)</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">posting_store</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
|
|
|
|
<span class="k">for</span> <span class="n">posting</span> <span class="ow">in</span> <span class="n">transaction</span><span class="o">.</span><span class="n">postings</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">posting_store</span><span class="o">.</span><span class="n">append</span><span class="p">([</span>
|
|
<span class="n">posting</span><span class="o">.</span><span class="n">account</span><span class="p">,</span>
|
|
<span class="nb">str</span><span class="p">(</span><span class="n">posting</span><span class="o">.</span><span class="n">amount</span><span class="o">.</span><span class="n">amount</span><span class="p">),</span>
|
|
<span class="n">posting</span><span class="o">.</span><span class="n">amount</span><span class="o">.</span><span class="n">symbol</span>
|
|
<span class="p">])</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">detail_view</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
|
|
<span class="k">break</span>
|
|
</div>
|
|
<div class="viewcode-block" id="AccountingApplication.on_show_about_activate"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication.on_show_about_activate">[docs]</a> <span class="k">def</span> <span class="nf">on_show_about_activate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">widget</span><span class="p">):</span>
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'Showing About'</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">aboutdialog</span><span class="o">.</span><span class="n">show_all</span><span class="p">()</span>
|
|
</div>
|
|
<div class="viewcode-block" id="AccountingApplication.on_aboutdialog_close"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication.on_aboutdialog_close">[docs]</a> <span class="k">def</span> <span class="nf">on_aboutdialog_close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">widget</span><span class="p">):</span>
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'Closing About'</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">aboutdialog</span><span class="o">.</span><span class="n">hide_all</span><span class="p">()</span>
|
|
</div>
|
|
<span class="nd">@indicate_activity</span><span class="p">(</span><span class="s">'Refreshing Transactions'</span><span class="p">)</span>
|
|
<div class="viewcode-block" id="AccountingApplication.on_refresh_transactions_activate"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication.on_refresh_transactions_activate">[docs]</a> <span class="k">def</span> <span class="nf">on_refresh_transactions_activate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">widget</span><span class="p">):</span>
|
|
<span class="k">def</span> <span class="nf">load_transactions</span><span class="p">():</span>
|
|
<span class="n">transactions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">get_register</span><span class="p">()</span>
|
|
<span class="n">GLib</span><span class="o">.</span><span class="n">idle_add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">on_transactions_loaded</span><span class="p">,</span> <span class="n">transactions</span><span class="p">)</span>
|
|
|
|
<span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">load_transactions</span><span class="p">)</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
|
</div>
|
|
<span class="nd">@indicate_activity_done</span>
|
|
<div class="viewcode-block" id="AccountingApplication.on_transactions_loaded"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.AccountingApplication.on_transactions_loaded">[docs]</a> <span class="k">def</span> <span class="nf">on_transactions_loaded</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transactions</span><span class="p">):</span>
|
|
<span class="n">_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">'transactions: </span><span class="si">%s</span><span class="s">'</span><span class="p">,</span> <span class="n">transactions</span><span class="p">)</span>
|
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">transaction_data</span> <span class="o">=</span> <span class="n">transactions</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">transaction_store</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
|
|
|
|
<span class="k">for</span> <span class="n">transaction</span> <span class="ow">in</span> <span class="n">transactions</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">transaction_store</span><span class="o">.</span><span class="n">append</span><span class="p">([</span>
|
|
<span class="n">transaction</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
|
|
<span class="n">transaction</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">'%Y-%m-</span><span class="si">%d</span><span class="s">'</span><span class="p">),</span>
|
|
<span class="n">transaction</span><span class="o">.</span><span class="n">payee</span>
|
|
<span class="p">])</span>
|
|
|
|
</div></div>
|
|
<div class="viewcode-block" id="main"><a class="viewcode-back" href="../../api/accounting.html#accounting.gtkclient.main">[docs]</a><span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
|
|
|
|
<span class="n">GObject</span><span class="o">.</span><span class="n">threads_init</span><span class="p">()</span>
|
|
|
|
<span class="n">accounting</span> <span class="o">=</span> <span class="n">AccountingApplication</span><span class="p">()</span>
|
|
<span class="c">#accounting_win.connect('delete-event', Gtk.main_quit)</span>
|
|
|
|
<span class="n">Gtk</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
|
|
</div>
|
|
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
|
|
</pre></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="../../search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../../genindex.html" title="General Index"
|
|
>index</a></li>
|
|
<li class="right" >
|
|
<a href="../../http-routingtable.html" title="HTTP Routing Table"
|
|
>routing table</a> |</li>
|
|
<li class="right" >
|
|
<a href="../../py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li><a href="../../index.html">Accounting API 0.1-beta documentation</a> »</li>
|
|
<li><a href="../index.html" >Module code</a> »</li>
|
|
<li><a href="../accounting.html" >accounting</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2013, Joar Wandborg.
|
|
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
|
|
</div>
|
|
</body>
|
|
</html> |