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(): #to connect with database
- con_str=cwd+ '/Data/RAMAN.db'
- cnn = sqlite3.connect(con_str)
- return cnn
- cnn.close()
- def data_rows_count(): #to count no of rows in database
- con = connect()
- cur.execute("SELECT * FROM ELEMENT")
- rows=cur.fetchall()
- i=0
- for r in rows:
- i+=1
- return i
- def titling(name): # to display the names and surnames in uppercase for 1st letter
- return name.title()
- def single_quote_remover(text): # to remove single quotes from entry to prevent SQL crash
- return text.replace ("'","/")
- class Example(wx.Frame): # this is the parent 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)
- for i in RAMAN.db:
- 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