1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
import sys, os
import sqlite3
from PyQt5.QtWidgets import (QApplication, QCheckBox, QComboBox, QDateTimeEdit,
QDial, QDialog, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit,
QProgressBar, QPushButton, QRadioButton, QScrollBar, QSizePolicy,
QSlider, QSpinBox, QStyleFactory, QTableWidget, QTabWidget, QTextEdit,
QVBoxLayout, QWidget, QMainWindow, QFrame, QFormLayout, QMessageBox)
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import pyqtSlot, QSettings, QDateTime, Qt, QTimer, QDateTime
from PyQt5 import QtCore, QtGui, QtWidgets, QtSql
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtSql import QSqlDatabase
import logging
from logging.handlers import RotatingFileHandler
class App(QMainWindow):
#===============================================================================================
def __init__(self, parent=None):
super(App, self).__init__(parent)
#--- Application datas ---------------------------------------------------------------------
settings=QSettings('ini/application.ini',QSettings.IniFormat);
global APPLICATION_NAME
APPLICATION_NAME="DEBUG_MODE" #settings.value("GLOBAL_PARAMETERS/APPLICATION_NAME")
self.setFont(QtGui.QFont('Courier new', 10))
self.setWindowIcon(QIcon('ini/graph.ico'))
self.setWindowTitle(APPLICATION_NAME+ " - Design By.")
#--- Logfile -------------------------------------------------------------------------------
if not os.path.isdir('logfile'):
os.mkdir('logfile')
#--- Creation of objet logger which be used to write into logs -----------------------------
self.logger = logging.getLogger()
#--- Level logger at DEBUG, like that he writes all ----------------------------------------
self.logger.setLevel(logging.DEBUG)
#--- Creation of formater which add time,
#--- level of each messsage when we will write a message into logfile. ---------------------
self.formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
#--- Creation of handler which redirect a write of log to a file
#--- in 'append mode' with one backup and a size of 1Mo. -----------------------------------
self.file_handler = RotatingFileHandler('logfile/'+APPLICATION_NAME+'.log', 'a', 1000000, 1)
#--- DEBUG level assigned, logger must used the last formater created previously
#--- and add this handle to logger. --------------------------------------------------------
self.file_handler.setLevel(logging.DEBUG)
self.file_handler.setFormatter(self.formatter)
self.logger.addHandler(self.file_handler)
#--- Creation of a seconf handler which redirect each log write on console. ----------------
self.stream_handler = logging.StreamHandler()
self.stream_handler.setLevel(logging.DEBUG)
self.logger.addHandler(self.stream_handler)
#--- End of logfile parameters -------------------------------------------------------------
self.logger.log(logging.INFO, 'Start of '+APPLICATION_NAME +' by ' +os.getlogin()+'.')
self.initUI()
#===============================================================================================
def initUI(self):
#--- User Interface ------------------------------------------------------------------------
#--- Header --------------------------------------------------------------------------------
#Headband = QPixmap('ini/bandeau.jpg')
#self.bandeau = QLabel(self)
#self.bandeau.setFixedHeight(15)
#self.bandeau.setScaledContents(True)
#self.bandeau.setPixmap(Headband)
#--- QTabWidget creation with x tabwidget --------------------------------------------------
self.tabwidget = QTabWidget(self)
self.tabwidget.addTab(self.tab1(), "Tabwidget 1")
self.tabwidget.addTab(self.tab2(), "Tabwidget 2")
self.tabwidget.addTab(self.tab3(), "Tabwidget 3")
self.tabwidget.addTab(self.tab4(), "Tabwidget 4")
self.setCentralWidget(QFrame())
layout = QGridLayout()
#layout.addWidget(self.bandeau, 0, 0)
layout.addWidget(self.CreateToolInformationFormGroup(), 1, 0)
layout.addWidget(self.tabwidget, 2, 0)
#self.tabwidget.setDisabled(True)
self.centralWidget().setLayout(layout)
#--- Affichage d'un message sur la barre de status -----------------------------------------
self.statusBar().showMessage(os.getlogin()+' is currently connected.')
def CreateToolInformationFormGroup(self):
#--- FormGroup below header ----------------------------------------------------------------
groupBox = QGroupBox("--- QGroupBox ---")
self.label_1 = QLabel()
self.label_1.setText("label_1.setText")
self.toolQRcode = QLineEdit(self)
self.toolQRcode.textChanged.connect(self.to_upper)
self.toolQRcode.setFixedWidth(200)
self.toolQRcode.setMaxLength(8)
self.toolQRcode.returnPressed.connect(self.onPressed)
self.label_ToolInformations = QLabel()
self.label_ToolInformations.setText("")
vbox = QVBoxLayout()
vbox.addWidget(self.label_1)
vbox.addWidget(self.toolQRcode)
vbox.addWidget(self.label_ToolInformations)
#vbox.addStretch(1)
groupBox.setLayout(vbox)
return groupBox
#--- QEditLine in Uppercase --------------------------------------------------------------------
def to_upper(self, txt):
self.toolQRcode.setText(txt.upper())
#--- Function after onPressed QEditLine --------------------------------------------------------
def onPressed(self):
self.label_ToolInformations.setText(self.toolQRcode.text())
#--- Tabwidget 1 -------------------------------------------------------------------------------
def tab1(self):
groupBoxTab1 = QGroupBox("--- Tabwidget 1 ---")
return groupBoxTab1
#--- Tabwidget 2 -------------------------------------------------------------------------------
def tab2(self):
groupBoxTab2 = QGroupBox("--- Tabwidget 2 ---")
return groupBoxTab2
#--- Tabwidget 3 -------------------------------------------------------------------------------
def tab3(self):
groupBoxTab3 = QGroupBox("--- Tabwidget 3 ---")
return groupBoxTab3
#--- Tabwidget 4 -------------------------------------------------------------------------------
def tab4(self):
groupBoxTab4 = QGroupBox("--- Tabwidget 4 ---")
return groupBoxTab4
#--- /!\ --- DO NOT DELETE BELOW --- /!\ -----------------------------------------------------------
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle('Fusion')
ex = App()
ex.showMaximized()
sys.exit(app.exec_()) |
Partager