Start development series 1.2-post
[dom-editor.git] / Dome / loader.py
blob0623192dbfa4a5e52d2cd901e9d98cf4efa9c5d9
1 import string
3 #from gtk import *
4 #from GDK import *
6 from rox.support import get_local_path
8 TARGET_URILIST = 0
9 TARGET_RAW = 1
11 def extract_uris(data):
12 lines = string.split(data, '\r\n')
13 out = []
14 for l in lines:
15 if l and l[0] != '#':
16 out.append(l)
17 return out
19 def drag_data_received(widget, context, x, y, selection_data, info, time, win):
20 if info == TARGET_RAW:
21 win.load_data(selection_data.data)
22 else:
23 uris = extract_uris(selection_data.data)
24 if not uris:
25 win.error("Nothing to load!")
26 return
27 paths = []
28 remote = []
29 for uri in uris:
30 path = get_local_path(uri)
31 if path:
32 win.load_file(path)
33 else:
34 remote.append(uri)
35 if remote:
36 win.error("Can't load remote files yet!")
38 # 'widget' is the GTK widget that will accept drops
39 # 'window' provides 'load_file' and 'load_data' methods.
40 def make_xds_loader(widget, window):
41 widget.drag_dest_set(DEST_DEFAULT_ALL,
42 [('text/uri-list', 0, TARGET_URILIST),
43 ('text/plain', 0, TARGET_RAW),
44 ('application/octet-stream', 0, TARGET_RAW)
46 ACTION_COPY | ACTION_PRIVATE)
48 widget.connect('drag_data_received', drag_data_received, window)