4 from rox
import saving
, g
, TRUE
, FALSE
8 class ArchiveBox(saving
.SaveBox
, saving
.Saveable
):
9 "A savebox with an operation selector."
11 saving
.SaveBox
.__init
__(self
, self
, '', 'text/plain')
14 def build_main_area(self
):
15 self
.vbox
.add(self
.save_area
)
17 self
.operation
= g
.OptionMenu()
18 self
.vbox
.pack_start(self
.operation
, FALSE
, TRUE
, 0)
20 self
.operation
.set_border_width(5)
23 self
.ops_menu
= g
.Menu()
24 self
.operation
.set_menu(self
.ops_menu
)
26 def set_data(self
, data
):
30 self
.ops
= [op
for op
in formats
.operations
if op
.can_handle(data
)]
32 name
= data
.default_name
33 self
.save_area
.entry
.set_text(name
)
34 start
= name
.rfind('/') + 1
35 #self.save_area.entry.select_region(start, -1)
36 g
.Editable
.select_region(self
.save_area
.entry
, start
, -1)
40 # Add all supported ops to the menu.
43 item
= g
.MenuItem(str(op
))
45 self
.ops_menu
.append(item
)
49 self
.operation
.set_history(self
.ops
.index(data
.default
))
51 print >>sys
.stderr
, "Warning: %s not in ops list!" % data
.default
54 self
.operation
.connect('changed', self
.op_changed
)
55 self
.save_area
.entry
.connect('changed', self
.name_changed
)
57 self
.save_area
.set_type(data
.default
.type)
59 def name_changed(self
, entry
):
64 name
= entry
.get_text()
65 doc
= self
.save_area
.document
68 if name
.endswith('.' + op
.extension
):
69 self
.operation
.set_history(i
)
75 def op_changed(self
, operation
):
76 op
= self
.ops
[operation
.get_history()]
77 self
.set_type(op
.type)
83 name
= self
.save_area
.entry
.get_text()
85 if name
.endswith('.' + op2
.extension
):
86 name
= name
[:-len(op2
.extension
)-1]
89 name
+= '.' + op
.extension
90 self
.save_area
.entry
.set_text(name
)
94 def save_to_file(self
, path
):
95 op
= self
.ops
[self
.operation
.get_history()]
96 if hasattr(op
, 'save_to_file'):
97 op
.save_to_file(self
.data
, path
)
99 saving
.Saveable
.save_to_file(self
, path
)
101 def save_to_stream(self
, stream
):
102 op
= self
.ops
[self
.operation
.get_history()]
103 op
.save_to_stream(self
.data
, stream
)