2 from rox
import g
, TRUE
, FALSE
, saving
5 from Ft
.Xml
.Domlette
import PrettyPrint
10 from rox
.saving
import SaveBox
14 from codecs
import lookup
15 utf8_encoder
= lookup('UTF-8')[0]
17 class Window(rox
.Window
, saving
.Saveable
):
18 def __init__(self
, path
= None, data
= None):
19 # 'data' is used when 'path' is a stylesheet...
20 rox
.Window
.__init
__(self
)
22 self
.status
= g
.Statusbar()
23 self
.status
.push(0, 'Welcome to Dome. Click the right-hand mouse button for menus.')
24 self
.showing_message
= False
26 # Make it square, to cope with Xinerama
27 size
= min(g
.gdk
.screen_width(), g
.gdk
.screen_height())
30 self
.set_default_size(size
, size
)
31 self
.set_position(g
.WIN_POS_CENTER
)
39 path
= os
.path
.abspath(path
)
42 self
.model
= Model
.Model(path
, dome_data
= data
)
46 from GUIView
import GUIView
47 #from Display2 import Display as GUIView
50 vbox
= g
.VBox(FALSE
, 0)
54 tools
.set_style(g
.TOOLBAR_ICONS
)
55 vbox
.pack_start(tools
, FALSE
, TRUE
, 0)
58 tools
.insert_stock(g
.STOCK_HELP
, 'Help', None, self
.tool_help
, None, 0)
59 tools
.insert_stock(g
.STOCK_JUMP_TO
, 'Step', None, self
.tool_step
, None, 0)
60 tools
.insert_stock(g
.STOCK_GO_FORWARD
, 'Next', None, self
.tool_next
, None, 0)
61 tools
.insert_stock(g
.STOCK_GOTO_LAST
, 'Play', None, self
.tool_play
, None, 0)
62 tools
.insert_stock(g
.STOCK_STOP
, 'Stop', None, self
.tool_stop
, None, 0)
63 tools
.insert_stock(g
.STOCK_NO
, 'Record', None, self
.tool_record
, None, 0)
64 tools
.insert_stock(g
.STOCK_SAVE
, 'Save', None, self
.tool_save
, None, 0)
67 vbox
.pack_start(paned
)
70 view
= View
.View(self
.model
)
72 self
.list = List(view
)
77 #swin = g.ScrolledWindow()
78 #swin.set_policy(g.POLICY_AUTOMATIC, g.POLICY_ALWAYS)
80 paned
.set_position(200)
82 self
.gui_view
= GUIView(self
, view
)
83 #swin.add(self.gui_view)
84 paned
.add2(self
.gui_view
)
85 #swin.set_hadjustment(self.gui_view.get_hadjustment())
86 #swin.set_vadjustment(self.gui_view.get_vadjustment())
88 vbox
.pack_start(self
.status
, False, True, 0)
92 self
.gui_view
.grab_focus()
95 def delete(window
, event
):
96 if self
.model
.root_program
.modified
:
97 self
.save(discard
= 1)
100 self
.connect('delete-event', delete
)
102 def set_status(self
, message
= None):
103 if self
.showing_message
:
106 self
.status
.push(0, message
)
107 self
.showing_message
= bool(message
)
108 self
.status
.draw((0, 0, self
.status
.allocation
.width
, self
.status
.allocation
.height
))
114 def set_state(self
, state
):
115 if state
== self
.dome_state
:
118 self
.dome_state
= " " + state
124 def update_title(self
):
125 title
= self
.model
.uri
126 self
.set_title(title
+ self
.dome_state
)
128 def save(self
, discard
= 0):
130 self
.savebox
.destroy()
131 path
= self
.model
.uri
133 self
.savebox
= saving
.SaveBox(self
, path
,
134 'application/x-dome', discard
= discard
)
135 self
.savebox
.set_transient_for(self
)
136 self
.savebox
.set_destroy_with_parent(True)
137 radio_dome
= g
.RadioButton(None, 'Save everything (.dome)')
138 radio_xml
= g
.RadioButton(radio_dome
, 'Export data as XML')
139 radio_html
= g
.RadioButton(radio_xml
, 'Export data as XHTML')
142 (radio_dome
, 'dome', 'application/x-dome', self
.save_as_dome
),
143 (radio_xml
, 'xml', 'text/xml', self
.save_as_xml
),
144 (radio_html
, 'xhtml', 'application/xhtml+xml', self
.save_as_html
))
146 def changed(toggle
= None):
147 name
= self
.savebox
.save_area
.entry
.get_text()
148 if name
.endswith('.xml'):
150 elif name
.endswith('.dome'):
152 elif name
.endswith('.xhtml'):
155 for radio
, ext
, mime
, fn
in self
.save_radios
:
156 if radio
.get_active():
158 self
.savebox
.set_type(mime
)
159 self
.savebox
.save_area
.entry
.set_text(name
)
161 for radio
, ext
, mime
, fn
in self
.save_radios
:
162 self
.savebox
.vbox
.pack_start(radio
, False, True, 0)
163 radio
.connect('toggled', changed
)
165 for radio
, ext
, mime
, fn
in self
.save_radios
:
166 if path
.endswith('.' + ext
):
167 radio
.set_active(True)
169 self
.savebox
.vbox
.show_all()
172 def write(self
, text
):
173 if type(text
) == unicode:
174 text
= utf8_encoder(text
)[0]
175 self
.output_data
.write(text
)
177 def save_to_stream(self
, stream
):
178 self
.set_status('Saving...')
180 for radio
, ext
, mime
, fn
in self
.save_radios
:
181 if radio
.get_active():
186 def save_as_dome(self
, stream
):
187 print "Saving", self
.view
.root
188 #self.view.model.strip_space()
189 doc
= self
.view
.export_all()
190 print "Writing data..."
191 PrettyPrint(doc
, stream
)
193 def save_as_xml(self
, stream
):
194 print "Saving XML", self
.view
.root
195 doc
= self
.view
.model
.doc
196 print "Writing data..."
197 PrettyPrint(doc
, stream
)
199 def save_as_html(self
, stream
):
200 from xml
.dom
.html
import HTMLDocument
202 print "Saving HTML", self
.view
.root
203 print >>stream
, to_html
.to_html(self
.view
.root
.ownerDocument
)
205 def set_uri(self
, uri
):
206 if self
.save_radios
[0][0].get_active():
208 self
.model
.root_program
.modified
= 0
213 def tool_save(self
, button
= None):
216 def tool_stop(self
, button
= None):
217 if self
.view
.rec_point
:
218 self
.view
.stop_recording()
219 if self
.view
.running():
220 self
.view
.single_step
= 1
224 def tool_play(self
, button
= None):
225 from View
import InProgress
, Done
226 # Step first, in case we're on a breakpoint
227 self
.view
.single_step
= 1
229 self
.view
.do_one_step()
230 except InProgress
, Done
:
232 self
.view
.single_step
= 0
235 def tool_next(self
, button
= None):
236 from View
import InProgress
, Done
237 self
.view
.single_step
= 2
239 self
.view
.do_one_step()
240 except InProgress
, Done
:
243 def tool_step(self
, button
= None):
244 from View
import InProgress
, Done
245 self
.view
.single_step
= 1
247 self
.view
.do_one_step()
248 except InProgress
, Done
:
251 def tool_record(self
, button
= None):
252 if self
.view
.rec_point
:
253 self
.view
.stop_recording()
255 self
.view
.record_at_point()
257 def tool_help(self
, button
= None):
258 rox
.filer
.show_file(os
.path
.join(rox
.app_dir
, 'Help', 'README'))