- d:id:Voluntas:20060820のコメント欄で思いついた.じゃない,思い立った.
こんなの.PythonとwxPythonの実行環境が必須です.ansi版とunicode版が選べますがunicode版がおすすめ.
こんなスクリプトを書くのにn時間かかったのは内緒だ.最初正規表現で書こうとしてあきらめたのは教訓になった.なんでも正規表現でやろうとしないほうがいい.
はてなのURLの妥当性とかはチェックしてません.ラベルやタイトルの英語がおかしいときはコメントで教えてください.
参考にした資料
- http://www.harukaze.net/~haruka/wxpython/index.htmlのチェックボックス,テキストコントロール,ボタンによるイベントの例
- wxPython in Actionのp.190-p.192
# -*- coding: utf-8 -*- import wx class MainFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Hatena Diary URL to Convert diary notation', size=(500,100)) panel = wx.Panel(self, -1) URLLabel = wx.StaticText(panel, -1, 'URI:') self.URLText = wx.TextCtrl(panel, -1, '', size = (400, -1)) self.URLText.SetInsertionPoint(0) self.URLText.Bind(wx.EVT_TEXT, self.convert) hatenaNoLabel = wx.StaticText(panel, -1, 'Diary Notation:') self.hatenaNoText = wx.TextCtrl(panel, -1, '', size = (400, -1)) self.checkTitle = wx.CheckBox(panel, -1, "Title") self.checkTitle.Bind(wx.EVT_CHECKBOX, self.convert) sizer =wx.FlexGridSizer(cols = 2, hgap = 6, vgap = 6) sizer.AddMany([URLLabel,self.URLText,hatenaNoLabel,self.hatenaNoText,self.checkTitle]) panel.SetSizer(sizer) def convert(self, event): try: import urlparse url = self.URLText.GetValue() t = urlparse.urlsplit(url) self.exp = t[1][0]+':id'+t[2].replace('/',':') self.exp = self.exp.strip(':') if self.checkTitle.GetValue(): self.exp += ':title' self.hatenaNoText.SetValue(self.exp) except IndexError: self.hatenaNoText.SetValue('This string isn\'t diary/group URL') class MyApp(wx.App): def OnInit(self): self.frame = MainFrame() self.frame.Show() self.SetTopWindow(self.frame) return True if __name__ == '__main__': app = MyApp() app.MainLoop()