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')
16 if formats
.current_command
:
17 formats
.current_command
.kill()
18 self
.connect('destroy', destroyed
)
20 def set_in_progress(self
, busy
):
22 self
.operation
.set_sensitive(not busy
)
23 self
.set_response_sensitive(g
.RESPONSE_OK
, not busy
)
25 in_progress
= property(None, set_in_progress
, None)
27 def build_main_area(self
):
28 self
.vbox
.add(self
.save_area
)
30 self
.operation
= g
.OptionMenu()
31 self
.vbox
.pack_start(self
.operation
, FALSE
, TRUE
, 0)
33 self
.operation
.set_border_width(5)
36 self
.ops_menu
= g
.Menu()
37 self
.operation
.set_menu(self
.ops_menu
)
39 def set_data(self
, data
):
43 ops
= [op
for op
in formats
.operations
if op
.can_handle(data
)]
45 name
= data
.default_name
46 self
.save_area
.entry
.set_text(name
)
47 start
= name
.rfind('/') + 1
48 #self.save_area.entry.select_region(start, -1)
49 g
.Editable
.select_region(self
.save_area
.entry
, start
, -1)
51 # Add all supported ops to the menu.
55 if last
and last
!= op
.__class
__:
58 self
.ops_menu
.append(item
)
61 item
= g
.MenuItem(str(op
))
63 self
.ops_menu
.append(item
)
68 self
.operation
.set_history(self
.ops
.index(data
.default
))
70 print >>sys
.stderr
, "Warning: %s not in ops list!" % data
.default
72 self
.operation
.connect('changed', self
.op_changed
)
73 self
.save_area
.entry
.connect('changed', self
.name_changed
)
75 self
.save_area
.set_type(data
.default
.type)
77 def name_changed(self
, entry
):
82 name
= entry
.get_text()
85 if op
and name
.endswith('.' + op
.extension
):
86 self
.operation
.set_history(i
)
92 def op_changed(self
, operation
):
93 op
= self
.ops
[operation
.get_history()]
95 self
.set_type(op
.type)
101 name
= self
.save_area
.entry
.get_text()
103 if op2
and name
.endswith('.' + op2
.extension
):
104 name
= name
[:-len(op2
.extension
)-1]
107 name
+= '.' + op
.extension
108 self
.save_area
.entry
.set_text(name
)
112 def save_to_file(self
, path
):
113 op
= self
.ops
[self
.operation
.get_history()]
114 if hasattr(op
, 'save_to_file'):
117 op
.save_to_file(self
.data
, path
)
121 saving
.Saveable
.save_to_file(self
, path
)
123 def save_to_stream(self
, stream
):
126 op
= self
.ops
[self
.operation
.get_history()]
127 op
.save_to_stream(self
.data
, stream
)