Added 'early alert' and sound capabilities. See Help/README for details
[memo.git] / main.py
blob2d92bb216ed5866a2c36ab9497655f01aeaaa664
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
46 # All options must be registered by the time we get here
47 rox.app_options.notify()
49 # This is just to prevent us from loading two copies...
50 memo_service = 'net.sourceforge.rox.Memo'
51 from rox import xxmlrpc, g, tasks
52 try:
53 proxy = xxmlrpc.XXMLProxy(memo_service)
54 # Check to make sure it really is running...
55 def check():
56 call = proxy.get_object('/').get_pid()
57 yield call, tasks.TimeoutBlocker(2)
58 if call.happened:
59 pid = call.get_response()
60 rox.alert('Memo is already running (PID = %d)!' % pid)
61 os._exit(1)
62 g.main_quit()
63 tasks.Task(check())
64 g.main()
65 print "Possible existing copy of Memo is not responding"
66 except xxmlrpc.NoSuchService:
67 pass # Good
68 server = xxmlrpc.XXMLRPCServer(memo_service)
69 class MemoObject:
70 allowed_methods = ['get_pid']
71 def get_pid(self):
72 return os.getpid()
73 server.add_object('/', MemoObject())
75 memo_list = memos.MasterList()
77 main_window = Window.Window(memo_list)
79 def main():
80 try:
81 rox.mainloop()
82 finally:
83 import dbus_notify
84 dbus_notify.close_all()