domingo, 12 de abril de 2015

sqlite3

#*********************************************************************
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#*********************************************************************
import sqlite3 as lite
import sys
import os
#------------------------------------------------------------------------------------------
con = None
#------------------------------------------------------------------------------------------
class PreSistema():
    def __init__(self):
        self.vpresistema = 'p'
        print('Atributos instanciados - Presistema!')
#------------------------------------------------------------------------------------------


#------------------------------------------------------------------------------------------
    def sqliteVersao():
        '''Versão do sqlite.
        '''
       
        try: 
            con = lite.connect('test.db')
            cur = con.cursor()
            cur.execute('SELECT SQLITE_VERSION()')
            data = cur.fetchone()
            print ('Versão do SQLite: %s' % data)
        except (lite.Error, e):
            print ('Erro %s:' % e.args[0])
            sys.exit(1)
        finally:
            if con:
                con.close()
                print('Fechado com erro.')
        print('Método sqliteVersao.')
#------------------------------------------------------------------------------------------
    def verificaConexao(arkivo):
        '''Verifica conexão do BD.
        '''
        dbfilename = arkivo
        dbis_new = not os.path.exists(dbfilename)

        if dbis_new:
            try:
                con = lite.connect(dbfilename)#cria
                print ('Conexão criada.')
            except (lite.Error, e):
                print('Sai com erro.')
                sys.exit(1)
            finally:
                if con:
                    con.close()
                    print('conexã encerrada.')
            print ('Caminha não econtrado. Foi criado o esquema.')
        else:
            print ('Banco de dados existente e assumido o esquema atual.')
           
        print('Método verificaConexao.')
#------------------------------------------------------------------------------------------


#************************************************************************
if __name__ == '__main__':
    PreSistema()
    print ('Classe instanciada - PreSistemas!')
#************************************************************************
.

sexta-feira, 10 de abril de 2015

código pronto - configurador

.





#*********************************************************************
#
try:
    import tkinter
    from tkinter import ttk
    from tkinter import messagebox
    from tkinter import StringVar
    import time
    print('Instanciado os módulos tkinter no Paginador.')
except ImportError:
    print('Erro na importação dos módulos no Paginador.')
#
#*********************************************************************
vcaminhoimagens = '../bildoj/'
#*********************************************************************
class Paginador():
    def __init__(self):
        self.root = tkinter.Tk()
        self.root.title("Condigurador")
       
        self.style = ttk.Style()
        self.style.configure("BW.TLabel", foreground="black", background="white")
#-----------------------------------------------------------------------------------------------
Código para criar as páginas:
#-----------------------------------------------------------------------------------------------
        self.n = ttk.Notebook(self.root)
        self.pagina0 = ttk.Frame(self.n);
        self.pagina1 = ttk.Frame(self.n);
        self.pagina2 = ttk.Frame(self.n);
        self.pagina3 = ttk.Frame(self.n);
        self.pagina4 = ttk.Frame(self.n);
        self.pagina5 = ttk.Frame(self.n);

        self.n.add(self.pagina0, text='Página 1')
        self.n.add(self.pagina2, text='Página 2')
        self.n.add(self.pagina3, text='Página 3')
        self.n.add(self.pagina4, text='Página 4')
        self.n.add(self.pagina5, text='Página 5')
        self.n.pack()
#-----------------------------------------------------------------------------------------------
Código para particionar a página em linhas e colunas:
#-----------------------------------------------------------------------------------------------
        self.paginapessoa.columnconfigure(0, weight=3)
        self.paginapessoa.columnconfigure(1, weight=3)
        self.paginapessoa.columnconfigure(2, weight=3)
        self.paginapessoa.columnconfigure(3, weight=3)
        self.paginapessoa.columnconfigure(4, weight=3)
        self.paginapessoa.columnconfigure(5, weight=3)
        self.paginapessoa.columnconfigure(6, weight=3)
       
        self.paginapessoa.rowconfigure(0, weight=3)
        self.paginapessoa.rowconfigure(1, weight=3)
        self.paginapessoa.rowconfigure(2, weight=3)
        self.paginapessoa.rowconfigure(3, weight=3)
        self.paginapessoa.rowconfigure(4, weight=3)
        self.paginapessoa.rowconfigure(5, weight=3)
        self.paginapessoa.rowconfigure(6, weight=3)
