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 # Make it square, to cope with Xinerama
23 size
= min(g
.gdk
.screen_width(), g
.gdk
.screen_height())
26 self
.set_default_size(size
, size
)
27 self
.set_position(g
.WIN_POS_CENTER
)
35 path
= os
.path
.abspath(path
)
38 self
.model
= Model
.Model(path
, dome_data
= data
)
42 from GUIView
import GUIView
43 #from Display2 import Display as GUIView
46 vbox
= g
.VBox(FALSE
, 0)
50 tools
.set_style(g
.TOOLBAR_ICONS
)
51 vbox
.pack_start(tools
, FALSE
, TRUE
, 0)
54 tools
.insert_stock(g
.STOCK_HELP
, 'Help', None, self
.tool_help
, None, 0)
55 tools
.insert_stock(g
.STOCK_JUMP_TO
, 'Step', None, self
.tool_step
, None, 0)
56 tools
.insert_stock(g
.STOCK_GO_FORWARD
, 'Next', None, self
.tool_next
, None, 0)
57 tools
.insert_stock(g
.STOCK_GOTO_LAST
, 'Play', None, self
.tool_play
, None, 0)
58 tools
.insert_stock(g
.STOCK_STOP
, 'Stop', None, self
.tool_stop
, None, 0)
59 tools
.insert_stock(g
.STOCK_NO
, 'Record', None, self
.tool_record
, None, 0)
60 tools
.insert_stock(g
.STOCK_SAVE
, 'Save', None, self
.tool_save
, None, 0)
63 vbox
.pack_start(paned
)
66 view
= View
.View(self
.model
)
68 self
.list = List(view
)
73 #swin = g.ScrolledWindow()
74 #swin.set_policy(g.POLICY_AUTOMATIC, g.POLICY_ALWAYS)
76 paned
.set_position(200)
78 self
.gui_view
= GUIView(self
, view
)
79 #swin.add(self.gui_view)
80 paned
.add2(self
.gui_view
)
81 #swin.set_hadjustment(self.gui_view.get_hadjustment())
82 #swin.set_vadjustment(self.gui_view.get_vadjustment())
86 self
.gui_view
.grab_focus()
89 def delete(window
, event
):
90 if self
.model
.root_program
.modified
:
91 self
.save(discard
= 1)
94 self
.connect('delete-event', delete
)
99 def set_state(self
, state
):
100 if state
== self
.dome_state
:
103 self
.dome_state
= " " + state
109 def update_title(self
):
110 title
= self
.model
.uri
111 self
.set_title(title
+ self
.dome_state
)
113 def save(self
, discard
= 0):
115 self
.savebox
.destroy()
116 path
= self
.model
.uri
118 self
.savebox
= saving
.SaveBox(self
, path
,
119 'application/x-dome', discard
= discard
)
120 self
.savebox
.set_transient_for(self
)
121 self
.savebox
.set_destroy_with_parent(True)
122 radio_dome
= g
.RadioButton(None, 'Save everything (.dome)')
123 radio_xml
= g
.RadioButton(radio_dome
, 'Export data as XML')
124 radio_html
= g
.RadioButton(radio_xml
, 'Export data as HTML')
127 (radio_dome
, 'dome', 'application/x-dome', self
.save_as_dome
),
128 (radio_xml
, 'xml', 'text/xml', self
.save_as_xml
),
129 (radio_html
, 'html', 'text/html', self
.save_as_html
))
131 def changed(toggle
= None):
132 name
= self
.savebox
.save_area
.entry
.get_text()
133 if name
.endswith('.xml'):
135 elif name
.endswith('.dome'):
137 elif name
.endswith('.html'):
140 for radio
, ext
, mime
, fn
in self
.save_radios
:
141 if radio
.get_active():
143 self
.savebox
.set_type(mime
)
144 self
.savebox
.save_area
.entry
.set_text(name
)
146 for radio
, ext
, mime
, fn
in self
.save_radios
:
147 self
.savebox
.vbox
.pack_start(radio
, False, True, 0)
148 radio
.connect('toggled', changed
)
150 for radio
, ext
, mime
, fn
in self
.save_radios
:
151 if path
.endswith('.' + ext
):
152 radio
.set_active(True)
154 self
.savebox
.vbox
.show_all()
157 def write(self
, text
):
158 if type(text
) == unicode:
159 text
= utf8_encoder(text
)[0]
160 self
.output_data
.write(text
)
162 def save_to_stream(self
, stream
):
163 for radio
, ext
, mime
, fn
in self
.save_radios
:
164 if radio
.get_active():
167 def save_as_dome(self
, stream
):
168 print "Saving", self
.view
.root
169 #self.view.model.strip_space()
170 doc
= self
.view
.export_all()
171 print "Writing data..."
172 PrettyPrint(doc
, stream
)
174 def save_as_xml(self
, stream
):
175 print "Saving XML", self
.view
.root
176 doc
= self
.view
.model
.doc
177 print "Writing data..."
178 PrettyPrint(doc
, stream
)
180 def save_as_html(self
, stream
):
181 from xml
.dom
.html
import HTMLDocument
183 print "Saving HTML", self
.view
.root
184 print >>stream
, to_html
.to_html(self
.view
.root
.ownerDocument
)
186 def set_uri(self
, uri
):
187 if self
.save_radios
[0][0].get_active():
189 self
.model
.root_program
.modified
= 0
194 def tool_save(self
, button
= None):
197 def tool_stop(self
, button
= None):
198 if self
.view
.rec_point
:
199 self
.view
.stop_recording()
200 if self
.view
.running():
201 self
.view
.single_step
= 1
205 def tool_play(self
, button
= None):
206 from View
import InProgress
, Done
207 # Step first, in case we're on a breakpoint
208 self
.view
.single_step
= 1
210 self
.view
.do_one_step()
211 except InProgress
, Done
:
213 self
.view
.single_step
= 0
216 def tool_next(self
, button
= None):
217 from View
import InProgress
, Done
218 self
.view
.single_step
= 2
220 self
.view
.do_one_step()
221 except InProgress
, Done
:
224 def tool_step(self
, button
= None):
225 from View
import InProgress
, Done
226 self
.view
.single_step
= 1
228 self
.view
.do_one_step()
229 except InProgress
, Done
:
232 def tool_record(self
, button
= None):
233 if self
.view
.rec_point
:
234 self
.view
.stop_recording()
236 self
.view
.record_at_point()
238 def tool_help(self
, button
= None):
239 rox
.filer
.show_file(os
.path
.join(rox
.app_dir
, 'Help', 'README'))