Release 2.1
[memo.git] / main.py
blobc896b9d24bcdbaa6b8dd440b225e62f53754ca90
1 import findrox; findrox.version(2, 0, 3)
2 import rox
3 from rox import choices, OptionsBox
5 def build_filechooser(self, node, label, option):
6 """<filechooser name='...' label='...'/>Tooltip</filechooser>.
7 Lets the user choose a file (using a GtkFileChooser or by drag-and-drop).
8 Note: Since the FileChooserButton widget requires GTK >= 2.6, lesser GTK
9 versions will just show a normal text entry box, which should work with DND.
10 """
11 if g.gtk_version >= (2,6,0):
12 filebutton = g.FileChooserButton(label)
13 eb = g.EventBox()
14 eb.add(filebutton)
15 clearbutton = g.Button("Clear")
16 self.may_add_tip(eb, node)
17 hbox = g.HBox(False, 4)
18 if label:
19 hbox.pack_start(g.Label(label + ":"), False, True, 0)
20 hbox.pack_start(eb, True, True, 0)
21 hbox.pack_start(clearbutton, False, True, 0)
22 self.handlers[option] = (
23 lambda: filebutton.get_filename(),
24 lambda: filebutton.set_filename(option.value))
25 filebutton.connect('selection-changed', lambda w: self.check_widget(option))
26 clearbutton.connect('clicked', lambda w: filebutton.set_filename("") )
27 return [hbox]
28 else:
29 # Fallback to text input
30 return self.build_entry(node, label, option)
32 OptionsBox.widget_registry['filechooser'] = build_filechooser
34 choices.migrate('Memo', 'rox.sourceforge.net')
36 import os, __builtin__
37 __builtin__._ = rox.i18n.translation(os.path.join(rox.app_dir, 'Messages'))
39 rox.setup_app_options('Memo', site = 'rox.sourceforge.net')
41 from rox.Menu import set_save_name
42 set_save_name('Memo', site = 'rox.sourceforge.net')
44 import Window, memos, clock
45 try:
46 # Need this for the Systray options
47 import Systray
48 except AssertionError:
49 pass
51 # All options must be registered by the time we get here
52 rox.app_options.notify()
54 # This is just to prevent us from loading two copies...
55 memo_service = 'net.sourceforge.rox.Memo'
56 from rox import xxmlrpc, g, tasks
57 try:
58 proxy = xxmlrpc.XXMLProxy(memo_service)
59 # Check to make sure it really is running...
60 def check():
61 call = proxy.get_object('/').get_pid()
62 yield call, tasks.TimeoutBlocker(2)
63 if call.happened:
64 pid = call.get_response()
65 rox.alert('Memo is already running (PID = %d)!' % pid)
66 os._exit(1)
67 g.main_quit()
68 tasks.Task(check())
69 g.main()
70 print "Possible existing copy of Memo is not responding"
71 except xxmlrpc.NoSuchService:
72 pass # Good
73 server = xxmlrpc.XXMLRPCServer(memo_service)
74 class MemoObject:
75 allowed_methods = ['get_pid']
76 def get_pid(self):
77 return os.getpid()
78 server.add_object('/', MemoObject())
80 memo_list = memos.MasterList()
82 main_window = Window.Window(memo_list)
84 def main():
85 try:
86 rox.mainloop()
87 finally:
88 import dbus_notify
89 dbus_notify.close_all()