#-----------------------------------------------------------------------------------------------
Código que posiciona os objetos na página:
#-----------------------------------------------------------------------------------------------
        self.lbl1.grid(column=0, row=0)
        self.entra1.grid(column=0, row=1)
        self.lbl2.grid(column=0, row=2)
        self.entra2.grid(column=0, row=3)
         
        self.opc3.grid(column=4, row=0)
        self.opc1.grid(column=4, row=1)
        self.opc2.grid(column=5, row=1)
        self.opc3.grid(column=4, row=2)
        self.opc4.grid(column=5, row=2)

        self.lbl4.grid(column=4, row=3)
        self.opc5.grid(column=4, row=4)
        self.opc6.grid(column=5, row=4)
        self.opc7.grid(column=4, row=5)
        self.opc8.grid(column=5, row=5)
      
        self.bt1.grid(column=0, row=5)
#-----------------------------------------------------------------------------------------------
Código que cria os objetos:
#-----------------------------------------------------------------------------------------------
        self.ventra1 = tkinter.StringVar()
        self.ventra1.set('sem nome')
        self.ventra2 = tkinter.StringVar()
        self.ventra2.set('sem senha')
       
        self.vlbl1 = tkinter.StringVar()
        self.vlbl1.set('Nome')
        self.lbl1 = tkinter.Label(self.pagina1, text="Pessoa x", textvariable=self.vlbl1, bg='yellow')
        self.entra1 = tkinter.Entry(self.pagina1)
        self.entra1.config(textvariable=self.ventra1)
       
        self.vlbl2 = tkinter.StringVar()
        self.vlbl2.set('Senha')
        self.lbl2 = tkinter.Label(self.pagina1, text="Senha", textvariable=self.vlbl2, bg='yellow')
        self.entra2 = tkinter.Entry(self.pagina1, textvariable=self.ventra2, show='*')

        self.bt1 = ttk.Button(self.pagina1, text="Registrar")
        self.bt1.bind("<Button-1>", self._fbt1)
      
        self.v3 = tkinter.StringVar()
        self.v3.set("3")
        self.lbl3 = tkinter.Label(self.pagina1, text="Quantidade", bg='yellow')
        self.opc1 = ttk.Radiobutton(self.pagina1, text='Um', variable=self.vqtdepessoas, value='1', command=self._fopc)
        self.opc2 = ttk.Radiobutton(self.pagina1, text='Dois', variable=self.vqtdepessoas, value='2', command=self._fopc)
        self.opc3 = ttk.Radiobutton(self.pagina1, text='Três', variable=self.v3, value='3', command=self._fopc)
        self.opc4 = ttk.Radiobutton(self.pagina1, text='Quatro', variable=self.v3, value='4', command=self._fopc)

        self.v4 = tkinter.StringVar()
        self.v4.set("opc6")
        self.lbl4 = tkinter.Label(self.pagina1, text="Opções", bg='yellow')
        self.opc5 = ttk.Radiobutton(self.pagina1, text='opc 5', variable=self.v4, value='opc5', command=self._opc2)
        self.opc6 = ttk.Radiobutton(self.pagina1, text='opc 6', variable=self.v4, value='opc6', command=self._opc2)
        self.opc7 = ttk.Radiobutton(self.pagina1, text='opc 7', variable=self.v4, value='opc7', command=self._opc2)
        self.opc8 = ttk.Radiobutton(self.pagina1, text='opc 8', variable=self.v4, value='opc8', command=self._opc2)
#-----------------------------------------------------------------------------------------------

#-----------------------------------------------------------------------------------------------

#************************************************************************
if __name__ == '__main__':
    Configurador()
    print ('Classe instanciada - Configurador!')
#************************************************************************
.