GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
init.py
1 import sys
2 import _sw_app_utils
3 from gnucash import *
4 from _sw_core_utils import gnc_prefs_is_extra_enabled
5 import gtk
6 import os
7 sys.path.append(os.path.dirname(__file__))
8 noisy = gnc_prefs_is_extra_enabled()
9 if noisy:
10  print "woop", os.path.dirname(__file__)
11 # Importing the console class causes SIGTTOU to be thrown if GnuCash is
12 # started in the background. This causes a hang if it is not handled,
13 # so ignore it for the duration
14 import signal
15 old_sigttou = signal.signal(signal.SIGTTOU, signal.SIG_IGN)
16 
17 import pycons.console as cons
18 
19 # Restore the SIGTTOU handler
20 signal.signal(signal.SIGTTOU, old_sigttou)
21 
22 if noisy:
23  print "Hello from python!"
24  print "test", sys.modules.keys()
25  print "test2", dir(_sw_app_utils)
26 
27 root = _sw_app_utils.gnc_get_current_root_account()
28 
29 if noisy:
30  print "test", dir(root), root.__class__
31  print "test2", dir(gnucash_core_c)
32 
33 acct = Account(instance = root)
34 
35 if noisy:
36  print "test3", dir(acct)
37  #print acct.GetName()
38  #print acct.GetBalance()
39  #print acct.GetSplitList()
40  #print "test2", dir(gnucash.gnucash_core_c)
41 
42 class Console (cons.Console):
43  """ GTK python console """
44 
45  def __init__(self, argv=[], shelltype='python', banner=[],
46  filename=None, size=100):
47  cons.Console.__init__(self, argv, shelltype, banner, filename, size)
48  self.buffer.create_tag('center',
49  justification=gtk.JUSTIFY_CENTER,
50  font='Mono 4')
51  self.figures = []
52  self.callbacks = []
53  self.last_figure = None
54  self.active_canvas = None
55  self.view.connect ('key-press-event', self.key_press_event)
56  self.view.connect ('button-press-event', self.button_press_event)
57  self.view.connect ('scroll-event', self.scroll_event)
58 
59 
60  def key_press_event (self, widget, event):
61  """ Handle key press event """
62 
63  if self.active_canvas:
64  self.active_canvas.emit ('key-press-event', event)
65  return True
66  return cons.Console.key_press_event (self, widget, event)
67 
68  def scroll_event (self, widget, event):
69  """ Scroll event """
70  if self.active_canvas:
71  return True
72  return False
73 
74  def button_press_event (self, widget, event):
75  """ Button press event """
76  return self.refresh()
77 
78  def refresh (self):
79  """ Refresh drawing """
80  for fig in self.figures:
81  figure, canvas, anchor = fig
82  canvas.draw()
83  return False
84 
85 
86 # Change this to "if True:" to switch on a python console at gnucash
87 # startup:
88 if False:
89  console = Console(argv = [], shelltype = 'python', banner = [['woop', 'title']], size = 100)
90 
91  window = gtk.Window(gtk.WINDOW_TOPLEVEL)
92  window.set_position(gtk.WIN_POS_CENTER)
93  window.set_default_size(800,600)
94  window.set_border_width(0)
95  # Hm. gtk.main_quit will kill gnucash without closing the file
96  # properly. That's kinda bad.
97  window.connect('destroy-event', gtk.main_quit)
98  window.connect('delete-event', gtk.main_quit)
99  window.add (console)
100  window.show_all()
101  console.grab_focus()
struct account_s Account
Account in Gnucash. This is the typename for an account. The actual structure is defined in the priva...
Definition: gnc-engine.h:132
def scroll_event
Definition: init.py:68
def key_press_event
Definition: init.py:60
def refresh
Definition: init.py:78
last_figure
Definition: init.py:53
active_canvas
Definition: init.py:54
def button_press_event
Definition: init.py:74