顯示具有 筆記 標籤的文章。 顯示所有文章
顯示具有 筆記 標籤的文章。 顯示所有文章

2011年10月24日 星期一

VBA:動態二維數組

試了,留個備忘。

Option Base 1                            '數組的下限編號由 "1" 起

Sub test001()
'測試動態二維數組
    Dim MyArry()                             '宣告一個數組
   
    Worksheets("sheet1").Activate            '設定資料頁
    r = Range("A65536").End(xlUp).Row        '按資料頁,設第一維
    s = Range("IV1").End(xlToLeft).Column    '按資料頁,設第二維
   
    ReDim MyArry(r, s)      '動態數組,改變二維的數量
    '
    For i = 1 To r          '迴圈,將資料頁 A 欄寫進第一維  (姓名)
        For j = 1 To s      '迴圈,將資料頁 B 欄寫進第二維  (編號)
            MyArry(i, j) = Cells(i, j).Value     ' 寫入 姓名 至第一維
            MyArry(i, s) = Cells(i, s).Value     ' 寫入 編號 至第二維
        Next j
    Next i
End Sub


2011年9月8日 星期四

VBA 下的 sumif 公式

    For j = 11 To 23
            Set rgc = Range(Cells(15, 5), Cells(15, 5).End(xlDown))
            Set rgf = Range(Cells(15, j), Cells(15, j).End(xlDown))
            Cells(10, j).Select
                       
            'ActiveCell.Formula = "=SUMIF(" & rgc.Address & ",""第一分類""," & rgf.Address & ")"
            Cells(10, j).Formula = "=SUMIF(" & rgc.Address & ",""第一分類""," & rgf.Address & ")"
            Cells(10, j) = Cells(10, j).Value
            Cells(11, j).Formula = "=SUMIF(" & rgc.Address & ",""第二分類""," & rgf.Address & ")"
            Cells(11, j) = Cells(11, j).Value
            Cells(12, j).Formula = "=SUMIF(" & rgc.Address & ",""第三分類""," & rgf.Address & ")"
            Cells(12, j) = Cells(12, j).Value
           
            Cells(8, j) = Cells(10, j).Value + Cells(11, j).Value + Cells(12, j).Value
           
    Next j

2011年7月12日 星期二

團購的威力(二)

巨龍船務又推出新「團購」,
結果賣出 118,622 張船票。

沒錯,共 11 萬 8 千多張「預售票」。















我估算它的收益如下:


2011年2月12日 星期六

Python筆記(模組的應用)




class Aa:
    def __init__(self,Value_1,Value_2):
        self.name=Value_1
        self.data=Value_2
    aa=99
    def sayhi(self):
        print " Hello, Everyone! "

       
>>> test=Aa("storylai","1010")
>>> test.name
'storylai'
>>> test.data
'1010'
>>> test.aa
99
>>> test.sayhi()
 Hello, Everyone!




要記下來的:

class Aa:
不用說了,模組的標準型態

def __init__(self,Value_1,Value_2):
    self.name=Value_1
    self.data=Value_2
模組的初始化。使用時必須輸入兩個變數。
        >>> test=Aa("storylai","1010")
__init__ 也是Method,类似於构造函数,只要对象被建立时便马上运行。       

aa=99       
這是模組內置變數的例子。
        >> test.aa
        99
       
def sayhi(self):
    print " Hello, Everyone! "
這是模組內置函數的例子。
        >>> test.sayhi()
         Hello, Everyone!
        

究竟 Self 是什麼?
這就是 class 的方法(Method)與普通函數的唯一分別,self必須是第一個參數名稱,我們卻不必為這個參數賦值,Python會自動提供轉換。
例如 Aa 這個 class 中的 __init__(self,Value_1,Value_2),Python自動轉為Aa.method(__init__, arg1, arg2)
        




2011年1月4日 星期二

VBA: 簡化了抄入方法

Sub readedit()
'#######  預設檔案擺放的位置,可修改以下變數
          sPath = ActiveWorkbook.Path & "\aReport\"
