/[ascend]/branches/adrian/pygtk/canvas/blocklist.py
ViewVC logotype

Diff of /branches/adrian/pygtk/canvas/blocklist.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2890 by adrian, Wed Apr 1 10:57:31 2015 UTC revision 2891 by adrian, Fri Apr 10 19:32:37 2015 UTC
# Line 5  if __name__ == '__main__': Line 5  if __name__ == '__main__':
5      print "ERROR: ASCEND Canvas should now be invoked using the file 'canvas.py' instead of 'blocklist.py'."      print "ERROR: ASCEND Canvas should now be invoked using the file 'canvas.py' instead of 'blocklist.py'."
6      exit(1)      exit(1)
7    
8  import gtk  from gi.repository import Gtk, GdkPixbuf
9  import os, os.path, glob  import os
10    import os.path
11    import glob
12  import cairo  import cairo
13  import ascpy  import ascpy
14    
15  class BlockIconView(gtk.IconView):  class BlockIconView(Gtk.IconView):
16      """      """
17       IconView containing the palette of BlockTypes available for use in the       IconView containing the palette of BlockTypes available for use in the
18       canvas. The list of blocks is supplied currently as an initialisation       canvas. The list of blocks is supplied currently as an initialisation
# Line 20  class BlockIconView(gtk.IconView): Line 22  class BlockIconView(gtk.IconView):
22       that is not yet implemented.       that is not yet implemented.
23       """       """
24      def __init__(self,blocks=None,app=None):      def __init__(self,blocks=None,app=None):
25          self.model = gtk.ListStore(str, gtk.gdk.Pixbuf)          self.model = Gtk.ListStore(str, GdkPixbuf.Pixbuf)
26          self.app = app          self.app = app
27          self.otank = {}          self.otank = {}
28          try:          try:
# Line 33  class BlockIconView(gtk.IconView): Line 35  class BlockIconView(gtk.IconView):
35          except Exception as e:          except Exception as e:
36              pass              pass
37    
38          gtk.IconView.__init__(self)          Gtk.IconView.__init__(self)
39          self.set_model(self.model)          self.set_model(self.model)
40          self.set_text_column(0)          self.set_text_column(0)
41          self.set_pixbuf_column(1)          self.set_pixbuf_column(1)
# Line 100  def BlockToolChain(): Line 102  def BlockToolChain():
102      chain.append(RubberbandTool())      chain.append(RubberbandTool())
103      return chain      return chain
104    
105  class mainWindow(gtk.Window):  class mainWindow(Gtk.Window):
106    
107      menu_xml = '''<ui>      menu_xml = '''<ui>
108      <menubar name='MenuBar'>      <menubar name='MenuBar'>
# Line 154  class mainWindow(gtk.Window): Line 156  class mainWindow(gtk.Window):
156          self.ascwrap= library          self.ascwrap= library
157          self.errorvars = []          self.errorvars = []
158          self.errorblocks = []          self.errorblocks = []
159          self.status = gtk.Statusbar()          self.status = Gtk.Statusbar()
160          self.temp = []          self.temp = []
161          self.act = 1 #to be used for storing canvas zoom in/out related data.          self.act = 1 #to be used for storing canvas zoom in/out related data.
162          # the Gaphas canvas          # the Gaphas canvas
163          canvas = BlockCanvas()          canvas = BlockCanvas()
164    
165          # the main window          # the main window
166          gtk.Window.__init__(self)          Gtk.Window.__init__(self)
167          self.iconok = self.render_icon(gtk.STOCK_YES,gtk.ICON_SIZE_MENU)          self.iconok = self.render_icon(Gtk.STOCK_YES,Gtk.IconSize.MENU)
168          self.iconinfo = self.render_icon(gtk.STOCK_DIALOG_INFO,gtk.ICON_SIZE_MENU)          self.iconinfo = self.render_icon(Gtk.STOCK_DIALOG_INFO,Gtk.IconSize.MENU)
169          self.iconwarning = self.render_icon(gtk.STOCK_DIALOG_WARNING,gtk.ICON_SIZE_MENU)          self.iconwarning = self.render_icon(Gtk.STOCK_DIALOG_WARNING,Gtk.IconSize.MENU)
170          self.iconerror = self.render_icon(gtk.STOCK_DIALOG_ERROR,gtk.ICON_SIZE_MENU)          self.iconerror = self.render_icon(Gtk.STOCK_DIALOG_ERROR,Gtk.IconSize.MENU)
171    
172          self.set_title("ASCEND Canvas Modeller")          self.set_title("ASCEND Canvas Modeller")
173          self.set_default_size(650,650)          self.set_default_size(650,650)
174          self.connect("destroy", gtk.main_quit)          self.connect("destroy", Gtk.main_quit)
175    
176          windowicon = gtk.Image()          windowicon = Gtk.Image()
177          windowicon.set_from_file(os.path.join('..','glade','ascend.svg'))          windowicon.set_from_file(os.path.join('..','glade','ascend.svg'))
178          self.set_icon(windowicon.get_pixbuf())          self.set_icon(windowicon.get_pixbuf())
179    
180          vbox = gtk.VBox()          vbox = Gtk.VBox()
181    
182          ui_manager = gtk.UIManager()          ui_manager = Gtk.UIManager()
183          accelgroup = ui_manager.get_accel_group()          accelgroup = ui_manager.get_accel_group()
184          self.add_accel_group(accelgroup)          self.add_accel_group(accelgroup)
185    
186          actiongroup = gtk.ActionGroup('CanvasActionGroup')          actiongroup = Gtk.ActionGroup('CanvasActionGroup')
187    
188          self.prefs = Preferences()          self.prefs = Preferences()
189    
190          actions = [('File', None, '_File')          actions = [('File', None, '_File')
191              ,('Quit', gtk.STOCK_QUIT, '_Quit', None,'Quit the Program', self.quit)              ,('Quit', Gtk.STOCK_QUIT, '_Quit', None,'Quit the Program', self.quit)
192              ,('New', gtk.STOCK_NEW,'_New',None,'Start a new Simulation', self.new)              ,('New', Gtk.STOCK_NEW,'_New',None,'Start a new Simulation', self.new)
193              ,('Open', gtk.STOCK_OPEN,'_Open',None,'Open a saved Canvas file', self.fileopen)              ,('Open', Gtk.STOCK_OPEN,'_Open',None,'Open a saved Canvas file', self.fileopen)
194              ,('Save', gtk.STOCK_SAVE,'_Save',None,'Open a saved Canvas file', self.save_canvas)              ,('Save', Gtk.STOCK_SAVE,'_Save',None,'Open a saved Canvas file', self.save_canvas)
195              ,('SaveAs', gtk.STOCK_SAVE_AS,'_Save As...',None,'Open a saved Canvas file', self.filesave)              ,('SaveAs', Gtk.STOCK_SAVE_AS,'_Save As...',None,'Open a saved Canvas file', self.filesave)
196              ,('Export', gtk.STOCK_PRINT, '_Export SVG', None,'Quit the Program', self.export_svg_as)              ,('Export', Gtk.STOCK_PRINT, '_Export SVG', None,'Quit the Program', self.export_svg_as)
197              ,('Library', gtk.STOCK_OPEN, '_Load Library...', '<Control>l','Load Library', self.load_library_dialog)              ,('Library', Gtk.STOCK_OPEN, '_Load Library...', '<Control>l','Load Library', self.load_library_dialog)
198              ,('Edit', None, '_Edit')              ,('Edit', None, '_Edit')
199              ,('Undo', gtk.STOCK_UNDO, '_Undo', '<Control>z', 'Undo Previous Action', self.undo_canvas)              ,('Undo', Gtk.STOCK_UNDO, '_Undo', '<Control>z', 'Undo Previous Action', self.undo_canvas)
200              ,('Redo',gtk.STOCK_REDO, '_Redo', '<Control>y', 'Redo Previous Undo', self.redo_canvas)              ,('Redo',Gtk.STOCK_REDO, '_Redo', '<Control>y', 'Redo Previous Undo', self.redo_canvas)
201              ,('BlockProperties',gtk.STOCK_PROPERTIES, '_Block Properties', None, 'Edit Block Properties', self.bp)              ,('BlockProperties',Gtk.STOCK_PROPERTIES, '_Block Properties', None, 'Edit Block Properties', self.bp)
202              ,('Delete', gtk.STOCK_DELETE, '_Delete', 'Delete', 'Delete Selected Item', self.delblock)              ,('Delete', Gtk.STOCK_DELETE, '_Delete', 'Delete', 'Delete Selected Item', self.delblock)
203              ,('View', None, '_View')              ,('View', None, '_View')
204              ,('Fullscreen', gtk.STOCK_FULLSCREEN, '_Full Screen', 'F11', 'Toggle Full Screen', self.fullscrn)              ,('Fullscreen', Gtk.STOCK_FULLSCREEN, '_Full Screen', 'F11', 'Toggle Full Screen', self.fullscrn)
205              ,('ZoomIn', gtk.STOCK_ZOOM_IN, '_Zoom In', None, 'Zoom In Canvas', self.zoom)              ,('ZoomIn', Gtk.STOCK_ZOOM_IN, '_Zoom In', None, 'Zoom In Canvas', self.zoom)
206              ,('ZoomOut', gtk.STOCK_ZOOM_OUT, '_Zoom Out', None, 'Zoom Out Canvas', self.zoom)              ,('ZoomOut', Gtk.STOCK_ZOOM_OUT, '_Zoom Out', None, 'Zoom Out Canvas', self.zoom)
207              #,('BestFit', gtk.STOCK_ZOOM_FIT, '_Best Fit', None, 'Best Fit Canvas',self.zoom)              #,('BestFit', Gtk.STOCK_ZOOM_FIT, '_Best Fit', None, 'Best Fit Canvas',self.zoom)
208              ,('Tools', None, '_Tools')              ,('Tools', None, '_Tools')
209              ,('Debug', None, '_Debug', None, 'View Instance Browser',self.debug_canvas)              ,('Debug', None, '_Debug', None, 'View Instance Browser',self.debug_canvas)
210              ,('Run', gtk.STOCK_EXECUTE, '_Run', None, 'Solve Canvas', self.run_canvas)              ,('Run', Gtk.STOCK_EXECUTE, '_Run', None, 'Solve Canvas', self.run_canvas)
211              ,('Preview', gtk.STOCK_PRINT_PREVIEW, '_Preview', None, 'Preview Generated Code', self.preview_canvas)              ,('Preview', Gtk.STOCK_PRINT_PREVIEW, '_Preview', None, 'Preview Generated Code', self.preview_canvas)
212              ,('Help', None, '_Help')              ,('Help', None, '_Help')
213              ,('Development', gtk.STOCK_INFO, '_Development', None, 'Check Development', self.on_get_help_online_click)              ,('Development', Gtk.STOCK_INFO, '_Development', None, 'Check Development', self.on_get_help_online_click)
214              ,('ReportBug', None, '_Report Bug', None, 'Report a Bug!', self.on_report_a_bug_click)              ,('ReportBug', None, '_Report Bug', None, 'Report a Bug!', self.on_report_a_bug_click)
215              ,('About', gtk.STOCK_ABOUT, '_About', None, 'About Us', self.about)              ,('About', Gtk.STOCK_ABOUT, '_About', None, 'About Us', self.about)
216          ]          ]
217    
218          actiongroup.add_actions(actions)          actiongroup.add_actions(actions)
# Line 220  class mainWindow(gtk.Window): Line 222  class mainWindow(gtk.Window):
222    
223          #Creating Menu Bar          #Creating Menu Bar
224          menubar = ui_manager.get_widget('/MenuBar')          menubar = ui_manager.get_widget('/MenuBar')
225          vbox.pack_start(menubar,False,False)          vbox.pack_start(menubar,False,False,0)
226    
227          #Creating Tool Bar          #Creating Tool Bar
228          toolbar = ui_manager.get_widget('/ToolBar')          toolbar = ui_manager.get_widget('/ToolBar')
229          vbox.pack_start(toolbar,False,False)          vbox.pack_start(toolbar,False,False,0)
230    
231          '''The Toolbar Definations start here'''          '''The Toolbar Definations start here'''
232    
233          tb = gtk.Toolbar()          tb = Gtk.Toolbar()
234          #Load Button          #Load Button
235          loadbutton = gtk.ToolButton(gtk.STOCK_OPEN)          loadbutton = Gtk.ToolButton(Gtk.STOCK_OPEN)
236          loadbutton.connect("clicked",self.fileopen)          loadbutton.connect("clicked",self.fileopen)
237          tb.insert(loadbutton,0)          tb.insert(loadbutton,0)
238    
239          #Save Button          #Save Button
240          savebutton = gtk.ToolButton(gtk.STOCK_SAVE)          savebutton = Gtk.ToolButton(Gtk.STOCK_SAVE)
241          savebutton.connect("clicked",self.save_canvas)          savebutton.connect("clicked",self.save_canvas)
242          tb.insert(savebutton,1)          tb.insert(savebutton,1)
243    
244          #Debug Button          #Debug Button
245          debugbutton = gtk.ToolButton(gtk.STOCK_PROPERTIES)          debugbutton = Gtk.ToolButton(Gtk.STOCK_PROPERTIES)
246          debugbutton.set_label("Debug")          debugbutton.set_label("Debug")
247          debugbutton.connect("clicked",self.debug_canvas)          debugbutton.connect("clicked",self.debug_canvas)
248          tb.insert(debugbutton,2)          tb.insert(debugbutton,2)
249    
250          #Preview Button          #Preview Button
251          previewb = gtk.ToolButton(gtk.STOCK_PRINT_PREVIEW)          previewb = Gtk.ToolButton(Gtk.STOCK_PRINT_PREVIEW)
252          previewb.set_label("Preview")          previewb.set_label("Preview")
253          previewb.connect("clicked",self.preview_canvas)          previewb.connect("clicked",self.preview_canvas)
254          tb.insert(previewb,3)          tb.insert(previewb,3)
255    
256          #Export Button          #Export Button
257          exportbutton = gtk.ToolButton(gtk.STOCK_CONVERT)          exportbutton = Gtk.ToolButton(Gtk.STOCK_CONVERT)
258          exportbutton.set_label("Export SVG")          exportbutton.set_label("Export SVG")
259          exportbutton.connect("clicked",self.export_svg_as)          exportbutton.connect("clicked",self.export_svg_as)
260          tb.insert(exportbutton,2)          tb.insert(exportbutton,2)
261    
262          #Run Button          #Run Button
263          runb = gtk.ToolButton(gtk.STOCK_EXECUTE)          runb = Gtk.ToolButton(Gtk.STOCK_EXECUTE)
264          runb.set_label("Run")          runb.set_label("Run")
265          runb.connect("clicked",self.run_canvas)          runb.connect("clicked",self.run_canvas)
266          tb.insert(runb, 4)          tb.insert(runb, 4)
267    
268          ##Custom Entry          ##Custom Entry
269          #m_entry = gtk.ToolButton(gtk.STOCK_SAVE_AS)          #m_entry = Gtk.ToolButton(Gtk.STOCK_SAVE_AS)
270          #m_entry.set_label("Custom METHOD")          #m_entry.set_label("Custom METHOD")
271          #m_entry.connect("clicked",self.custommethod)          #m_entry.connect("clicked",self.custommethod)
272          #tb.insert(m_entry,5)          #tb.insert(m_entry,5)
273    
274          vbox.pack_start(tb, False, False)          vbox.pack_start(tb, False, False,0)
275    
276          # hbox occupies top part of vbox, with icons on left & canvas on right.          # hbox occupies top part of vbox, with icons on left & canvas on right.
277          paned = gtk.HPaned()          paned = Gtk.HPaned()
278    
279          # the 'view' widget implemented by Gaphas          # the 'view' widget implemented by Gaphas
280          #gaphas.view.DEBUG_DRAW_BOUNDING_BOX = True          #gaphas.view.DEBUG_DRAW_BOUNDING_BOX = True
# Line 280  class mainWindow(gtk.Window): Line 282  class mainWindow(gtk.Window):
282          self.view.tool =  BlockToolChain()          self.view.tool =  BlockToolChain()
283    
284          # table containing scrollbars and main canvas          # table containing scrollbars and main canvas
285          t = gtk.Table(2,2)          t = Gtk.Table(2,2)
286          self.view.canvas = canvas          self.view.canvas = canvas
287          self.view.zoom(1)          self.view.zoom(1)
288          self.view.set_size_request(600, 450)          self.view.set_size_request(600, 450)
289          hs = gtk.HScrollbar(self.view.hadjustment)          hs = Gtk.HScrollbar(self.view.hadjustment)
290          vs = gtk.VScrollbar(self.view.vadjustment)          vs = Gtk.VScrollbar(self.view.vadjustment)
291          t.attach(self.view, 0, 1, 0, 1)          t.attach(self.view, 0, 1, 0, 1)
292          t.attach(hs, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.FILL)          t.attach(hs, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.FILL)
293          t.attach(vs, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=gtk.FILL)          t.attach(vs, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.FILL)
294    
295          # a scrolling window to contain the icon palette          # a scrolling window to contain the icon palette
296          self.scroll = gtk.ScrolledWindow()          self.scroll = Gtk.ScrolledWindow()
297          self.scroll.set_border_width(2)          self.scroll.set_border_width(2)
298          self.scroll.set_shadow_type(gtk.SHADOW_ETCHED_IN)          self.scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
299    
300          self.scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)          self.scroll.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
301    
302          self.blockiconview = BlockIconView(blocks=self.ascwrap.canvas_blocks,app=self)          self.blockiconview = BlockIconView(blocks=self.ascwrap.canvas_blocks,app=self)
303          self.scroll.add(self.blockiconview)          self.scroll.add(self.blockiconview)
# Line 303  class mainWindow(gtk.Window): Line 305  class mainWindow(gtk.Window):
305    
306          paned.pack1(self.scroll, False, True)          paned.pack1(self.scroll, False, True)
307          paned.pack2(t, True, True)          paned.pack2(t, True, True)
308          vbox.pack_start(paned, True, True)          vbox.pack_start(paned, True, True, 0)
309          vpane = gtk.VPaned()          vpane = Gtk.VPaned()
310          vpane.pack1(vbox)          vpane.pack1(vbox)
311          lower_vbox = gtk.VBox()          lower_vbox = Gtk.VBox()
312    
313          self.ET = errorreporter.ErrorReporter( self.reporter,self.iconok,self.iconinfo,self.iconwarning,self.iconerror)          self.ET = errorreporter.ErrorReporter( self.reporter,self.iconok,self.iconinfo,self.iconwarning,self.iconerror)
314          self.notebook = gtk.Notebook()          self.notebook = Gtk.Notebook()
315          self.notebook.set_tab_pos(gtk.POS_TOP)          self.notebook.set_tab_pos(Gtk.PositionType.TOP)
316          label = gtk.Label('Error / Status Reporter Console')          label = Gtk.Label(label='Error / Status Reporter Console')
317          scrolledwindow = gtk.ScrolledWindow()          scrolledwindow = Gtk.ScrolledWindow()
318          scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)          scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
319          scrolledwindow.add(self.ET.errorview)          scrolledwindow.add(self.ET.errorview)
320          self.notebook.append_page(scrolledwindow, label)          self.notebook.append_page(scrolledwindow, label)
321          lower_vbox.pack_start(self.notebook,True, True)          lower_vbox.pack_start(self.notebook,True, True, 0)
322          lower_vbox.pack_start(self.status, False, False)          lower_vbox.pack_start(self.status, False, False, 0)
323          vpane.pack2(lower_vbox,False,False)          vpane.pack2(lower_vbox,False,False)
324    
325          self.undo_manager = undo.undoManager(self)          self.undo_manager = undo.undoManager(self)
# Line 371  class mainWindow(gtk.Window): Line 373  class mainWindow(gtk.Window):
373              while(len(self.view.selected_items)!=0):              while(len(self.view.selected_items)!=0):
374                  self.view.canvas.remove(self.view._selected_items.pop())                  self.view.canvas.remove(self.view._selected_items.pop())
375                  self.status.push(0,"Item deleted.")                  self.status.push(0,"Item deleted.")
376                  self.view.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFF'))                  self.view.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#FFF'))
377    
378          '''if self.view.focused_item:          '''if self.view.focused_item:
379              self.view.canvas.remove(self.view.focused_item)              self.view.canvas.remove(self.view.focused_item)
380              self.status.push(0,"Item deleted.")              self.status.push(0,"Item deleted.")
381              self.view.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFF'))'''              self.view.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#FFF'))'''
382    
383    
384    
# Line 389  class mainWindow(gtk.Window): Line 391  class mainWindow(gtk.Window):
391          self.view.canvas.filename = None          self.view.canvas.filename = None
392          self.view.canvas.canvasmodelstate = 'Unsolved'          self.view.canvas.canvasmodelstate = 'Unsolved'
393          self.status.push(0,"Canvasmodel state : %s"% self.view.canvas.canvasmodelstate)          self.status.push(0,"Canvasmodel state : %s"% self.view.canvas.canvasmodelstate)
394          self.view.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFF'))          self.view.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#FFF'))
395    
396      def debug_canvas(self,widget):      def debug_canvas(self,widget):
397          """          """
# Line 416  class mainWindow(gtk.Window): Line 418  class mainWindow(gtk.Window):
418              print "ERROR:",str(e)              print "ERROR:",str(e)
419              self.status.push(0,"Canvasmodel could not be saved : " + str(e))              self.status.push(0,"Canvasmodel could not be saved : " + str(e))
420              b = obrowser.Browser("canvas",self.view.canvas)              b = obrowser.Browser("canvas",self.view.canvas)
421              d = gtk.Dialog("Error",self,gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))              d = Gtk.Dialog("Error",self,Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
422              d.vbox.add(gtk.Label(str(e)))              d.vbox.add(Gtk.Label(label=str(e)))
423              d.show_all()              d.show_all()
424              d.run()              d.run()
425              d.hide()              d.hide()
# Line 481  class mainWindow(gtk.Window): Line 483  class mainWindow(gtk.Window):
483      def export_svg_as(self,widget):      def export_svg_as(self,widget):
484    
485          f = None          f = None
486          dialog = gtk.FileChooserDialog("Export Canvas As...", None,          dialog = Gtk.FileChooserDialog("Export Canvas As...", None,
487              gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))              Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
488          dialog.set_default_response(gtk.RESPONSE_OK)          dialog.set_default_response(Gtk.ResponseType.OK)
489          filter = gtk.FileFilter()          filter = Gtk.FileFilter()
490          filter.set_name("Image File")          filter.set_name("Image File")
491          filter.add_pattern("*.svg")          filter.add_pattern("*.svg")
492          dialog.add_filter(filter)          dialog.add_filter(filter)
# Line 502  class mainWindow(gtk.Window): Line 504  class mainWindow(gtk.Window):
504          tmpcr.show_page()          tmpcr.show_page()
505          tmpsurface.flush()          tmpsurface.flush()
506    
507          if response == gtk.RESPONSE_OK:          if response == Gtk.ResponseType.OK:
508              name = dialog.get_filename()              name = dialog.get_filename()
509              if '.svg' not in name:              if '.svg' not in name:
510                  name += '.svg'                  name += '.svg'
# Line 657  class mainWindow(gtk.Window): Line 659  class mainWindow(gtk.Window):
659              self.view.canvas.saved_data[str(i.getName())] = i.getValue()              self.view.canvas.saved_data[str(i.getName())] = i.getValue()
660    
661      def about(self, widget):      def about(self, widget):
662          about = gtk.AboutDialog()          about = Gtk.AboutDialog()
663          about.set_program_name("ASCEND CANVAS")          about.set_program_name("ASCEND CANVAS")
664          about.set_version("0.9.6x alpha")          about.set_version("0.9.6x alpha")
665          about.set_copyright("Carnegie Mellon University")          about.set_copyright("Carnegie Mellon University")
666          about.set_comments("Canvas - Based GUI Modeller for Energy Systems")          about.set_comments("Canvas - Based GUI Modeller for Energy Systems")
667          about.set_website("http://www.ascend.cheme.cmu.edu")          about.set_website("http://www.ascend.cheme.cmu.edu")
668          windowicon = gtk.Image()          windowicon = Gtk.Image()
669          windowicon.set_from_file(os.path.join("../glade/ascend.svg"))          windowicon.set_from_file(os.path.join("../glade/ascend.svg"))
670          about.set_icon(windowicon.get_pixbuf())          about.set_icon(windowicon.get_pixbuf())
671          about.set_logo(gtk.gdk.pixbuf_new_from_file("../glade/ascend.png"))          about.set_logo(GdkPixbuf.Pixbuf.new_from_file("../glade/ascend.png"))
672          about.run()          about.run()
673          about.destroy()          about.destroy()
674    
675      def dummy(self, widget):      def dummy(self, widget):
676          dum = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Sorry ! This fuctionality is not implemented yet.")          dum = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Sorry ! This fuctionality is not implemented yet.")
677          dum.run()          dum.run()
678          dum.destroy()          dum.destroy()
679    
680      def fileopen(self, widget):      def fileopen(self, widget):
681          dialog = gtk.FileChooserDialog("Open..",self,gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))          dialog = Gtk.FileChooserDialog("Open..",self,Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
682          dialog.set_default_response(gtk.RESPONSE_OK)          dialog.set_default_response(Gtk.ResponseType.OK)
683          filter = gtk.FileFilter()          filter = Gtk.FileFilter()
684          filter.set_name("Canvas Files")          filter.set_name("Canvas Files")
685          filter.add_mime_type("Canvas Files/a4b")          filter.add_mime_type("Canvas Files/a4b")
686          filter.add_pattern("*.a4b")          filter.add_pattern("*.a4b")
687          dialog.add_filter(filter)          dialog.add_filter(filter)
688          filter = gtk.FileFilter()          filter = Gtk.FileFilter()
689          filter.set_name("All files")          filter.set_name("All files")
690          filter.add_pattern("*")          filter.add_pattern("*")
691          dialog.add_filter(filter)          dialog.add_filter(filter)
692    
693          res = dialog.run()          res = dialog.run()
694          if res == gtk.RESPONSE_OK:          if res == Gtk.ResponseType.OK:
695              result = dialog.get_filename()              result = dialog.get_filename()
696              self.load_canvas_file(result)              self.load_canvas_file(result)
697          dialog.destroy()          dialog.destroy()
# Line 703  class mainWindow(gtk.Window): Line 705  class mainWindow(gtk.Window):
705                  self.loadlib(self, self.view.canvas.model_library)                  self.loadlib(self, self.view.canvas.model_library)
706              self.view.canvas.reattach_ascend(self.ascwrap.library,self.ascwrap.annodb)              self.view.canvas.reattach_ascend(self.ascwrap.library,self.ascwrap.annodb)
707              self.view.canvas.update_now()              self.view.canvas.update_now()
708              self.view.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFF'))              self.view.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#FFF'))
709              self.load_presaved_canvas(None)              self.load_presaved_canvas(None)
710              self.reporter.reportError(" File %s successfully loaded." % filename)              self.reporter.reportError(" File %s successfully loaded." % filename)
711              self.status.push(0,"File %s Loaded." % filename)              self.status.push(0,"File %s Loaded." % filename)
# Line 716  class mainWindow(gtk.Window): Line 718  class mainWindow(gtk.Window):
718    
719      def filesave(self, widget):      def filesave(self, widget):
720          f = None          f = None
721          dialog = gtk.FileChooserDialog("Save..", self, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))          dialog = Gtk.FileChooserDialog("Save..", self, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
722          dialog.set_default_response(gtk.RESPONSE_OK)          dialog.set_default_response(Gtk.ResponseType.OK)
723          if self.view.canvas.filestate == 0:          if self.view.canvas.filestate == 0:
724              dialog.set_filename("untitled")              dialog.set_filename("untitled")
725          filter = gtk.FileFilter()          filter = Gtk.FileFilter()
726          filter.set_name("Canvas File")          filter.set_name("Canvas File")
727          filter.add_pattern("*.a4b")          filter.add_pattern("*.a4b")
728          dialog.add_filter(filter)          dialog.add_filter(filter)
# Line 728  class mainWindow(gtk.Window): Line 730  class mainWindow(gtk.Window):
730          dialog.set_do_overwrite_confirmation(True)          dialog.set_do_overwrite_confirmation(True)
731          #dialog.connect("confirm-overwrite", self.confirm_overwrite_callback)          #dialog.connect("confirm-overwrite", self.confirm_overwrite_callback)
732          response = dialog.run()          response = dialog.run()
733          if response == gtk.RESPONSE_OK:          if response == Gtk.ResponseType.OK:
734              name = dialog.get_filename()              name = dialog.get_filename()
735              if '.a4b' not in name:              if '.a4b' not in name:
736                  name += '.a4b'                  name += '.a4b'
# Line 743  class mainWindow(gtk.Window): Line 745  class mainWindow(gtk.Window):
745              except Exception,e:              except Exception,e:
746                  print "ERROR:",str(e)                  print "ERROR:",str(e)
747                  b = obrowser.Browser("canvas",self.view.canvas)                  b = obrowser.Browser("canvas",self.view.canvas)
748                  d = gtk.Dialog("Error",self,gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))                  d = Gtk.Dialog("Error",self,Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
749                  d.vbox.add(gtk.Label(str(e)))                  d.vbox.add(Gtk.Label(label=str(e)))
750                  d.show_all()                  d.show_all()
751                  d.run()                  d.run()
752                  d.hide()                  d.hide()
# Line 757  class mainWindow(gtk.Window): Line 759  class mainWindow(gtk.Window):
759          uri = widget.get_filename()          uri = widget.get_filename()
760          if is_uri_read_only(uri):          if is_uri_read_only(uri):
761              if user_wants_to_replace_read_only_file (uri):              if user_wants_to_replace_read_only_file (uri):
762                  return gtk.FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME                  return Gtk.FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME
763              else:              else:
764                  return gtk.FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN                  return Gtk.FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN
765          else:          else:
766              return gtk.FILE_CHOOSER_CONFIRMATION_CONFIRM              return Gtk.FILE_CHOOSER_CONFIRMATION_CONFIRM
767          return          return
768    
769    
# Line 769  class mainWindow(gtk.Window): Line 771  class mainWindow(gtk.Window):
771          if self.view.focused_item:          if self.view.focused_item:
772              blockproperties.BlockProperties(self, self.view.focused_item).run()              blockproperties.BlockProperties(self, self.view.focused_item).run()
773          else:          else:
774              m = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "No Block was selected! Please select a Block to view its properties.")              m = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "No Block was selected! Please select a Block to view its properties.")
775              m.run()              m.run()
776              m.destroy()              m.destroy()
777    
# Line 838  class mainWindow(gtk.Window): Line 840  class mainWindow(gtk.Window):
840          print "updating canvas"          print "updating canvas"
841          self.view.canvas.update_now()          self.view.canvas.update_now()
842          if flag == 1:          if flag == 1:
843              self.view.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#F88'))              self.view.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#F88'))
844              flag = 0              flag = 0
845          else:          else:
846              self.view.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#AFA'))              self.view.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse('#AFA'))
847    
848      def load_library_dialog(self,widget):      def load_library_dialog(self,widget):
849          #TODO: separate          #TODO: separate
850          dialog = gtk.FileChooserDialog('Load Library...',self, gtk.FILE_CHOOSER_ACTION_OPEN,(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))          dialog = Gtk.FileChooserDialog('Load Library...',self, Gtk.FileChooserAction.OPEN,(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
851          dialog.set_default_response(gtk.RESPONSE_OK)          dialog.set_default_response(Gtk.ResponseType.OK)
852          dialog.set_current_folder(os.path.join(self.ascwrap.defaultlibraryfolder))          dialog.set_current_folder(os.path.join(self.ascwrap.defaultlibraryfolder))
853    
854          filter = gtk.FileFilter()          filter = Gtk.FileFilter()
855          filter.set_name("Canvas Files")          filter.set_name("Canvas Files")
856          filter.add_mime_type("Canvas Files/a4c")          filter.add_mime_type("Canvas Files/a4c")
857          filter.add_pattern("*.a4c")          filter.add_pattern("*.a4c")
858          dialog.add_filter(filter)          dialog.add_filter(filter)
859    
860          filter = gtk.FileFilter()          filter = Gtk.FileFilter()
861          filter.set_name("All files")          filter.set_name("All files")
862          filter.add_pattern("*")          filter.add_pattern("*")
863          dialog.add_filter(filter)          dialog.add_filter(filter)
864    
865          res = dialog.run()          res = dialog.run()
866          if res == gtk.RESPONSE_OK:          if res == Gtk.ResponseType.OK:
867              result = dialog.get_filename()              result = dialog.get_filename()
868              self.loadlib(lib_name = os.path.basename(result))              self.loadlib(lib_name = os.path.basename(result))
869          dialog.destroy()          dialog.destroy()
# Line 871  class mainWindow(gtk.Window): Line 873  class mainWindow(gtk.Window):
873      ##TODO: Separate      ##TODO: Separate
874      #if loadcondition == 1:      #if loadcondition == 1:
875      #if self.view.canvas.model_library == lib_name:      #if self.view.canvas.model_library == lib_name:
876      #m = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, "The selected Library is already loaded. ")      #m = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.WARNING, Gtk.ButtonsType.CLOSE, "The selected Library is already loaded. ")
877      #m.run()      #m.run()
878      #m.destroy()      #m.destroy()
879      #return      #return
880      #if self.view.canvas.get_all_items():      #if self.view.canvas.get_all_items():
881      #m = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Unable to switch Library ! The canvas contains models from present Model Library. ")      #m = Gtk.MessageDialog(self, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Unable to switch Library ! The canvas contains models from present Model Library. ")
882      #m.run()      #m.run()
883      #m.destroy()      #m.destroy()
884      #return      #return

Legend:
Removed from v.2890  
changed lines
  Added in v.2891

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22