1 """This module is GUI end of the system.
2 """
3
4 import wx
5 import guiclasses
6 from numpy import *
7 import matplotlib
8 matplotlib.use('Agg')
9 import matplotlib.pyplot as plt
10 import pylab as pl
11 import util
12 from matplotlib.figure import Figure
13 import wx.lib.sheet as sheet
14 import wx.grid
15 import plotting
16
17
19 """Create a panel for demonstrate weekly hit count of the web page for last 10 weeks.
20 It plotes a bar chart
21 """
22 - def __init__(self, parent, id, size=(100,100),style=wx.SUNKEN_BORDER):
23 """Constructor of TopHitPanel
24
25 @param parent: parent container
26 @param id: id of the widget
27 @param size: size tuple
28 @param style:style for panel
29 """
30 guiclasses.SplitterPanel.__init__(self, parent, id, size,style)
31
32
33
34 self.b1=wx.Button(self.WorkPad,-1)
35 self.tb1=wx.TextCtrl(self.WorkPad,-1)
36 self.tb1.SetSize((250,self.tb1.GetSize()[1]))
37
38
39 self.b1.SetLabel('Get Hits in Last 10 Weeks')
40 self.b1.SetPosition((20,60))
41 self.b1.SetSize((150,self.b1.GetSize()[1]))
42
43 self.tb1.WriteText('/webcal/index.php')
44 self.tb1.SetPosition((20,20))
45
46
47
48 self.Bind(wx.EVT_BUTTON,self.OnClickb1)
49
50
52 """ Event handler function for button press. Will be executed when user presses 'Get Hits in Last 10 Weeks' button
53
54 @param evt: event object of wxPython
55 """
56
57 pagename=self.tb1.GetValue()
58 pagestat=util.getHitsByPage(pagename)[0]
59 pos=range(0,-10,-1)[::-1]
60 l=pos[:9]
61 l.append('Current Week')
62 xTicks=l
63 print xTicks
64
65 filename=plotting.getbar(pos,pagestat,xlabel='weeks',xticks=xTicks,title='Weekly Hits (last 10 weeks)')
66
67
68
69 bmp=wx.Bitmap(filename)
70
71
72 self.ImagePanel.SetBitmap(bmp)
73
74
75
77 """Create a panel to show keywords by which users visited the site. Currenly it shows keywords for google, yahoo and bing
78 """
79 - def __init__(self, parent, id, size=(100,100),style=wx.SUNKEN_BORDER):
80 """Constructor of BrokenLinks
81
82 @param parent: parent container
83 @param id: id of the widget
84 @param size: size tuple
85 @param style:style for panel
86 """
87 guiclasses.SplitterPanel.__init__(self, parent, id, size,style)
88
89
90
91 self.b1=wx.Button(self.WorkPad,-1)
92 self.tb1=wx.TextCtrl(self.WorkPad,-1,style=wx.TE_MULTILINE|wx.TE_READONLY)
93
94
95 pos=350
96
97 self.b1.SetLabel('Search Engine Keywords')
98 self.b1.SetPosition((20,60))
99 self.b1.SetSize( (180,self.b1.GetSize()[1]) )
100
101 self.tb1.SetPosition((20,200))
102 self.tb1.SetBestFittingSize((pos-40,300))
103
104
105 self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.OnSplitterMoved)
106 self.Bind(wx.EVT_BUTTON,self.OnClickb1)
107
108 self.Splitter.SetSashPosition(350)
109
111 """This is the handler function for EVT_SPLITTER_SASH_POS_CHANGED event.
112 It fits textbox with proper margin again
113
114 @param evt:wxPython event object
115 """
116 print 'Moved'
117
118 pos=self.Splitter.GetSashPosition()
119
120 self.tb1.SetBestFittingSize((pos-40,300))
121
122
124 """This is the handler function for button press.
125 This will be executed when 'Search Engine Keywords' button is pressed
126
127 @param evt:wxPython event object
128 """
129 keywords=util.SearengineQueries()
130 for keyword in keywords:
131 self.tb1.WriteText(keyword+'\n')
132
133
135 """Create a panel for demonstrate Top Hits pages. It plotes a bar chart
136 """
137 - def __init__(self, parent, id, size=(100,100),style=wx.SUNKEN_BORDER):
138 """Constructor of TopHitPanel
139
140 @param parent: parent container
141 @param id: id of the widget
142 @param size: size tuple
143 @param style:style for panel
144 """
145 guiclasses.SplitterPanel.__init__(self, parent, id, size,style)
146
147
148
149 self.b1=wx.Button(self.WorkPad,-1)
150 self.tb1=wx.TextCtrl(self.WorkPad,-1)
151
152
153
154 self.b1.SetLabel('Get Page Ranks')
155 self.b1.SetPosition((20,60))
156 self.b1.SetSize((120,self.b1.GetSize()[1]))
157
158 self.tb1.WriteText('10')
159 self.tb1.SetPosition((20,20))
160
161
162
163 self.Bind(wx.EVT_BUTTON,self.OnClickb1)
164
165
167 """ Event handler function for button press. Will be executed when user presses 'Get Page Ranks' button
168
169 @param evt: event object of wxPython
170 """
171 print 'Clicked'
172 print self.tb1.GetValue()
173 hitcount=int(self.tb1.GetValue())
174 print util.topHits(hitcount)
175
176
177 hits=[t[1] for t in util.topHits(hitcount)][::-1]
178 pages=[t[0] for t in util.topHits(hitcount)][::-1]
179 pos = pl.arange(hitcount)+.5
180 val = hits
181 print hits
182 print pages
183
184 pl.figure(1)
185 rectangles= pl.barh(pos,val, align='center')
186 pl.yticks(pos, range(hitcount,0,-1))
187
188 pl.xlabel('Number of Hits -->')
189 pl.title('Is your page in top Hits ?')
190 pl.grid(True)
191
192
193 """
194 fig = pl.figure()
195 ax = fig.add_subplot(1,1,1)
196 rectangles=ax.barh(pos,val, align='center')
197 #ax.set_yticklabels(range(hitcount,0,-1),position=pos)
198 ax.set_yticklabels(' ')
199 ax.set_xlabel('Number of Hits -->')
200 ax.set_title('Is your page in top Hits ?')
201 pl.grid(True)
202 """
203
204
205
206 for x in range(len(rectangles)):
207 rectangle=rectangles[x]
208 pagename=pages[x]
209 height=rectangle.get_height()
210 width=rectangle.get_width()
211 plt.text(5,rectangle.get_y()-0.3+height/2,pagename)
212
213
214 plt.savefig('myfig')
215 pl.clf()
216
217
218 image=wx.Image('myfig.png')
219
220
221 bmp=wx.BitmapFromImage(image)
222
223
224 self.ImagePanel.SetBitmap(bmp)
225
226
227
229 """Create a panel to ge broken links. It shows the list of linked by and linked to pages
230 """
231 - def __init__(self, parent, id, size=(100,100),style=wx.SUNKEN_BORDER):
232 """Constructor of BrokenLinks
233
234 @param parent: parent container
235 @param id: id of the widget
236 @param size: size tuple
237 @param style:style for panel
238 """
239 guiclasses.SplitterPanel.__init__(self, parent, id, size,style)
240
241
242
243 self.b1=wx.Button(self.WorkPad,-1)
244 self.tb1=wx.TextCtrl(self.WorkPad,-1)
245 self.argsheet=sheet.CSheet(self.WorkPad)
246
247
248
249
250 pos=500
251
252
253 self.b1.SetLabel('Get Broken Links')
254 self.b1.SetPosition((20,60))
255 self.b1.SetSize( (140,self.b1.GetSize()[1]))
256
257 self.tb1.SetPosition((20,20))
258 self.tb1.SetValue('http://jeeves1.csetest.iitb.ac.in/')
259 self.tb1.SetSize( (300,self.b1.GetSize()[1]))
260
261
262 self.argsheet.SetPosition((10,200))
263 self.argsheet.SetBackgroundColour(wx.LIGHT_GREY)
264 self.argsheet.SetNumberCols(2)
265 self.argsheet.SetNumberRows(15)
266 self.argsheet.SetColSize(0,( (pos-70) /2))
267 self.argsheet.SetColSize(1,( (pos-70) /2))
268
269 self.argsheet.SetBestFittingSize((pos-40,200))
270 self.argsheet.SetColLabelValue(0,'Linked By')
271 self.argsheet.SetColLabelValue(1,'Potential Dead Links')
272
273 self.Splitter.SetSashPosition(500)
274
275
276
277 self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.OnSplitterMoved)
278 self.Bind(wx.EVT_BUTTON,self.OnClickb1)
279
280
282 """This is the handler function for EVT_SPLITTER_SASH_POS_CHANGED event.
283 It fits CSheet with proper margin again
284
285 @param evt:wxPython event object
286 """
287 print 'Moved'
288
289 pos=self.Splitter.GetSashPosition()
290
291
292 self.argsheet.SetBestFittingSize((pos-40,500))
293 self.argsheet.SetColSize(0,( (pos-70) /2))
294 self.argsheet.SetColSize(1,( (pos-70) /2))
295
296
298 """This is the handler function for button press.
299 This will be executed when 'Get Broken Links' button is pressed
300
301 @param evt:wxPython event object
302 """
303 host= self.tb1.GetValue()
304
305 deadlinks= util.deadLinks(host)
306 self.argsheet.ClearGrid()
307
308 for x in range(len(deadlinks)):
309 self.argsheet.SetCellValue(x,0,deadlinks[x][0])
310 self.argsheet.SetCellValue(x,1,deadlinks[x][1])
311
312
313
315 """Derived from wx.Frame class.
316 It represents application window. It is parent container of all widgets.
317 """
319 """Constructor of MyFrame
320
321 @param parent: parent container
322 @param id: id of the widget
323 @param title: title
324 """
325 wx.Frame.__init__(self, parent, id, title, size=(600, 500))
326
327
328 nb = wx.Notebook(self)
329 page1=TopHitPanel(nb,-1)
330 page2=BrokenLinks(nb,-1)
331 page3=SearchEngineKeyword(nb,-1)
332 page4=TenWeeksHits(nb,-1)
333 pageN=guiclasses.SplitterPanel(nb,-1)
334 sizer = wx.BoxSizer()
335
336
337
338 nb.AddPage(page1,'TopHits')
339 nb.AddPage(page2,'BrokenLinks')
340 nb.AddPage(page3,'Search Engine Keyword')
341 nb.AddPage(page4,'TenWeeksHits')
342
343 nb.AddPage(pageN,'Blank Page Demo')
344
345
346 sizer.Add(nb, 1, wx.EXPAND)
347 self.SetSizer(sizer)
348
349
350
351 self.Centre()
352 self.Show(True)
353
354 if __name__=='__main__':
355 """Main function of the program.
356 Invokes GUI and other modules
357 """
358 import load
359 app = wx.App()
360 MyFrame(None, -1, 'Advait Mohan Raut, MTech IITB Mumbai #09305923')
361 app.MainLoop()
362