数值蟒
Tuesday, 16. May 2006, 14:14:09
之前对于 NumPy, Numeric, Numarray, Scipy 之间的关系非常困惑,在看了History of Scipy 之后,有了一些大致的了解,看来 NumPy+SciPy 将是数值蟒的首选了。
Tuesday, 16. May 2006, 14:14:09
Tuesday, 16. May 2006, 04:55:04
Monday, 8. May 2006, 13:47:56
@cherrypy.expose
def doPost(self, url="", title="", notes="", tags=""):
con = cherrypy.thread_data.db.cursor()
user = ""
info = (title, url, notes, user, tags, time.time())
con.execute("insert into bookmark (title, url, notes, user, tags, time) values (?,?,?,?,?,?)", info)
cherrypy.thread_data.db.commit()
con.close()
yield '...... done!<br>'
yield 'go back to <a href="%s">%s</a>' % (url, title)
Sunday, 7. May 2006, 12:50:25
post to del.icio.us按钮,可以在浏览网页的时候随时保存,另外加上一些tag,使得归类是如此的简单。比起在Opera、FireFox、IE等浏览器上的书签系统要方便很多(难以想象在本地对几百个书签进行分类、查找)。javascript:location.href='http://localhost:8000/?url='+encodeURIComponent(location.href)+';title='+encodeURIComponent(document.title)
import os, time
import cherrypy
from cherrytemplate import renderTemplate
from pysqlite2 import dbapi2 as sqlite
# add this before cherrypy server start
def connect(thread_index):
cherrypy.thread_data.db = sqlite.connect("contact.db")
cherrypy.server.on_start_thread_list.append(connect)
class BasePage:
def __init__(self, title=None):
self.title = 'Bookmark'
if title:
self.title += ' : %s' % title
@cherrypy.expose
def default(self, *args):
return '%s not available <a href="/">go back home</a>' % repr(args)
def header(self):
return renderTemplate(file='./template/header.html')
def navibar(self):
return renderTemplate(file='./template/navibar.html')
def footer(self):
yield '<p><font color="grey"> %s </font></p>' % repr(cherrypy.request.headers)
yield renderTemplate(file='./template/footer.html')
class PostRemote(BasePage):
""" supply remote post
you can make a button on youre bowser, whose URL should be:
javascript:location.href='http://localhost:8000/post?url='+
encodeURIComponent(location.href)+';title='+encodeURIComponent(document.title)
where 'http://localhost:8000/post' is the url of instance of PostRemote mounted on.
"""
def __init__(self):
BasePage.__init__(self, "post")
@cherrypy.expose
def index(self, url="", title=""):
return renderTemplate(file='./template/form_postremote.html')
@cherrypy.expose
def doPost(self, url="", title="", notes="", tags=""):
return "gotcha"
cherrypy.root = PostRemote()
if __name__=="__main__":
cherrypy.config.update(file = 'tutorial.conf')
cherrypy.server.start()
Saturday, 22. April 2006, 08:42:52
import wx
# an observable calls callback functions when the data has
# changed
#o = Observable()
#def func(data):
# print "hello", data
#o.addCallback(func)
#o.set(1)
# --| "hello", 1
class Observable:
def __init__(self, initialValue=None):
self.data = initialValue
self.callbacks = {}
def addCallback(self, func):
self.callbacks[func] = 1
def delCallback(self, func):
del self.callback[func]
def _docallbacks(self):
for func in self.callbacks:
func(self.data)
def set(self, data):
self.data = data
self._docallbacks()
def get(self):
return self.data
def unset(self):
self.data = None
class Model:
def __init__(self):
self.myMoney = Observable(0)
def addMoney(self, value):
self.myMoney.set(self.myMoney.get() + value)
def removeMoney(self, value):
self.myMoney.set(self.myMoney.get() - value)
class View(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Main View")
sizer = wx.BoxSizer(wx.VERTICAL)
text = wx.StaticText(self, -1, "My Money")
ctrl = wx.TextCtrl(self, -1, "")
sizer.Add(text, 0, wx.EXPAND|wx.ALL)
sizer.Add(ctrl, 0, wx.EXPAND|wx.ALL)
self.moneyCtrl = ctrl
ctrl.SetEditable(False)
self.SetSizer(sizer)
self.moneyCtrl = ctrl
def SetMoney(self, money):
self.moneyCtrl.SetValue(str(money))
class ChangerWidget(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Main View")
sizer = wx.BoxSizer(wx.VERTICAL)
self.add = wx.Button(self, -1, "Add Money")
self.remove = wx.Button(self, -1, "Remove Money")
sizer.Add(self.add, 0, wx.EXPAND|wx.ALL)
sizer.Add(self.remove, 0, wx.EXPAND|wx.ALL)
self.SetSizer(sizer)
class Controller:
def __init__(self, app):
self.model = Model()
self.view1 = View(None)
self.view2 = ChangerWidget(self.view1)
self.MoneyChanged(self.model.myMoney.get())
self.view2.add.Bind(wx.EVT_BUTTON, self.AddMoney)
self.view2.remove.Bind(wx.EVT_BUTTON, self.RemoveMoney)
self.model.myMoney.addCallback(self.MoneyChanged)
self.view1.Show()
self.view2.Show()
def AddMoney(self, evt):
self.model.addMoney(10)
def RemoveMoney(self, evt):
self.model.removeMoney(10)
def MoneyChanged(self, money):
self.view1.SetMoney(money)
app = wx.PySimpleApp()
Controller(app)
app.MainLoop()
Showing posts 11 - 15 of 23.
anonymous
Anonymous writes: Download: http://rapidshare.com/files/4986504 ...
anonymous
anonymous
anonymous
anonymous
xiemm writes: Do you think openfoam is good?? Can you write mor ...
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
| ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | ||
CommunityWiki
Emacs Wiki
如何网聚
读书、听歌、看电影