'######################################################
'清除本頁所有資料
Cells.Clear
'讀取本 Workbook 名稱
wName = ActiveWorkbook.Name
'讀取本 WorkSheet 名稱
sName = ActiveSheet.Name
'開始抄入 31 日的檔案
With Workbooks(wName).Worksheets(sName)
    For aa = 1 To 31
        '決定本頁的續寫範圍
        LastRow = .Range("A65536").End(xlUp).Row
            If LastRow = 1 Then
                '如果是第 1 日,則寫在第一列
                LastRow = 1
            Else
                '不是第 1 日,則須寫在緊隨資料後的空白列
                LastRow = LastRow + 1
            End If
        '取得檔案名稱中的"日期"
        sDay = Right("0" & aa, 2)
        '合成要開啟的檔案全名
        aRs = "rs-201012" & sDay & ".xls"
        '以唯讀開啟每日報數檔
        Workbooks.Open Filename:=sPath & aRs, ReadOnly:=True
            '如果是第 1 日,則連「標題列」抄入
            If aa = 1 Then
                '簡化了的抄入方法 (1)
                Sheets("Report").Range("A1").CurrentRegion.Copy .Cells(LastRow, 1)
            Else
            '不果是第 1 日,則 Resize 省略「標題列」
                Set aRng = Sheets("Table").Range("A1").CurrentRegion
                Set aRng = aRng.Offset(1, 0).Resize(aRng.Rows.Count - 1)
                    '簡化了的抄入方法 (2)
                    aRng.Copy .Cells(LastRow, 1)
            End If
        '關閉已開的每日檔
        ActiveWorkbook.Close
    '開下一日之報數檔
    Next aa
End With

'簡化了的寫法:假設只有本頁開啟
With Range("A1").CurrentRegion
        '原來的報數檔都是「文字」,故轉為值
        .Cells = .Cells.Value
        '設定字型
        .Font.Name = "Arial"
        '設定字型大小
        .Font.Size = 8
 '   .Font.Bold = True
 '   .Font.ColorIndex = 3
End With

End Sub

2010年11月22日 星期一

VBA:恢復工具列

試著試著,Excel 的 toolbar 、 menu 都不見了,幸好找到以下的程式碼。不用重裝。


Sub Recover1()
    Dim cmb As CommandBar
   On Error Resume Next
    For Each cmb In Application.CommandBars
        cmb.Visible = True
        cmb.Enabled = True
    Next cmb
End Sub

2010年11月20日 星期六

試用 Array() 做變數:分頁名稱

 
 
Sub Main_11

    DIm oArray(3) As String
        oArray(0)="Sheet1"
        oArray(1)="Sheet2"
        oArray(2)="Sheet3"

        oDoc=ThisComponent
        oController=oDoc.getCurrentController()
        oSheets=oDoc.getSheets()

        for i=0 to 2 step 1
            oController.setActiveSheet(oSheets.getByName(oArray(i)))
        next i

End sub

以 range 概念取得最後行數

Sub Main_13
    Dim oRange As Object , oCursor As Object
    oRange = ThisComponent.Sheets(2).getCellRangeByName("C1")
    oCursor = ThisComponent.Sheets(2).createCursorByRange(oRange)
        '
        '以 collapseToCurrentRegion  範圍來取得
        oCursor.collapseToCurrentRegion
        Msgbox oCursor.getRows.Count
        Msgbox oCursor.getColumns.Count
        '
        '以 gotoEndOfUsedArea  範圍來取得 
        oCursor.gotoEndOfUsedArea(true)
        Msgbox oCursor.getRows.Count
        Msgbox oCursor.getColumns.Count
end sub

2010年11月16日 星期二

另一個取代 Range ("A65536").End (xlUp).Row 方法

REM  *****  BASIC  *****

Sub Main
  '指定要取得 "Sheet1" B 欄 的最後欄位
  'Ooo 由零開始,我習慣 +1
  LastRow=GetLastRow("Sheet1","B") +1
  msgbox LastRow
End Sub

