やる夫で学ぶCooking&AAstory 第0章 http://d.hatena.ne.jp/lionfan/20090105#1231170925
#! /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import gtk
import pango
import urllib
from BeautifulSoup import BeautifulSoup
win = gtk.Window()
win.connect('destroy', gtk.main_quit)
win.set_default_size(800, 600)
win.set_title('やる夫で学ぶCooking&AAstory 第0章')
table = gtk.Table(1, 2, False)
win.add(table)
swin = gtk.ScrolledWindow()
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
l = gtk.Label('')
l.set_alignment(0.5, 0.5)
fonts = ['Mona 10', 'MS UI Gothic 10']
for fn in fonts:
try:
font = pango.FontDescription(fn)
if font:
l.modify_font(font)
break
except:
pass
swin.add_with_viewport(l)
table.attach(swin,
# X direction Y direction
0, 1, 0, 1,
gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL,
0, 0)
b = gtk.Button('次へ')
def button_clicked(widget):
if len(ascii_arts) == 0:
gtk.main_quit()
return
elif len(ascii_arts) == 1:
b.set_label('閉じる')
text = ''.join(ascii_arts.pop(0).findAll(text=True))
l.set_text(text)
b.connect('clicked', button_clicked)
table.attach(b,
# X direction Y direction
0, 1, 1, 2,
gtk.EXPAND | gtk.FILL, 0,
0, 0)
html = urllib.urlopen('http://d.hatena.ne.jp/lionfan/20090105#1231170925').read().decode('euc-jp', 'ignore')
soup = BeautifulSoup(html, convertEntities='html')
ascii_arts = soup.findAll('div', { 'class' : 'ascii-art'})
b.emit('clicked')
win.show_all()
try:
gtk.main()
except KeyboardInterrupt:
gtk.main_quit()
追記第1章も作った...というかタイトルとURL変えただけだが...
#! /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import gtk
import pango
import urllib
from BeautifulSoup import BeautifulSoup
win = gtk.Window()
win.connect('destroy', gtk.main_quit)
win.set_default_size(800, 600)
win.set_title('やる夫で学ぶCooking&AAstory 第1章')
table = gtk.Table(1, 2, False)
win.add(table)
swin = gtk.ScrolledWindow()
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
l = gtk.Label('')
l.set_alignment(0.5, 0.5)
fonts = ['Mona 10', 'MS UI Gothic 10']
for fn in fonts:
try:
font = pango.FontDescription(fn)
if font:
l.modify_font(font)
break
except:
pass
swin.add_with_viewport(l)
table.attach(swin,
# X direction Y direction
0, 1, 0, 1,
gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL,
0, 0)
b = gtk.Button('次へ')
def button_clicked(widget):
if len(ascii_arts) == 0:
gtk.main_quit()
return
elif len(ascii_arts) == 1:
b.set_label('閉じる')
text = ''.join(ascii_arts.pop(0).findAll(text=True))
l.set_text(text)
b.connect('clicked', button_clicked)
table.attach(b,
# X direction Y direction
0, 1, 1, 2,
gtk.EXPAND | gtk.FILL, 0,
0, 0)
html = urllib.urlopen('http://d.hatena.ne.jp/lionfan/20090106#1231249409').read().decode('euc-jp', 'ignore')
soup = BeautifulSoup(html, convertEntities='html')
ascii_arts = soup.findAll('div', { 'class' : 'ascii-art'})
b.emit('clicked')
win.show_all()
try:
gtk.main()
except KeyboardInterrupt:
gtk.main_quit()