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

Contents of /branches/adrian/pygtk/canvas/canvasproperties.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2913 - (show annotations) (download) (as text)
Fri Apr 17 18:53:28 2015 UTC (7 years, 2 months ago) by adrian
File MIME type: text/x-python
File size: 5148 byte(s)
Fixed method entry issue
1 '''
2 Canvas Properties Dialog Pop Up
3 Author: Grivan Thapar, July 2010
4 '''
5 import os
6
7 from gi.repository import Gtk
8 from gi.repository import GObject
9 from gi.repository import GtkSource
10
11 import modeltree
12
13
14 class CanvasProperties(object):
15 '''
16 Pop-Up window for viewing and editing general Canvas properties
17 '''
18 def __init__(self,parent):
19
20 ##Get the XML Config##
21 glade_file_path = os.path.join('..','glade','canvasproperties.glade')
22 builder = Gtk.Builder()
23 builder.add_from_file(glade_file_path)
24
25 self.dialog = builder.get_object('dialog')
26 self.dialog.set_transient_for(parent)
27 self.parent = parent
28
29 ##Get the ASCEND lang##
30 self.sourceviewLangman = GtkSource.LanguageManager.get_default()
31 op = self.sourceviewLangman.get_search_path()
32 if os.path.join('..','..','tools','gtksourceview-2.0') not in op:
33 op.append(os.path.join('..','..','tools','gtksourceview-2.0'))
34 self.sourceviewLangman.set_search_path(op)
35 self.sourceviewLang = self.sourceviewLangman.get_language('ascend')
36
37 ##Preview Tab##
38 scrolledwindow = builder.get_object('scrolledwindow1')
39 self.sourceviewView = GtkSource.View()
40 self.sourceviewView.set_editable(False)
41 #self.sourceviewView.set_auto_indent(True)
42 self.sourceviewBuff = GtkSource.Buffer()
43 self.sourceviewBuff.set_language(self.sourceviewLang)
44 self.sourceviewBuff.set_highlight_syntax(True)
45 if self.parent is not None:
46 self.sourceviewBuff.set_text(str(self.parent.view.canvas))
47 self.sourceviewView.set_buffer(self.sourceviewBuff)
48 scrolledwindow.add(self.sourceviewView)
49 self.sourceviewView.show()
50
51 ##Declaration Tab##
52 scrolledwindow2 = builder.get_object('scrolledwindow2')
53 self.sourceviewView2 = GtkSource.View()
54 self.sourceviewView2.set_auto_indent(True)
55 self.sourceviewBuffMethod = GtkSource.Buffer()
56 self.sourceviewBuffMethod.set_language(self.sourceviewLang)
57 self.sourceviewBuffMethod.set_highlight_syntax(True)
58 if self.parent is not None:
59 self.sourceviewBuffMethod.set_text(str(self.parent.view.canvas.user_code))
60 self.sourceviewView2.set_buffer(self.sourceviewBuffMethod)
61 scrolledwindow2.add(self.sourceviewView2)
62 self.sourceviewView2.show()
63
64 ##Instance Tab##
65 try:
66 self.instance_box = builder.get_object('instancescrolledwin')
67 self.instance_model = modeltree.TreeView(parent.M)
68 self.instance_box.add(self.instance_model.treeview)
69 self.instance_model.treeview.show()
70 except Exception as e:
71 self.instance_box = builder.get_object('instancescrolledwin')
72 self.instance_label = Gtk.Label()
73 self.instance_box.add_with_viewport(self.instance_label)
74 self.instance_label.set_text('Instance not Built, Solve the Canvas Model first!')
75 self.instance_label.show()
76
77 ##Stream(s) tab##
78 self.treeview = builder.get_object('treeview1')
79 self.stream_store = Gtk.TreeStore(GObject.TYPE_PYOBJECT,GObject.TYPE_STRING,
80 GObject.TYPE_STRING)
81 if self.parent is not None:
82 for stream in self.parent.ascwrap.streams:
83 row = self.stream_store.append(None,[stream,str(stream),''])
84 for prop in stream.stream_properties:
85 self.stream_store.append(row,
86 [stream,
87 prop,
88 stream.stream_properties[prop]])
89 self.treeview.set_model(self.stream_store)
90 self.draw_stream_view()
91
92 OK_button = builder.get_object('ok')
93 OK_button.connect('clicked',self.save_changes)
94 OK_button.grab_default()
95
96 def draw_stream_view(self):
97 self.name_render = Gtk.CellRendererText()
98 self.name_render.set_property('foreground-set',True)
99 self.name_render.set_property('weight-set',True)
100
101 self.prop_render = Gtk.CellRendererText()
102 self.prop_render.set_property('foreground-set',True)
103 self.prop_render.set_property('weight-set',True)
104 self.prop_render.set_property('editable',True)
105 self.prop_render.connect('edited',self.set_stream_prop_callback)
106
107 self.name_column = Gtk.TreeViewColumn('Name',self.name_render,text=1,
108 foreground =4, weight=5)
109 self.prop_column = Gtk.TreeViewColumn('Value',self.prop_render,text=2,
110 foreground =4, weight=5)
111 self.treeview.append_column(self.name_column)
112 self.treeview.append_column(self.prop_column)
113
114 def set_stream_prop_callback(self,combo,path,new_text):
115 iter = self.stream_store.get_iter(path)
116 stream = self.stream_store.get_value(iter,0)
117 prop = self.stream_store.get_value(iter,1)
118 if new_text == str(stream.stream_properties[prop]):
119 return
120 stream.stream_properties[prop]=new_text.split(',')
121 self.stream_store.set_value(iter,2,new_text.split(','))
122
123 def save_method_buffer(self,textbuffer):
124 print textbuffer.get_modified()
125
126 def run(self):
127 self.dialog.run()
128 self.dialog.hide()
129
130 def save_changes(self,button):
131 if self.sourceviewBuffMethod.get_modified():
132 startiter = self.sourceviewBuffMethod.get_start_iter()
133 enditer = self.sourceviewBuffMethod.get_end_iter()
134 usertext = self.sourceviewBuffMethod.get_text(startiter, enditer, True)
135 self.parent.view.canvas.user_code = usertext
136
137 if __name__ == '__main__':
138 cp = CanvasProperties(None)
139 cp.run()
140
141 # vim: set ts=4 noet:
142

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