Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 101 lines (86 sloc) 3.378 kb
914e4f83 »
2008-08-22 Created MWController.py file.
1 #
2 # MWController.py
3 # MetaWindow
4 #
5 # Created by Will Larson on 8/22/08.
6 # Copyright (c) 2008 Will Larson. All rights reserved.
7 #
8
96a1e93c »
2008-08-25 Now search animates.
9 import objc, metaweb, webbrowser, pickle, datetime, md5, threading
5019a9e2 »
2008-08-26 All functionality in segment four is complete. Theoretically.
10 from MWRowWindowController import MWRowWindowController
c344ca38 »
2008-08-25 Now caches results correctly.
11 from AppKit import *
914e4f83 »
2008-08-22 Created MWController.py file.
12 from Foundation import *
13
c344ca38 »
2008-08-25 Now caches results correctly.
14
914e4f83 »
2008-08-22 Created MWController.py file.
15 class MWController(NSObject):
3fda3069 »
2008-08-22 Added object in nib, also fixed accidental strand of code left in app…
16 tableView = objc.IBOutlet()
17 textField = objc.IBOutlet()
228f5fb3 »
2008-08-23 The degree of suffering and rewriting inflicted upon myself in creati…
18 arrayController = objc.IBOutlet()
96a1e93c »
2008-08-25 Now search animates.
19 indicator = objc.IBOutlet()
228f5fb3 »
2008-08-23 The degree of suffering and rewriting inflicted upon myself in creati…
20 results = []
5019a9e2 »
2008-08-26 All functionality in segment four is complete. Theoretically.
21 rowCache = {}
c344ca38 »
2008-08-25 Now caches results correctly.
22 _cache = None
23
24 def getCache(self):
25 if self._cache is None:
26 self._cache = NSApp.delegate().cache
27 return self._cache
28 cache = property(getCache,None,None,"Cache of searches.")
3fda3069 »
2008-08-22 Added object in nib, also fixed accidental strand of code left in app…
29
191b6dba »
2008-08-25 Double click now opens row in webpage (project 1 in segment 3).
30 def awakeFromNib(self):
31 if self.tableView:
32 self.tableView.setTarget_(self)
33 self.tableView.setDoubleAction_("open:")
5019a9e2 »
2008-08-26 All functionality in segment four is complete. Theoretically.
34 self.tableView.setDraggingSourceOperationMask_forLocal_(NSDragOperationCopy, False)
35
36 def dealloc(self):
37 for key in self.rowCache:
38 value = self.rowCache[key]
39 value.release()
40 super(MWController,self).dealloc()
191b6dba »
2008-08-25 Double click now opens row in webpage (project 1 in segment 3).
41
42 def open_(self,sender):
43 selectedObjs = self.arrayController.selectedObjects()
44 if len(selectedObjs) == 0:
45 NSLog(u"No selected row!")
46 return
47
48 row = selectedObjs[0]
49 NSLog(u"Row: %s" % row)
50 if not row.has_key('id') or row['id'] == None:
51 NSLog(u"Row has no id!")
52 return
53
5019a9e2 »
2008-08-26 All functionality in segment four is complete. Theoretically.
54 if self.rowCache.has_key(row):
55 rwc = self.rowCache[row]
56 rwc.showWindow_(self)
57 else:
58 rwc =MWRowWindowController.alloc().initWithWindowNibName_(u"RowWindow")
59 rwc.rowDict = row
60 rwc.showWindow_(self)
61 rwc.retain()
62 self.rowCache[row] = rwc
63
c344ca38 »
2008-08-25 Now caches results correctly.
64
65 def getCachedSearch(self,searchString):
66 if self.cache.has_key(searchString):
67 filename,timestamp = self.cache[searchString]
68 age = datetime.datetime.now() - timestamp
69 if age > datetime.timedelta(days=1):
70 return None
71 filepath = NSApp.delegate().pathForFile(filename)
72 file = open(filepath,'r')
73 data = pickle.load(file)
74 file.close()
75 return data
76 return None
191b6dba »
2008-08-25 Double click now opens row in webpage (project 1 in segment 3).
77
c344ca38 »
2008-08-25 Now caches results correctly.
78 def cacheResultsForSearch(self,searchString,results):
79 filename = u"%s.cached" % md5.md5(searchString).hexdigest()[12:]
80 filepath = NSApp.delegate().pathForFile(filename)
81 file = open(filepath,'w')
82 pickle.dump(results,file)
83 file.close()
84 self.cache[searchString] = (filename,datetime.datetime.now())
66b42f60 »
2008-08-26 Drag and drop searching works.`
85
86 def dragSearch(self,searchString):
87 self.textField.setStringValue_(searchString)
88 self.search_(self)
191b6dba »
2008-08-25 Double click now opens row in webpage (project 1 in segment 3).
89
3fda3069 »
2008-08-22 Added object in nib, also fixed accidental strand of code left in app…
90 @objc.IBAction
91 def search_(self,sender):
92 search_value = self.textField.stringValue()
c344ca38 »
2008-08-25 Now caches results correctly.
93 cached = self.getCachedSearch(search_value)
94 if cached is None:
bd90efb6 »
2008-08-25 End of third tutorial. Display progress indicator while searching.
95 self.indicator.startAnimation_(self)
96 cached = metaweb.search(search_value)
97 self.cacheResultsForSearch(search_value,cached)
98 self.indicator.stopAnimation_(self)
c344ca38 »
2008-08-25 Now caches results correctly.
99 self.results = [ NSDictionary.dictionaryWithDictionary_(x) for x in cached]
228f5fb3 »
2008-08-23 The degree of suffering and rewriting inflicted upon myself in creati…
100 self.arrayController.rearrangeObjects()
Something went wrong with that request. Please try again.