Exemplo n.º 1
0
class PanelZero(wx.Panel):
    def __init__(self,parent):
	wx.Panel.__init__(self,parent=parent)
	self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)

	link = HyperLinkCtrl(self,pos=(10,350))
	self.consumer_key = 'your consumber key'
	self.consumer_secret = 'your consumber secret'
	self.url = "www.douban.com"
	self.request_token_path = "http://www.douban.com/service/auth/request_token"
	self.authorizationUrl = "http://www.douban.com/service/auth/authorize?oauth_token="
	self.access_token_path = "http://www.douban.com/service/auth/access_token"
	self.client = Oauth(self.consumer_key,self.consumer_secret)
	self.client.get_request_token(self.url,self.request_token_path)
	authorizationUrl = self.client.get_authorizationUrl(self.authorizationUrl)
	#print authorizationUrl
	link.SetURL(authorizationUrl)
	if os.path.exists('./data/user.pickle'):		
	    link.SetLabel("已完成授权")
	else:
	    link.SetLabel("去豆瓣授权")
	link.SetFont(wx.Font(15,wx.SWISS,wx.NORMAL,wx.NORMAL,False))
	link.SetBackgroundColour("SKY BLUE")
	link.SetForegroundColour("white")
	link.SetVisited(Visited=False)

	button = wx.lib.buttons.GenButton(self,-1,"Login",pos=(100,220))
	button.SetFont(wx.Font(20,wx.SWISS,wx.NORMAL,wx.BOLD,False))
	button.SetBackgroundColour("SKY BLUE")
	button.SetForegroundColour("white")

	self.Bind(wx.EVT_BUTTON,self.OnClick,button)
	self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    def OnEraseBackground(self, evt):
        """
        Add a picture to the background
        """
        dc = evt.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        bmp = wx.Bitmap("./image/hzw.jpg")
        dc.DrawBitmap(bmp, 0, 0)

    def OnClick(self,event):
	if os.path.exists("./data/user.pickle"):
	    pass
	else :
	    access_token = self.client.get_access_token(self.url,self.access_token_path)
	    with open('./data/user.pickle','wb') as f:
		userinfo = pickle.dump(access_token,f)
	self.Hide()
	self.GetParent().panel1 = PanelOne(self.GetParent())
	self.GetParent().panel1.Fit()
	self.GetParent().panel1.SetBackgroundColour('white')
	self.GetParent().panel1.Show()