Function GetLastRow(SHT as string , COL as string)as integer
  With ThisComponent
    oController = .getCurrentController()
    oSheets = .getSheets()
    '讀取傳入的「分頁名稱」變數 SHT
    oSheet1 = oSheets.getByName( SHT )
    oController.setActiveSheet( oSheet1 )
  End With

  '呼叫 UNO
  document   = ThisComponent.CurrentController.Frame
  dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

  rem ----------------------------------------------------------------------
  '讀取傳入的「欄位」變數 COL,再以 UNO 控制「游標」到最後一行 1048576
  dim args1(0) as new com.sun.star.beans.PropertyValue
  args1(0).Name = "ToPoint"
  args1(0).Value = COL & "1048576"
 
  dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

  REM -------------------------------------------------------------------------------
  '以 UNO 控制「游標」由最後一行 1048576 跳至有資料的一行
  dim args4(1) as new com.sun.star.beans.PropertyValue
  args4(0).Name = "By"
  args4(0).Value = 1
  args4(1).Name = "Sel"
  args4(1).Value = false

  dispatcher.executeDispatch(document, ".uno:GoUpToStartOfData", "", 0, args4())
REM -------------------------------------------------------------------------------
  ' 同樣,取得該行的 ROW 數,傳回 GetLastRow 再交回主程式。
  GetLastRow=ThisComponent.CurrentController.getSelection().RangeAddress.StartRow
  'GetLastCol=ThisComponent.CurrentController.getSelection().RangeAddress.StartColumn
End Function

取代 Range ("A65536").End (xlUp).Row

Ooo 長期以來,一直未有取代 Range ("A65536").End (xlUp).Row 的簡單句式,
今數據收集的工作很困難。只好在 Ooo 混用了 VBA 語法。

這兩天偶然發現兩個方法。記下來。

-1- 利用輔助列及COUNTBLANK,計出另一欄的最後一列。

PysCell = thiscomponent.sheets.getByName("Sheet1").getCellRangeByName("C1")
PysCell.formula = "=65536-COUNTBLANK(B1:B65536)"
print PysCell.value


-2- 利用 Function GetLastRow ,直接讀出某一欄的最後一列。

Sub Main
    LastRow=GetLastRow(1,0)
end sub

Function GetLastRow(x as integer,i as integer)as integer
    oSheet = ThisComponent.getSheets().getByIndex(i)
    oTargetCell = oSheet.getCellByPosition(x, 0)

        If IsNull(oTargetCell) then
            GetLastRow =oTargetCell.getRangeAddress.EndRow
        Else
            oCursor = oSheet.createCursorByRange(oTargetCell)
            oCursor.gotoEnd
            GetLastRow = oCursor.getRangeAddress.EndRow + 1
        End if

End Function

2010年11月13日 星期六

OpenOffice.org Macros Explained (Third Edition)

Andrew Pitonyak 先生的 OpenOffice.org Macros Explained 一書,一直是 寫 OpenOffice Macros 的權威,與另一本 StarSuite 8 BASIC 程式設計指南 都是我案頭書。

最近瀏覽 Andrew Pitonyak 先生的網站時,發現  OpenOffice.org Macros Explained 已著手修改成第三版,並提供下載。



我當然不甘後人,又有書可看了。

2010年11月10日 星期三

VBA 測試數組在同一分頁的應用

Sub tArray_03()
'
'測試數組在同一分頁的應用
'將Range("E1:h20")內容存至數組 myRangeData_1
'再連續 copy 至 K:N 欄
'重點是 copy 時不留空格
'
'清空要 paste 的欄位資料
[j:P] = ""

'將Range("E1:h20")內容存至數組 myRangeData_1
'用.CurrentRegion 好處是不需檢測實際範圍
myRangeData_1 = Range("E1").CurrentRegion
    'myRangeData_1 是兩維數組
    '讀取第 1 維的下標,即組中的 行數。這裡是 20 。
    LastRow = UBound(myRangeData_1, 1)
    '讀取第 2 維的下標,即組中的 欄數。這裡是 4 。
    LastCol = UBound(myRangeData_1, 2)


