Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import wx.grid
- import os
- import sqlite3
- cwd = os.path.abspath(os.curdir)
- def connect():
- con_str=cwd+ '/Data/RAMAN.db'
- cnn = sqlite3.connect(con_str)
- return cnn
- cnn.close()
- def data_rows_count():
- con = connect()
- cur.execute("SELECT * FROM ELEMENT")
- rows=cur.fetchall()
- i=0
- for r in rows:
- i+=1
- return i
- class Example(wx.Frame):
- def __init__(self, parent, title):
- super(Example, self).__init__(parent, title=title, size=(800,600))
- self.InitUI()
- self.Layout()
- self.Centre()
- self.Show()
- def refresh_data(self):
- cnn =connect()
- cur = cnn.cursor()
- cur.execute("SELECT * FROM ELEMENT")
- rows=cur.fetchall()
- for i in range (0,len(rows)):
- for j in range(0,4):
- cell = rows[i]
- self.grid_1.SetCellValue(i,j,str(cell[j]))
- def InitUI(self):
- p = wx.Panel(self)
- bs = wx.BoxSizer(wx.VERTICAL)
- self.t1 = wx.TextCtrl(p,size = (120,30),style = wx.TE_MULTILINE |wx.TE_CENTER
- )
- bs.Add(self.t1, 1, wx.EXPAND)
- gs = wx.GridSizer(11, 18, 5, 5)
- bs.Add(gs, 1, wx.EXPAND)
- def __set_properties(self):
- r=data_rows_count()
- self.grid_1.CreateGrid(r, 4)
- self.grid_1.SetColLabelValue(0, _("ATOMIC NUMBER"))
- self.grid_1.SetColSize(0, 12)
- self.grid_1.SetColLabelValue(1, _("SYMBOL"))
- self.grid_1.SetColSize(1, 150)
- self.grid_1.SetColLabelValue(2, _("ROW"))
- self.grid_1.SetColSize(2, 150)
- self.grid_1.SetColLabelValue(3, _("COLUMN"))
- self.grid_1.SetColSize(3, 150)
- self.refresh_data()
- for i in ELEMENT:
- btn = wx.Button(p, -1, i, (10,20))
- btn.myname = i
- btn.Bind(wx.EVT_BUTTON, self.OnClick, btn)
- gs.Add(btn, 0, wx.EXPAND)
- p.SetSizer(bs)
- def OnClick(self, event):
- name = event.GetEventObject().myname
- self.t1.AppendText(name)
- self.t1.AppendText("\n")
- cnn.commit()
- cnn.close()
- app = wx.App()
- Example(None, title = 'Grid demo')
- app.MainLoop()
Add Comment
Please, Sign In to add comment