Código Python:
Ver original
#inicio.py import wx import os import sqlite3 as lite from save import wSave #from dos import MyPanel class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "Prueba", size=(300, 400)) self.InitUI() self.Centre() self.Show() def InitUI(self): panel = wSave(self, style=wx.TAB_TRAVERSAL) #--------------------------------------------------------------------- # Run the program if __name__ == "__main__": app = wx.App(False) frame = MyFrame() app.MainLoop()
Código Python:
Ver original
#save.py import wx import os import sqlite3 as lite from metodos import alMetodos class wSave(wx.Panel): def __init__(self, *args, **kwargs): kwargs['style'] = wx.TAB_TRAVERSAL wx.Panel.__init__(self, *args, **kwargs) menubar = wx.MenuBar() fileMenu = wx.Menu() fitem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application') menubar.Append(fileMenu, '&File') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, alMetodos.OnQuit, fitem) help = wx.Menu() fitemdos = help.Append(-1, '&About') menubar.Append(help, '&Help') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, alMetodos.OnAboutBox, fitemdos) vbox = wx.BoxSizer(wx.VERTICAL) hbox = wx.BoxSizer(wx.HORIZONTAL) st1 = wx.StaticText(self,-1,label='Nombre: ') self.tc1 = wx.TextCtrl(self, -1, size=(100, -1)) self.tc1.SetFocus() hbox.Add(st1) hbox.Add(self.tc1, flag = wx.LEFT, border = 10) vbox.Add(hbox, flag=wx.LEFT | wx.TOP, border=40) vbox.Add((-1, 10)) hbox2 = wx.BoxSizer(wx.HORIZONTAL) st2 = wx.StaticText(self,-1, label=u"Anios: ") self.tc2 = wx.TextCtrl(self, -1, size=(100,-1)) hbox2.Add(st2) hbox2.Add(self.tc2, flag=wx.LEFT, border=25) vbox.Add(hbox2, flag=wx.LEFT | wx.TOP, border=40) vbox.Add((-1,10)) hbox3 = wx.BoxSizer(wx.HORIZONTAL) st3 = wx.StaticText(self, -1, label=u"Apodo: ") self.tc3 = wx.TextCtrl(self, -1, size=(100, -1)) hbox3.Add(st3) hbox3.Add(self.tc3, flag=wx.LEFT, border=20) vbox.Add(hbox3, flag=wx.LEFT | wx.TOP | wx.BOTTOM, border=40) vbox.Add((-1,10)) hbox4 = wx.BoxSizer(wx.HORIZONTAL) btn = wx.Button(self, label="Guardar") cle = wx.Button(self, label="Limpiar") btn.Bind(wx.EVT_BUTTON, alMetodos.onSave) cle.Bind(wx.EVT_BUTTON, alMetodos.onCle) #para espacio entre conponentes es con flag al igual que hbox y esas cosas hbox4.Add(btn,flag=wx.LEFT) hbox4.Add(cle,flag=wx.LEFT|wx.BOTTOM, border=10) vbox.Add(hbox4, flag=wx.LEFT, border=40) vbox.Add((-1,15)) self.tc1.MoveAfterInTabOrder(self.tc3) self.tc2.MoveAfterInTabOrder(self.tc1) self.tc3.MoveAfterInTabOrder(self.tc2) self.SetSizer(vbox) #---------------------------------------------------------------------- # Run the program if __name__ == "__main__": app = wx.App(False) frame = monti() app.MainLoop()
Código Python:
Ver original
#metodos.py import wx import os import sqlite3 as lite class alMetodos: def OnQuit(self, e): dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) ret = dial.ShowModal() if ret == wx.ID_YES: self.Destroy() else: self.Show() #---------------------------------------------------------------------- #About de la aplicacion def OnAboutBox(self, e): description = """ . """ licence = """Puede ser usado por cualquiera.""" info = wx.AboutDialogInfo() info.SetIcon(wx.Icon('hunter.png', wx.BITMAP_TYPE_PNG)) info.SetName('Monti') info.SetVersion('0.1a') info.SetDescription(description) info.SetCopyright('(C) 2013 Hiram') info.SetWebSite('http://valles.servehttp.com') info.SetLicence(licence) info.AddDeveloper('Hiram Zuniga') info.AddDocWriter('Hiram Zuniga') info.AddArtist('Hiram') info.AddTranslator('YORCH') wx.AboutBox(info) #---------------------------------------------------------------------- # Metoth questyon before to close def OnClose(self, event): dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) ret = dial.ShowModal() if ret == wx.ID_YES: self.Destroy() else: self.Show() #----------------------------------------------------------------------- #Guarda registro y limpia por si agregan uno nuevo def onSave(self, event): try: con = lite.connect('people') cur = con.cursor() name = self.tc1.GetValue() age = self.tc2.GetValue() remark = self.tc3.GetValue() cur.execute('insert into neighbours values(?, ?, ?)', (name, age, remark)) con.commit() cur.close() con.close() self.tc1.Clear() self.tc2.Clear() self.tc3.Clear() except lite.Error, error: dlg = wx.MessageDialog(self, str(error), 'Error occured') dlg.ShowModal() def onCle(self,event): self.tc1.Clear() self.tc2.Clear() self.tc3.Clear()