'做迴圈,連續抄寫至  K:N 欄
For i = 1 To 2000 Step 1
    '先檢測 k 欄是否已存有數據,如標題列等,
    '防止覆蓋之前的資料。
    newLastRow = [K65536].End(xlUp).Row
    '要由 k 欄開始 paste,故定義 J 欄,即 10 。
    C1 = 10
    '為 paste 的範圍做簡單分類設定,
    '如無任何欄位,則......
    If newLastRow = 1 Then
        '最大預設行數定為 0
        R2 = 0
        '最小預設行數定為 newLastRow
        R1 = newLastRow
    Else
        '最大預設行數定為 newLastRow
        R2 = newLastRow
        '最小預設行數定為 newLastRow + 1
        R1 = newLastRow + 1
    End If
  
    '將數組  myRangeData_1 抄入以下範圍
    '設定 copy 範圍 開始位置 Cells(R1, C1 + 1)
    '設定 copy 範圍 結束位置 Cells(R2 + LastRow, C1 + LastCol)
    Range(Cells(R1, C1 + 1), Cells(R2 + LastRow, C1 + LastCol)).Value = myRangeData_1
Next i

MsgBox "已完成!"


End Sub

2010年11月2日 星期二

佛山地震???

 
 
日  期:2010年11月02日
發震時間:08時15分9.42秒
參考地點:廣東佛山
震  級:2.2(ML)
經  度:113.4
緯  度:22.8

來源   http://www.gdsin.net/seis/seisdkb.htm

2010年10月22日 星期五

wxPython 筆記 ( event 01 )

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx

class MyApp(wx.App):
    def OnInit(self):
        frame=MyFrame(title=u"視窗",pos=(100,150),size=(250,200))
        frame.Show()
        self.SetTopWindow(frame)
        return True


class MyFrame(wx.Frame):
    def __init__(self,title,pos,size):
        wx.Frame.__init__(self,None,-1,title,pos,size) # 備用,使用取代 frame 的 OnInit()

        #建立panel
        panel=wx.Panel(self)
        #新增一個按鈕並把它加到panel裡面
        button=wx.Button(panel,label=u"按鍵_1",pos=(25,25),size=(80,50))
        #新增另一個按鈕並把它加到panel裡面
        button_2=wx.Button(panel,label=u"按鍵_2",pos=(25,100),size=(80,50))

        # 建立事件監聽 #############################################################

        # 攔截「右上角 x 之視窗關閉鍵   wx.EVT_CLOSE」,轉向 OnCloseWin,得 :確定要關閉程式
        self.Bind(wx.EVT_CLOSE,self.OnCloseWin)

        #攔截「按 button 鍵   wx.EVT_BUTTON 」,轉向 OnClick ,得出 : 你按了 '按鍵1'
        self.Bind(wx.EVT_BUTTON,self.OnClick_1,button)

        #攔截「按 button 鍵   wx.EVT_BUTTON 」,轉向 OnClick ,得出 : 你按了 '按鍵1'
        self.Bind(wx.EVT_BUTTON,self.OnClick_2,button_2)

    #定義按鈕案下的函數  
    def OnClick_1(self,event):
        wx.MessageBox(u"你按了 '按鍵_1' ",u"提示訊息")

    def OnClick_2(self,event):
        wx.MessageBox(u"你按了 '按鍵_2' ",u"提示訊息")
      
    #定義按下關閉視窗(右上X)的函數
    def OnCloseWin(self,event):
        dlg=wx.MessageDialog(None,u"確定要關閉程式?",u"提示訊息",wx.YES_NO)
      
        #按下YES才會關閉視窗
        if dlg.ShowModal()==wx.ID_YES:
            self.Destroy()


if __name__=="__main__":
    app = MyApp()
    app.MainLoop()

2010年10月13日 星期三

wxPython 筆記 (calculator)
















