#! /usr/bin/python # -*- coding: utf-8 -*- import sys import os import gtk import pango version = '0.9' splash = u'''      ||MESSAGE      ||ファイル名を指定して起動する Λ Λ  いいですね。      ||モナーフォント要インストール\ (゚ー゚*)       ||_____________  ⊂⊂ |         ∧ ∧    ∧ ∧    ∧ ∧    | ̄ ̄ ̄ ̄|   (  ∧ ∧ (   ∧ ∧ (  ∧ ∧ |      | ~(_(  ∧ ∧ __(  ∧ ∧__(   ∧ ∧ ̄ ̄ ̄   ~(_(  ∧ ∧_(  ∧ ∧_(   ∧ ∧  は~い、先生。     ~(_(   ,,)~(_(   ,,)~(_(   ,,)       ~(___ノ  ~(___ノ   ~(___ノ  ''' supported_encodings = ['ms932', 'utf-8', 'euc-jp', 'iso-2022-jp'] appname = os.path.basename(sys.argv[0]) def button_clicked(widget): gtk.main_quit() def key_pressed(widget, kev): if kev.keyval == gtk.keysyms.Escape: gtk.main_quit() win = gtk.Window() win.connect('destroy', gtk.mainquit) win.connect('key-press-event', key_pressed) win.set_default_size(600, 400) win.set_title(appname) table = gtk.Table(1, 2, gtk.FALSE) win.add(table) swin = gtk.ScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.show() l = gtk.Label('') l.set_alignment(0, 0) font = pango.FontDescription('Mona 12') l.modify_font(font) swin.add_with_viewport(l) #l.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) #l.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white')) l.show() table.attach(swin, # X direction Y direction 0, 1, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0) b = gtk.Button('閉じる') b.connect('clicked', button_clicked) b.show() table.attach(b, # X direction Y direction 0, 1, 1, 2, gtk.EXPAND | gtk.FILL, 0, 0, 0) table.show() win.set_default_size(600, 400) win.show() if len(sys.argv) == 2: fname = sys.argv[1] try: if fname == '-': file = sys.stdin else: file = open(sys.argv[1]) text = file.read() if fname != '-': file.close() for encoding in supported_encodings: try: utext = text.decode(encoding) text = utext break except UnicodeError: continue except KeyboardInterrupt: text = splash.replace('MESSAGE', 'エラー:中断しますた') break except IOError: text = splash.replace('MESSAGE', 'エラー:ファイルありません') else: text = splash.replace('MESSAGE', appname + ' ver' + version) l.set_text(text) try: gtk.main() except KeyboardInterrupt: gtk.mainquit