6 ################################################################################
8 # Copyright (c) 2010 University of Tsukuba Linux User Group
10 # This file is part of "gwit".
12 # "gwit" is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # "gwit" is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with "gwit". If not, see <http://www.gnu.org/licenses/>.
25 ################################################################################
38 keys = ["Q0xJLVQOVvPp0IZysugbug",
39 "6Irwgx5pzZ8RsqGqw3OcC7Ba5pc9wYCH0m1nDj5sc"]
42 setupglade = os.path.join(
43 os.path.dirname(__file__), "ui/setupwizard.ui")
45 builder = gtk.Builder()
46 self.builder = builder
47 builder.add_from_file(setupglade)
48 builder.connect_signals(self)
50 self.oauth = twoauth.oauth(*self.keys)
51 self.rtoken = self.oauth.request_token()
52 self.authurl = self.oauth.authorize_url(self.rtoken)
54 # Unmask lbutt once clicked
55 lbutt = gtk.LinkButton(self.authurl, "Please Allow This Application")
56 lbutt.connect("clicked", self.show_and_enable_pin)
58 self.get("table1").attach(lbutt, 1, 2, 0, 1)
61 self.get("window1").show_all()
64 def close(self, widget):
68 return self.builder.get_object(name)
70 def show_and_enable_pin(self, widget):
71 urldlg = gtk.MessageDialog(buttons = gtk.BUTTONS_OK, message_format = self.authurl)
72 urldlg.connect("response", self.show_and_enable_pin_close)
74 self.get("entry1").set_sensitive(True)
76 def show_and_enable_pin_close(self, dialog, response_id):
79 def on_button1_clicked(self, widget):
80 pin = int(self.get("entry1").get_text())
83 token = self.oauth.access_token(self.rtoken, pin)
85 print "[Error] %s" % e
88 self.keys.append(token["oauth_token"])
89 self.keys.append(token["oauth_token_secret"])
91 self.screen_name = unicode(token["screen_name"])
94 lbl.set_markup("<b>%s</b>" % self.screen_name)
96 self.get("table1").attach(lbl, 1, 2, 2, 3)
97 self.get("table1").show_all()
99 self.get("button1").set_sensitive(False)
100 self.get("entry1").set_sensitive(False)
101 self.get("button3").set_sensitive(True)
103 def on_button3_clicked(self, widget):
105 self.get("window1").destroy()
108 def on_entry1_changed(self, widget):
109 pin = widget.get_text()
110 if len(pin) == 7 and pin.isdigit():
111 self.get("button1").set_sensitive(True)
113 self.get("button1").set_sensitive(False)