zoukankan      html  css  js  c++  java
  • wxpython 开发sheet

    #!/usr/bin/python

    # spreadsheet.py

    from wx.lib import sheet
    import wx


    class MySheet(sheet.CSheet):
    def __init__(self, parent):
    sheet.CSheet.__init__(self, parent)
    self.row = self.col = 0
    self.SetNumberRows(55)
    self.SetNumberCols(25)

    for i in range(55):
    self.SetRowSize(i, 20)

    def OnGridSelectCell(self, event):
    self.row, self.col = event.GetRow(), event.GetCol()
    control = self.GetParent().GetParent().position
    value = self.GetColLabelValue(self.col) + self.GetRowLabelValue(self.row)
    control.SetValue(value)
    event.Skip()

    class Newt(wx.Frame):
    def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, -1, title, size = (550, 500))

    fonts = ['Times New Roman', 'Times', 'Courier', 'Courier New', 'Helvetica',
    'Sans', 'verdana', 'utkal', 'aakar', 'Arial']
    font_sizes = ['10', '11', '12', '14', '16']

    box = wx.BoxSizer(wx.VERTICAL)
    menuBar = wx.MenuBar()

    menu1 = wx.Menu()
    menuBar.Append(menu1, '&File')
    menu2 = wx.Menu()
    menuBar.Append(menu2, '&Edit')
    menu3 = wx.Menu()
    menuBar.Append(menu3, '&Edit')
    menu4 = wx.Menu()
    menuBar.Append(menu4, '&Insert')
    menu5 = wx.Menu()
    menuBar.Append(menu5, 'F&ormat')
    menu6 = wx.Menu()
    menuBar.Append(menu6, '&Tools')
    menu7 = wx.Menu()
    menuBar.Append(menu7, '&Data')
    menu8 = wx.Menu()
    menuBar.Append(menu8, '&Help')

    self.SetMenuBar(menuBar)

    toolbar1 = wx.ToolBar(self, -1, style= wx.TB_HORIZONTAL)
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_new.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_open.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_save.png'))
    toolbar1.AddSeparator()
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_cut.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_copy.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_paste.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_delete.png'))
    toolbar1.AddSeparator()
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_undo.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_redo.png'))
    toolbar1.AddSeparator()
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/incr22.png'))
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/decr22.png'))
    toolbar1.AddSeparator()
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/chart.xpm'))
    toolbar1.AddSeparator()
    toolbar1.AddLabelTool(-1, '', wx.Bitmap('icons/stock_exit.png'))

    toolbar1.Realize()

    toolbar2 = wx.ToolBar(self, wx.TB_HORIZONTAL | wx.TB_TEXT)

    self.position = wx.TextCtrl(toolbar2)
    font = wx.ComboBox(toolbar2, -1, value = 'Times', choices=fonts, size=(100, -1),
    style=wx.CB_DROPDOWN)
    font_height = wx.ComboBox(toolbar2, -1, value = '10', choices=font_sizes,
    size=(50, -1), style=wx.CB_DROPDOWN)

    toolbar2.AddControl(self.position)
    toolbar2.AddControl(font)
    toolbar2.AddControl(font_height)
    toolbar2.AddSeparator()
    bold = wx.Bitmap('icons/stock_text_bold.png')
    toolbar2.AddCheckTool(-1, bold)
    italic = wx.Bitmap('icons/stock_text_italic.png')
    toolbar2.AddCheckTool(-1, italic)
    under = wx.Bitmap('icons/stock_text_underline.png')
    toolbar2.AddCheckTool(-1, under)
    toolbar2.AddSeparator()
    toolbar2.AddLabelTool(-1, '', wx.Bitmap('icons/text_align_left.png'))
    toolbar2.AddLabelTool(-1, '', wx.Bitmap('icons/text_align_center.png'))
    toolbar2.AddLabelTool(-1, '', wx.Bitmap('icons/text_align_right.png'))

    box.Add(toolbar1, border=5)
    box.Add((5,5) , 0)
    box.Add(toolbar2)
    box.Add((5,10) , 0)

    toolbar2.Realize()
    self.SetSizer(box)
    notebook = wx.Notebook(self, -1, style=wx.RIGHT)

    sheet1 = MySheet(notebook)
    sheet2 = MySheet(notebook)
    sheet3 = MySheet(notebook)
    sheet1.SetFocus()

    notebook.AddPage(sheet1, 'Sheet1')
    notebook.AddPage(sheet2, 'Sheet2')
    notebook.AddPage(sheet3, 'Sheet3')

    box.Add(notebook, 1, wx.EXPAND)

    self.CreateStatusBar()
    self.Centre()
    self.Show(True)

    app = wx.App()
    Newt(None, -1, 'SpreadSheet')
    app.MainLoop()
  • 相关阅读:
    命令行环境下简单实用的工具——重定向&管道
    阿里2014校招笔试题(南大)——利用thread和sleep生成字符串的伪随机序列
    Pooled Allocation(池式分配)实例——Keil 内存管理
    modelsim数据导出用于matlab绘图
    顺序块和并行块
    初入博园
    数字图像处理实验(7):PROJECT 04-03 , Lowpass Filtering 标签: 图像处理MATLAB 2017-05-25 09:30 109人
    杭电acm刷题(3):1062,Text Reverse 标签: 杭电acm 2017-05-15 08:26 126人阅读 评论(0)
    杭电ACM刷题(2):1005,Number Sequence 标签: 杭电acmC语言 2017-05-11 22:43 116人阅读
    数字图像处理实验(6):PROJECT 04-02,Fourier Spectrum and Average Value 标签: 图像处理MATLABfft 2017-05-07 23:1
  • 原文地址:https://www.cnblogs.com/wudeng/p/9051551.html
Copyright © 2011-2022 走看看