#!/usr/bin/python
# http://wiki.wxpython.org/AnotherTutorial
# calculator.py

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):

        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(300, 250))
        self.formula = False
        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(22, '&Quit', 'Exit Calculator')
        menubar.Append(file, '&File')
        self.SetMenuBar(menubar)
        wx.EVT_MENU(self, 22, self.OnClose)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.display = wx.TextCtrl(self, -1, '',  style=wx.TE_RIGHT)
        sizer.Add(self.display, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)

        gs = wx.GridSizer(4, 4, 3, 3)
        gs.AddMany([(wx.Button(self, 20, 'Cls'), 0, wx.EXPAND),
                        (wx.Button(self, 21, 'Bck'), 0, wx.EXPAND),
                        (wx.StaticText(self, -1, ''), 0, wx.EXPAND),
                        (wx.Button(self, 22, 'Close'), 0, wx.EXPAND),
                        (wx.Button(self, 1, '7'), 0, wx.EXPAND),
                        (wx.Button(self, 2, '8'), 0, wx.EXPAND),
                        (wx.Button(self, 3, '9'), 0, wx.EXPAND),
                        (wx.Button(self, 4, '/'), 0, wx.EXPAND),
                        (wx.Button(self, 5, '4'), 0, wx.EXPAND),
                        (wx.Button(self, 6, '5'), 0, wx.EXPAND),
                        (wx.Button(self, 7, '6'), 0, wx.EXPAND),
                        (wx.Button(self, 8, '*'), 0, wx.EXPAND),
                        (wx.Button(self, 9, '1'), 0, wx.EXPAND),
                        (wx.Button(self, 10, '2'), 0, wx.EXPAND),
                        (wx.Button(self, 11, '3'), 0, wx.EXPAND),
                        (wx.Button(self, 12, '-'), 0, wx.EXPAND),
                        (wx.Button(self, 13, '0'), 0, wx.EXPAND),
                        (wx.Button(self, 14, '.'), 0, wx.EXPAND),
                        (wx.Button(self, 15, '='), 0, wx.EXPAND),
                        (wx.Button(self, 16, '+'), 0, wx.EXPAND) ])

        sizer.Add(gs, 1, wx.EXPAND)

        self.SetSizer(sizer)
        self.Centre()

        self.Bind(wx.EVT_BUTTON, self.OnClear, id=20)
        self.Bind(wx.EVT_BUTTON, self.OnBackspace, id=21)
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=22)
        self.Bind(wx.EVT_BUTTON, self.OnSeven, id=1)
        self.Bind(wx.EVT_BUTTON, self.OnEight, id=2)
        self.Bind(wx.EVT_BUTTON, self.OnNine, id=3)
        self.Bind(wx.EVT_BUTTON, self.OnDivide, id=4)
        self.Bind(wx.EVT_BUTTON, self.OnFour, id=5)
        self.Bind(wx.EVT_BUTTON, self.OnFive, id=6)
        self.Bind(wx.EVT_BUTTON, self.OnSix, id=7)
        self.Bind(wx.EVT_BUTTON, self.OnMultiply, id=8)
        self.Bind(wx.EVT_BUTTON, self.OnOne, id=9)
        self.Bind(wx.EVT_BUTTON, self.OnTwo, id=10)
        self.Bind(wx.EVT_BUTTON, self.OnThree, id=11)
        self.Bind(wx.EVT_BUTTON, self.OnMinus, id=12)
        self.Bind(wx.EVT_BUTTON, self.OnZero, id=13)
        self.Bind(wx.EVT_BUTTON, self.OnDot, id=14)
        self.Bind(wx.EVT_BUTTON, self.OnEqual, id=15)
        self.Bind(wx.EVT_BUTTON, self.OnPlus, id=16)

    def OnClear(self, event):
        self.display.Clear()

    def OnBackspace(self, event):
        formula = self.display.GetValue()
        self.display.Clear()
        self.display.SetValue(formula[:-1])

    def OnClose(self, event):
        self.Close()

    def OnDivide(self, event):
        if self.formula:
            return
        self.display.AppendText('/')

    def OnMultiply(self, event):
        if self.formula:
            return
        self.display.AppendText('*')

    def OnMinus(self, event):
        if self.formula:
            return
        self.display.AppendText('-')

    def OnPlus(self, event):
        if self.formula:
            return
        self.display.AppendText('+')

    def OnDot(self, event):
        if self.formula:
            return
        self.display.AppendText('.')

    def OnEqual(self, event):
        if self.formula:
            return
        formula = self.display.GetValue()
        self.formula = False
        try:
            self.display.Clear()
            output = eval(formula)
            self.display.AppendText(str(output))
        except StandardError:
            self.display.AppendText("Error")

    def OnZero(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('0')

    def OnOne(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('1')

    def OnTwo(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('2')

    def OnThree(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('3')

    def OnFour(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('4')

    def OnFive(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('5')

    def OnSix(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('6')

    def OnSeven(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('7')

    def OnEight(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('8')

    def OnNine(self, event):
        if self.formula:
            self.display.Clear()
            self.formula = False
        self.display.AppendText('9')

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'calculator.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()
  
  
  

2010年10月12日 星期二

wxPython 筆記 (RadioBox)

import wx

class RadioBoxFrame(wx.Frame):
#    def __init__(self):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id, 'Radio Box Example', size=(550, 400))

        panel = wx.Panel(self)
       
        sampleList = ['zero', 'one', 'two', 'three', 'four', 'five','six', 'seven', 'eight']
        wx.RadioBox(panel, -1, "A Radio Box", (10, 10), wx.DefaultSize,sampleList, 2, wx.RA_SPECIFY_COLS)
        wx.RadioBox(panel, -1, "Next Radio Box", (150, 10), wx.DefaultSize,sampleList, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
        wx.RadioBox(panel, -1, "Thrid Radio Box", (350, 10), wx.DefaultSize,sampleList, 1, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
        wx.RadioBox(panel, -1, "Fourth Radio Box", (10, 250), wx.DefaultSize,sampleList, 1, wx.RA_SPECIFY_ROWS | wx.NO_BORDER)

if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=RadioBoxFrame(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

2010年10月11日 星期一

創建一個wx.App 的子類

[摘錄] 創建一個 wx.App 的子類
http://www.czug.org/python/wxpythoninaction/ch02.htm

創建和使用一個wx.App子類,你需要執行四個步驟:
1、定義這個子類
2、在定義的子類中寫一個OnInit()方法
3、在你的程式的主要部分創建這個類的一個實例
4、調用應用程式實例的MainLoop()方法。這個方法將程式的控制權轉交給wxPython 

import wx 
class MyApp(wx.App):   #1 定義子類
def OnInit(self):     #2 用OnInit()方法
    frame = wx.Frame(parent=None, title=u'這是 Frame 容器')
    frame.Show()
    return True
app = MyApp()          #3 創建這個類的一個實例
app.MainLoop()         #4調用MainLoop() 方法

我們在第一章中看到過OnInit()方法。它在應用程式開始時並在主事件迴圈開始前被wxPython系統調用。這個方法不要求參數並返回一個布林值,如果所返回的值是False,則應用程式將立即退出。大多數情況下,你將想要該方法返回的結果為真。處理某些錯誤條件,退出可能是恰當的方法,諸如所一個所需的資源缺失。
 
由於OnInit()方法的存在,並且它是wxPython架構的一部分,所以任何關於你的定制的類的所需的初始化通常都由OnInit()方法管理,而不在Python的__init__方法中。

如果由於某些原因你決定需要__init__方法,那麼你必須在你的__init__方法中調用父類的__init__方法,如下所示:
 
wx.App.__init__(self)

通常,你在OnInit()方法中將至少創建一個框架物件,並調用該框架的Show()方法。你也可以有選擇地通過調用SetTopWindow()方法來為應用程式指定一個框架作為頂級視窗。頂級視窗被作為那些沒有指定父視窗的對話方塊的默認父視窗。

 

2010年10月8日 星期五

罪犯?曼德拉?和平獎!

......我沒有敵人,也沒有仇恨。所有監控過我,捉捕過我、審訊過我的警察,起訴過我的檢察官,判決過我的法官,都不是我的敵人。雖然我無法接受你們的監 控、逮捕、起訴和判決,但我尊重你的職業與人格,包括現在代表控方起訴我的張榮革和潘雪晴兩位檢察官。在12月3日兩位對我的詢問中,我能感到你們的尊重和誠意。

因為,仇恨會腐蝕一個人的智慧和良知,敵人意識將毒化一個民族的精神,煽動起你死我活的殘酷鬥爭,毀掉一個社會的寬容和人性,阻礙一個國家走向自由民主的進程。所以,我希望自己能夠超越個人的遭遇來看待國家的發展和社會的變化,以最大的善意對待政權的敵意,以愛化解恨......


摘自      劉曉波:我沒有敵人--我的最後陳述

2010年10月5日 星期二

wxPython 筆記 01

#############################################################
# Sample01 最簡單的 window
#############################################################

# -*- coding: utf-8 -*- #01

import wx #02

app = wx.PySimpleApp() #03

frame = wx.Frame(None, -1, u"這是 Frame 容器") #04
frame.Show() #05

app.MainLoop() #06

#01 定為 unicode 支援中文
#02 載入 wx 提供的資源
#03 通過使用 wxPySimpleApp 類創建一個應用程序對像:(佔用一定的記憶體)。
#04 創造一個 wxFrame 的實例, parent = None , id = -1, title = u'這是 Frame 容器'
#05 顯示剛創建的這個框框
#06 指定 wxPysimpleApp 在畫面上循環顯示,等待輸入。


#############################################################
# 備忘 wx.Frame(None, -1, "這是 Frame 容器")
#############################################################


wxPython -- wx.Frame參數說明
http://putidea.blogspot.com/2008/10/wxpython-wxframe.html

wxPython -- wxFrame style設定語法
http://putidea.blogspot.com/2008/10/wxpython-wxframe-style.html

wxPython -- ID的使用
http://putidea.blogspot.com/2008/10/wxpython-id.html



#############################################################
# Sample02 稍稍進階,標準的 window
#############################################################


# -*- coding: utf-8 -*-

import wx

class MyFirstFrame(wx.Frame): #07
def __init__(self,parent,id): #08
wx.Frame.__init__(self,parent,id,u'這是 Frame 容器',size=(500,300))

if __name__=='__main__': #09
app=wx.PySimpleApp()
frame=MyFirstFrame(parent=None,id=-1)
frame.Show()
app.MainLoop()

#07 以 class 創造 frame
#08 frame 的初始化
#09 確認本 frame 不是被引用時



###############################################################
# Sample03 另一個標準例子
# http://www.czug.org/python/wxpythoninaction/ch01.htm
###############################################################

# -*- coding: utf-8 -*-

import wx #10

class MyApp(wx.App): #11
def OnInit(self): #11-01
frame = wx.Frame(parent=None, title=u'這是 Frame 容器')
frame.Show()
return True

app = MyApp() #12
app.MainLoop() #13

#10 導入 wxPython
#11 引用 wxPython 的類、函數和常量(均以wx為前綴)
#11-01 定義 OnInit 為一個應用程序及初始化
#12 創建一個應用程序類的實例
#13 進入這個應用程序的主事件循環

 
 
 

2010年9月29日 星期三

OpenOffice 或許有版權問題出現

 
OpenOffice 或許有版權問題出現。

綜合消息指:

1- 美國大公司併購後,Oracle 取得 OpenOffice 的主要控制權,
又暗中將「完全免費」的 OpenOffice 「授權」收改,表明
Oracle 擁有 OpenOffice 的完全版權,又條改一些條款。當中
以 Windows 版本最受影響,日後公司使用時可能要付版權費。

2- 一向擁有 OpenOffice 的 OpenOffice.org 機構在 9 月 28 日突
然宣佈推出另一套以 OpenOffice 為藍本的新軟件。

3- 新軟件名稱為 LibreOffice ,網址: http://www.documentfoundation.org/

4- 相關的資料

http://www.computerworld.com/s/article/9188338/Update_OpenOffice.org_developers_move_to_break_ties_with_Oracle
http://linuxtoy.org/archives/openofficeorg-%E7%A4%BE%E5%8C%BA%E5%AE%A3%E5%B8%83%E5%BB%BA%E7%AB%8B-document-foundation.html