Browse code
initial commit
fiddlerwoaroof authored on 10/08/2014 04:18:37
Showing 2 changed files
Showing 2 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,52 @@ |
1 |
+from gi.repository import Gtk, WebKit |
|
2 |
+ |
|
3 |
+builder = Gtk.Builder() |
|
4 |
+builder.add_from_file("pybrowse.glade") |
|
5 |
+window = builder.get_object("mainWindow") |
|
6 |
+webview = WebKit.WebView() |
|
7 |
+def onLoad(*a): |
|
8 |
+ if a[0].get_load_status() == WebKit.LoadStatus.FINISHED: |
|
9 |
+ builder.get_object("goTxt").set_text(webview.get_uri()) |
|
10 |
+webview.connect("notify::load-status", onLoad) |
|
11 |
+mv = builder.get_object("mainview") |
|
12 |
+mv.add(webview) |
|
13 |
+ |
|
14 |
+ |
|
15 |
+class SigHandler(object): |
|
16 |
+ eval_model = builder.get_object('historyModel') |
|
17 |
+ |
|
18 |
+ def goBtn_clicked_cb(self, v): |
|
19 |
+ print(self,v) |
|
20 |
+ webview.load_uri(v.get_text()) |
|
21 |
+ eval_locals = dict() |
|
22 |
+ def evalBtn_clicked_cb(self, v): |
|
23 |
+ txt = v.get_text() |
|
24 |
+ exec(txt, globals(), self.eval_locals) |
|
25 |
+ path = self.eval_model.get_path(self.eval_model.append([txt])) |
|
26 |
+ builder.get_object("evalHistory").scroll_to_cell(path) |
|
27 |
+ def row_activated(self, s, *a): |
|
28 |
+ model, itr = s.get_selected() |
|
29 |
+ eval_txt = builder.get_object('evalTxt') |
|
30 |
+ eval_txt.set_text(model[itr][0]) |
|
31 |
+ eval_txt.grab_focus() |
|
32 |
+ def row_added(self, *a): |
|
33 |
+ print('row_added') |
|
34 |
+ print(a) |
|
35 |
+ |
|
36 |
+ |
|
37 |
+builder.connect_signals(SigHandler()) |
|
38 |
+window.connect("delete-event", Gtk.main_quit) |
|
39 |
+window.show_all() |
|
40 |
+ |
|
41 |
+import argparse |
|
42 |
+parser = argparse.ArgumentParser() |
|
43 |
+parser.add_argument('uri', nargs='?', default='http://google.com') |
|
44 |
+args = parser.parse_args() |
|
45 |
+webview.load_uri(args.uri) |
|
46 |
+ |
|
47 |
+try: |
|
48 |
+ Gtk.main() |
|
49 |
+except: |
|
50 |
+ import sys |
|
51 |
+ sys.exit(1) |
|
52 |
+ raise |
0 | 53 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,190 @@ |
1 |
+<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
+<!-- Generated with glade 3.18.3 --> |
|
3 |
+<interface> |
|
4 |
+ <requires lib="gtk+" version="3.12"/> |
|
5 |
+ <object class="GtkListStore" id="historyModel"> |
|
6 |
+ <columns> |
|
7 |
+ <!-- column-name item --> |
|
8 |
+ <column type="gchararray"/> |
|
9 |
+ </columns> |
|
10 |
+ </object> |
|
11 |
+ <object class="GtkApplicationWindow" id="mainWindow"> |
|
12 |
+ <property name="can_focus">False</property> |
|
13 |
+ <property name="default_width">500</property> |
|
14 |
+ <property name="default_height">600</property> |
|
15 |
+ <property name="show_menubar">False</property> |
|
16 |
+ <child> |
|
17 |
+ <object class="GtkBox" id="topBox"> |
|
18 |
+ <property name="visible">True</property> |
|
19 |
+ <property name="can_focus">False</property> |
|
20 |
+ <property name="orientation">vertical</property> |
|
21 |
+ <property name="spacing">2</property> |
|
22 |
+ <child> |
|
23 |
+ <object class="GtkBox" id="box2"> |
|
24 |
+ <property name="visible">True</property> |
|
25 |
+ <property name="can_focus">False</property> |
|
26 |
+ <child> |
|
27 |
+ <object class="GtkEntry" id="goTxt"> |
|
28 |
+ <property name="visible">True</property> |
|
29 |
+ <property name="can_focus">True</property> |
|
30 |
+ <signal name="activate" handler="goBtn_clicked_cb" object="goTxt" swapped="yes"/> |
|
31 |
+ </object> |
|
32 |
+ <packing> |
|
33 |
+ <property name="expand">True</property> |
|
34 |
+ <property name="fill">True</property> |
|
35 |
+ <property name="position">0</property> |
|
36 |
+ </packing> |
|
37 |
+ </child> |
|
38 |
+ <child> |
|
39 |
+ <object class="GtkButton" id="goBtn"> |
|
40 |
+ <property name="label">gtk-ok</property> |
|
41 |
+ <property name="visible">True</property> |
|
42 |
+ <property name="can_focus">True</property> |
|
43 |
+ <property name="receives_default">True</property> |
|
44 |
+ <property name="use_stock">True</property> |
|
45 |
+ <signal name="clicked" handler="goBtn_clicked_cb" object="goTxt" swapped="yes"/> |
|
46 |
+ </object> |
|
47 |
+ <packing> |
|
48 |
+ <property name="expand">False</property> |
|
49 |
+ <property name="fill">True</property> |
|
50 |
+ <property name="pack_type">end</property> |
|
51 |
+ <property name="position">1</property> |
|
52 |
+ </packing> |
|
53 |
+ </child> |
|
54 |
+ </object> |
|
55 |
+ <packing> |
|
56 |
+ <property name="expand">False</property> |
|
57 |
+ <property name="fill">True</property> |
|
58 |
+ <property name="position">0</property> |
|
59 |
+ </packing> |
|
60 |
+ </child> |
|
61 |
+ <child> |
|
62 |
+ <object class="GtkPaned" id="paned1"> |
|
63 |
+ <property name="visible">True</property> |
|
64 |
+ <property name="can_focus">True</property> |
|
65 |
+ <property name="orientation">vertical</property> |
|
66 |
+ <child> |
|
67 |
+ <object class="GtkScrolledWindow" id="mainview"> |
|
68 |
+ <property name="height_request">768</property> |
|
69 |
+ <property name="visible">True</property> |
|
70 |
+ <property name="can_focus">True</property> |
|
71 |
+ <property name="vexpand">True</property> |
|
72 |
+ <property name="vscrollbar_policy">always</property> |
|
73 |
+ <property name="shadow_type">in</property> |
|
74 |
+ <property name="min_content_height">500</property> |
|
75 |
+ <child> |
|
76 |
+ <placeholder/> |
|
77 |
+ </child> |
|
78 |
+ </object> |
|
79 |
+ <packing> |
|
80 |
+ <property name="resize">True</property> |
|
81 |
+ <property name="shrink">False</property> |
|
82 |
+ </packing> |
|
83 |
+ </child> |
|
84 |
+ <child> |
|
85 |
+ <object class="GtkBox" id="box1"> |
|
86 |
+ <property name="height_request">120</property> |
|
87 |
+ <property name="visible">True</property> |
|
88 |
+ <property name="can_focus">False</property> |
|
89 |
+ <property name="orientation">vertical</property> |
|
90 |
+ <child> |
|
91 |
+ <object class="GtkScrolledWindow" id="scrolledwindow1"> |
|
92 |
+ <property name="height_request">20</property> |
|
93 |
+ <property name="visible">True</property> |
|
94 |
+ <property name="can_focus">True</property> |
|
95 |
+ <property name="shadow_type">in</property> |
|
96 |
+ <property name="min_content_height">20</property> |
|
97 |
+ <child> |
|
98 |
+ <object class="GtkTreeView" id="evalHistory"> |
|
99 |
+ <property name="visible">True</property> |
|
100 |
+ <property name="can_focus">True</property> |
|
101 |
+ <property name="model">historyModel</property> |
|
102 |
+ <property name="headers_visible">False</property> |
|
103 |
+ <property name="search_column">0</property> |
|
104 |
+ <property name="show_expanders">False</property> |
|
105 |
+ <property name="enable_grid_lines">both</property> |
|
106 |
+ <signal name="add" handler="row_added" swapped="no"/> |
|
107 |
+ <signal name="row-activated" handler="row_activated" object="evalHistory-selection" swapped="no"/> |
|
108 |
+ <child internal-child="selection"> |
|
109 |
+ <object class="GtkTreeSelection" id="evalHistory-selection"/> |
|
110 |
+ </child> |
|
111 |
+ <child> |
|
112 |
+ <object class="GtkTreeViewColumn" id="itemcol"> |
|
113 |
+ <property name="title" translatable="yes">Item</property> |
|
114 |
+ <child> |
|
115 |
+ <object class="GtkCellRendererText" id="cellrenderertext1"/> |
|
116 |
+ <attributes> |
|
117 |
+ <attribute name="text">0</attribute> |
|
118 |
+ </attributes> |
|
119 |
+ </child> |
|
120 |
+ </object> |
|
121 |
+ </child> |
|
122 |
+ </object> |
|
123 |
+ </child> |
|
124 |
+ </object> |
|
125 |
+ <packing> |
|
126 |
+ <property name="expand">True</property> |
|
127 |
+ <property name="fill">True</property> |
|
128 |
+ <property name="position">0</property> |
|
129 |
+ </packing> |
|
130 |
+ </child> |
|
131 |
+ <child> |
|
132 |
+ <object class="GtkBox" id="box3"> |
|
133 |
+ <property name="visible">True</property> |
|
134 |
+ <property name="can_focus">False</property> |
|
135 |
+ <child> |
|
136 |
+ <object class="GtkEntry" id="evalTxt"> |
|
137 |
+ <property name="visible">True</property> |
|
138 |
+ <property name="can_focus">True</property> |
|
139 |
+ <signal name="activate" handler="evalBtn_clicked_cb" object="evalTxt" swapped="no"/> |
|
140 |
+ </object> |
|
141 |
+ <packing> |
|
142 |
+ <property name="expand">True</property> |
|
143 |
+ <property name="fill">True</property> |
|
144 |
+ <property name="position">0</property> |
|
145 |
+ </packing> |
|
146 |
+ </child> |
|
147 |
+ <child> |
|
148 |
+ <object class="GtkButton" id="evalBtn"> |
|
149 |
+ <property name="label">gtk-execute</property> |
|
150 |
+ <property name="visible">True</property> |
|
151 |
+ <property name="can_focus">True</property> |
|
152 |
+ <property name="receives_default">True</property> |
|
153 |
+ <property name="use_stock">True</property> |
|
154 |
+ <property name="yalign">0.49000000953674316</property> |
|
155 |
+ <property name="always_show_image">True</property> |
|
156 |
+ <signal name="clicked" handler="evalBtn_clicked_cb" object="evalTxt" swapped="no"/> |
|
157 |
+ </object> |
|
158 |
+ <packing> |
|
159 |
+ <property name="expand">False</property> |
|
160 |
+ <property name="fill">True</property> |
|
161 |
+ <property name="pack_type">end</property> |
|
162 |
+ <property name="position">1</property> |
|
163 |
+ </packing> |
|
164 |
+ </child> |
|
165 |
+ </object> |
|
166 |
+ <packing> |
|
167 |
+ <property name="expand">False</property> |
|
168 |
+ <property name="fill">True</property> |
|
169 |
+ <property name="pack_type">end</property> |
|
170 |
+ <property name="position">1</property> |
|
171 |
+ </packing> |
|
172 |
+ </child> |
|
173 |
+ </object> |
|
174 |
+ <packing> |
|
175 |
+ <property name="resize">True</property> |
|
176 |
+ <property name="shrink">True</property> |
|
177 |
+ </packing> |
|
178 |
+ </child> |
|
179 |
+ </object> |
|
180 |
+ <packing> |
|
181 |
+ <property name="expand">True</property> |
|
182 |
+ <property name="fill">True</property> |
|
183 |
+ <property name="pack_type">end</property> |
|
184 |
+ <property name="position">1</property> |
|
185 |
+ </packing> |
|
186 |
+ </child> |
|
187 |
+ </object> |
|
188 |
+ </child> |
|
189 |
+ </object> |
|
190 |
+</interface> |