pythonのお勉強

NO IMAGE

ここんとこ、机にかぢりついてpythonのguiアプリお勉強。してるんですが、一向に進まず・・・
 でも、開発環境はなんとなく固まってきたかも。

 開発言語:python
 guiツールキット:wxpython
 guiビルダー:wxglade
 IDLE:pyscripter

 なんだけど、pyscripterが落ちまくる。無難にeclipse当たりにした方が良いのかも。

 ちなみに今日書いたコードをべた貼り。とりあえず動くことは動く。

[source=’python’]#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Wed Jan 07 14:26:26 2009

import wx
import wx.grid

# begin wxGlade: extracode
# end wxGlade

class Myforman(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: Myforman.__init__
kwds[“style”] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel_1 = wx.Panel(self, -1)
self.sizer_2_staticbox = wx.StaticBox(self.panel_1, -1, “”)

# Menu Bar
self.kforman_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
self.kforman_menubar.Append(wxglade_tmp_menu, _(u”ファイル”))
wxglade_tmp_menu = wx.Menu()
self.kforman_menubar.Append(wxglade_tmp_menu, _(u”ヘルプ”))
self.SetMenuBar(self.kforman_menubar)
# Menu Bar end
self.label_1 = wx.StaticText(self.panel_1, -1, _(u”森林資源予測システムn    kforman”), style=wx.ALIGN_CENTRE)
self.button_2 = wx.Button(self.panel_1, -1, _(u”林分情報入力画面”))
self.button_2.Bind(wx.EVT_BUTTON, self.Showframe)

self.button_1 = wx.Button(self.panel_1, -1, _(u”立木情報入力画面”))

self.__set_properties()
self.__do_layout()
# end wxGlade

def Showframe(self,e):
win = Myforman1(None,-1)
win.Show()

def __set_properties(self):
# begin wxGlade: Myforman.__set_properties
self.SetTitle(_(u”施業提案システム kuforman”))
# end wxGlade

def __do_layout(self):
# begin wxGlade: Myforman.__do_layout
sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
sizer_2 = wx.StaticBoxSizer(self.sizer_2_staticbox, wx.VERTICAL)
sizer_2.Add(self.label_1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 8)
sizer_2.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 1)
sizer_2.Add(self.button_1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 8)
self.panel_1.SetSizer(sizer_2)
sizer_1.Add(self.panel_1, 1, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 8)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
self.Centre()
# end wxGlade

# end of class Myforman

class Myforman1(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: Myforman1.__init__
kwds[“style”] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.grid_1 = wx.grid.Grid(self, -1, size=(1, 1))

self.__set_properties()
self.__do_layout()
# end wxGlade

def __set_properties(self):
# begin wxGlade: Myforman1.__set_properties
self.SetTitle(_(“frame_1″))
self.grid_1.CreateGrid(10, 2)
self.grid_1.SetColLabelValue(0, _(u”胸高直径”))
self.grid_1.SetColLabelValue(1, _(u”樹高”))
# end wxGlade

def __do_layout(self):
# begin wxGlade: Myforman1.__do_layout
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3.Add(self.grid_1, 1, wx.EXPAND, 0)
self.SetSizer(sizer_3)
sizer_3.Fit(self)
self.Layout()
# end wxGlade

# end of class Myforman1

class MyForman2(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyForman2.__init__
kwds[“style”] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.label_2 = wx.StaticText(self, -1, _(u”樹種名nカタカナで記入してください。”))
self.text_ctrl_5 = wx.TextCtrl(self, -1, “”)
self.label_3 = wx.StaticText(self, -1, _(u”林齢n半角数字で記入してください”), style=wx.ALIGN_CENTRE)
self.text_ctrl_6 = wx.TextCtrl(self, -1, “”)
self.label_4 = wx.StaticText(self, -1, _(u”ha当たりl立木本数n半角数字で記入してください。n”))
self.text_ctrl_7 = wx.TextCtrl(self, -1, “”)

self.__set_properties()
self.__do_layout()
# end wxGlade

def __set_properties(self):
# begin wxGlade: MyForman2.__set_properties
self.SetTitle(_(“frame_2”))
# end wxGlade

def __do_layout(self):
# begin wxGlade: MyForman2.__do_layout
grid_sizer_1 = wx.GridSizer(3, 2, 1, 1)
grid_sizer_1.Add(self.label_2, 0, 0, 0)
grid_sizer_1.Add(self.text_ctrl_5, 0, 0, 0)
grid_sizer_1.Add(self.label_3, 0, 0, 0)
grid_sizer_1.Add(self.text_ctrl_6, 0, 0, 0)
grid_sizer_1.Add(self.label_4, 0, 0, 0)
grid_sizer_1.Add(self.text_ctrl_7, 0, wx.ALL, 0)
self.SetSizer(grid_sizer_1)
grid_sizer_1.Fit(self)
self.Layout()
# end wxGlade

# end of class MyForman2

class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
kforman = Myforman(None, -1, “”)
self.SetTopWindow(kforman)
kforman.Show()
return 1

# end of class MyApp

if __name__ == “__main__”:
import gettext
gettext.install(“app”) # replace with the appropriate catalog name

app = MyApp(0)
app.MainLoop()
[/source]