Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #imports:
- import os
- import platform
- import sys
- from PyQt4 import QtCore, QtGui
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- from newchilddlg import NewChildDlg
- #version:
- __version__ = "1.0.0"
- class MainWindow(QtGui.QMainWindow):
- COLUMNS = (
- 'am', 'courtdate', 'board_number', 'namesurname', 'fathersname',
- 'mothersname', 'birthday', 'placeofbirth', 'nationality', 'address',
- 'tel', 'job', 'praxis', 'dayofdoing', 'placeofdoing'
- )
- def __init__(self, parent=None):
- super(MainWindow, self).__init__(parent)
- #Window size:
- self.resize(800,600)
- self.centralwidget = QtGui.QWidget(self)
- self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
- #Table Widget:
- self.tableWidget = QtGui.QTableWidget(self.centralwidget)
- self.vBar = self.tableWidget.verticalScrollBar()
- self._vBar_lastVal = self.vBar.value()
- self.horizontalLayout.addWidget(self.tableWidget)
- self.vBar.valueChanged.connect(self.scrollbarChanged)
- self.tableWidget.setGridStyle(QtCore.Qt.SolidLine)
- self.tableWidget.setRowCount(100)
- self.tableWidget.setColumnCount(15)
- for i in xrange(15):
- item = QtGui.QTableWidgetItem()
- self.tableWidget.setHorizontalHeaderItem(i, item)
- self.tableWidget.horizontalHeader().setDefaultSectionSize(140)
- self.tableWidget.horizontalHeader().setHighlightSections(True)
- self.tableWidget.horizontalHeader().setStretchLastSection(False)
- self.tableWidget.verticalHeader().setDefaultSectionSize(30)
- self.tableWidget.verticalHeader().setStretchLastSection(False)
- self.horizontalLayout.addWidget(self.tableWidget)
- self.setCentralWidget(self.centralwidget)
- #Window Title:
- self.setWindowTitle(self.tr("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
- self.tableWidget.setSortingEnabled(False)
- #Collumns'names:
- item = self.tableWidget.horizontalHeaderItem(0)
- item.setText(self.tr("MainWindow", "Α.Μ.", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(1)
- item.setText(self.tr("MainWindow", "Ημερομηνία Δικάσιμου", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(2)
- item.setText(self.tr("MainWindow", "Αριθμός Πινακίου", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(3)
- item.setText(self.tr("MainWindow", "Ονοματεπώνυμο", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(4)
- item.setText(self.tr("MainWindow", "Όνομα Πατρός", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(5)
- item.setText(self.tr("MainWindow", "Όνομα Μητρός", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(6)
- item.setText(self.tr("MainWindow", "Ημερομηνία Γέννησης", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(7)
- item.setText(self.tr("MainWindow", "Τόπος Γέννησης", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(8)
- item.setText(self.tr("MainWindow", "Εθνικότητα", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(9)
- item.setText(self.tr("MainWindow", "Διεύθυνση Κατοικίας", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(10)
- item.setText(self.tr("MainWindow", "Τηλέφωνο", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(11)
- item.setText(self.tr("MainWindow", "Επάγγελμα-Ιδιότητα", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(12)
- item.setText(self.tr("MainWindow", "Πράξη", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(13)
- item.setText(self.tr("MainWindow", "Ημερομηνία Τέλεσης", None, QtGui.QApplication.UnicodeUTF8))
- item = self.tableWidget.horizontalHeaderItem(14)
- item.setText(self.tr("MainWindow", "Τόπος Τέλεσης", None, QtGui.QApplication.UnicodeUTF8))
- #menubar:
- self.menubar = QtGui.QMenuBar(self)
- self.menubar.setEnabled(True)
- self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
- self.menuFile = self.menubar.addMenu("&File")
- self.menuFile.setSizeIncrement(QtCore.QSize(0, 0))
- self.menuEdit = self.menubar.addMenu("&Edit")
- self.setMenuBar(self.menubar)
- self.menuFile.setTitle(self.tr("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
- self.menuEdit.setTitle(self.tr("MainWindow", "Edit", None, QtGui.QApplication.UnicodeUTF8))
- #Creating Action filenewchild:
- self.filenewchild = self.createAction("&Εισαγωγή Ανηλίκου", self.doupdate, "Ctrl+C", "" ,"Εισαγωγή Δεδομέων Ανηλίκου")
- self.menuFile.addAction(self.filenewchild)
- self.filenewchild.setText(self.tr("MainWindow", "Εισαγωγή Ανηλίκου", None, QtGui.QApplication.UnicodeUTF8))
- # initialize the data structure
- self.children = dict(
- am = [],
- courtdate = [],
- board_number = [],
- namesurname = [],
- fathersname = [],
- mothersname = [],
- birthday = [],
- placeofbirth = [],
- nationality = [],
- address = [],
- tel = [],
- job = [],
- praxis = [],
- dayofdoing = [],
- placeofdoing = [],
- )
- #Adding objects from lists to the Table Widget:
- self.updatetable()
- # Growing rows while scrolling down....
- def scrollbarChanged(self, val):
- bar = self.vBar
- minVal, maxVal = bar.minimum(), bar.maximum()
- avg = (minVal+maxVal)/2
- rowCount = self.tableWidget.rowCount()
- if val > self._vBar_lastVal and val >= avg:
- self.tableWidget.insertRow(rowCount)
- elif val < self._vBar_lastVal:
- lastRow = rowCount-30
- empty = True
- for col in xrange(self.tableWidget.columnCount()):
- item = self.tableWidget.item(lastRow, col)
- if item and item.text():
- empty=False
- break
- if empty:
- self.tableWidget.removeRow(lastRow)
- self._vBar_lastVal = val
- #A function to help us create Actions faster:
- def createAction(self,text, slot=None, shortcut=None, icon=None,
- tip=None, checkable=False, signal="triggered()"):
- action = QAction(text, self)
- if icon is not None:
- action.setIcon(QIcon(":/%s.png" % icon))
- if shortcut is not None:
- action.setShortcut(shortcut)
- if tip is not None:
- action.setToolTip(tip)
- if slot is not None:
- self.connect(action, SIGNAL(signal), slot)
- if checkable:
- action.setCheckable(True)
- return action
- #A function that updates the table:
- def updatetable(self):
- self.tableWidget.clear()
- for col, col_name in enumerate(self.COLUMNS):
- col_object = self.children[col_name]
- for row, value in enumerate(col_object):
- newItem = QtGui.QTableWidgetItem(value)
- self.tableWidget.setItem(row, col, newItem)
- #Handles NewChildDlg actions:
- def doupdate(self):
- d = NewChildDlg(self)
- if d.exec_():
- text = d.lineEdit.text()
- self.am.append(text)
- self.updatetable()
- #Main loop:
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- myapp = MainWindow()
- myapp.show()
- sys.exit(app.exec_())
Add Comment
Please, Sign In to add comment