from
os
import
getcwd as osGetcwd
from
sys
import
exit as sysExit
from
PyQt5.QtCore
import
QRegExp, Qt
from
PyQt5.QtGui
import
QRegExpValidator
from
PyQt5.QtWidgets
import
QApplication, QMainWindow, QWidget, QDockWidget
from
PyQt5.QtWidgets
import
QHBoxLayout, QVBoxLayout, QGridLayout, QGroupBox, QLabel
from
PyQt5.QtWidgets
import
QLineEdit, QPushButton, QAction, QStyleFactory
class
MenuToolBar(QDockWidget):
def
__init__(
self
, parent):
QDockWidget.__init__(
self
)
self
.Parent
=
parent
self
.MainMenu
=
parent.menuBar()
self
.MenuActRef
=
{
'HelloAct'
:
0
,
'ResetAct'
:
0
}
self
.WorldMenu
=
self
.MainMenu.addMenu(
'World'
)
self
.HelloAct
=
QAction(
'&Hello'
,
self
)
self
.HelloAct.setShortcut(
"Ctrl+H"
)
self
.HelloAct.setStatusTip(
'Say Hello to the World'
)
self
.HelloAct.triggered.connect(
self
.SayHello)
self
.MenuActRef[
'HelloAct'
]
=
self
.HelloAct
self
.ResetAct
=
QAction(
'&Reset'
,
self
)
self
.ResetAct.setShortcut(
"Ctrl+H"
)
self
.ResetAct.setStatusTip(
'Reset the Dialog'
)
self
.ResetAct.triggered.connect(
self
.ResetWorld)
self
.MenuActRef[
'ResetAct'
]
=
self
.ResetAct
self
.OkayAct
=
QAction(
'&Okay'
,
self
)
self
.OkayAct.setShortcut(
"Ctrl+O"
)
self
.OkayAct.setStatusTip(
'Okay?'
)
self
.OkayAct.triggered.connect(
self
.ItsOkay)
self
.MenuActRef[
'OkayAct'
]
=
self
.OkayAct
self
.WorldMenu.addAction(
self
.HelloAct)
self
.WorldMenu.addSeparator()
self
.WorldMenu.addAction(
self
.ResetAct)
self
.WorldMenu.addSeparator()
self
.WorldMenu.addAction(
self
.OkayAct)
self
.InitToolBar()
def
InitToolBar(
self
):
pass
def
SayHello(
self
):
self
.Parent.MenuSubmit()
def
ResetWorld(
self
):
self
.Parent.MenuReset()
def
ItsOkay(
self
):
self
.Parent.MenuOkay()
class
CenterPanel(QWidget):
def
__init__(
self
, parent):
QWidget.__init__(
self
)
self
.Parent
=
parent
self
.NumRegex
=
QRegExp(
"[0-9._]+"
)
self
.Validatr
=
QRegExpValidator(
self
.NumRegex)
self
.lblName
=
QLabel()
self
.lblName.setText(
'Name'
)
self
.lblNamTyp
=
QLabel()
self
.lblNamTyp.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
self
.lblNamTyp.setText(
'[-]'
)
self
.txtName
=
QLineEdit()
self
.lblWeight
=
QLabel()
self
.lblWeight.setText(
'Weight'
)
self
.lblWgtTyp
=
QLabel()
self
.lblWgtTyp.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
self
.lblWgtTyp.setText(
'[kg]'
)
self
.txtWeight
=
QLineEdit()
self
.txtWeight.setValidator(
self
.Validatr)
self
.lblYear
=
QLabel()
self
.lblYear.setText(
'Year'
)
self
.lblYrTyp
=
QLabel()
self
.lblYrTyp.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
self
.lblYrTyp.setText(
'[-]'
)
self
.txtYear
=
QLineEdit()
self
.txtYear.setInputMethodHints(Qt.ImhDigitsOnly)
self
.lblPlace
=
QLabel()
self
.lblPlace.setText(
'Place'
)
self
.lblPlcTyp
=
QLabel()
self
.lblPlcTyp.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
self
.lblPlcTyp.setText(
'[-]'
)
self
.txtPlace
=
QLineEdit()
self
.txtPlace.setInputMethodHints(Qt.ImhDigitsOnly)
self
.txtPlace.setReadOnly(
True
)
grdTest
=
QGridLayout()
grdTest.addWidget(
self
.lblName,
0
,
0
)
grdTest.addWidget(QLabel(
' '
),
0
,
1
)
grdTest.addWidget(
self
.lblNamTyp,
0
,
2
)
grdTest.addWidget(
self
.txtName,
0
,
3
)
grdTest.addWidget(
self
.lblWeight,
1
,
0
)
grdTest.addWidget(QLabel(
' '
),
1
,
1
)
grdTest.addWidget(
self
.lblWgtTyp,
1
,
2
)
grdTest.addWidget(
self
.txtWeight,
1
,
3
)
grdTest.addWidget(
self
.lblYear,
2
,
0
)
grdTest.addWidget(QLabel(
' '
),
2
,
1
)
grdTest.addWidget(
self
.lblYrTyp,
2
,
2
)
grdTest.addWidget(
self
.txtYear,
2
,
3
)
grdTest.addWidget(
self
.lblPlace,
3
,
0
)
grdTest.addWidget(QLabel(
' '
),
3
,
1
)
grdTest.addWidget(
self
.lblPlcTyp,
3
,
2
)
grdTest.addWidget(
self
.txtPlace,
3
,
3
)
gbxTest
=
QGroupBox()
gbxTest.setTitle(
'Test'
)
gbxTest.setLayout(grdTest)
self
.lblHidden
=
QLabel('')
self
.HideSet
=
False
self
.btnAddNew
=
QPushButton()
self
.btnAddNew.setText(
'Add New'
)
self
.btnAddNew.clicked.connect(
self
.ClearValues)
hbxAddNew
=
QHBoxLayout()
hbxAddNew.addWidget(
self
.lblHidden)
hbxAddNew.addStretch(
2
)
hbxAddNew.addWidget(
self
.btnAddNew)
vbxAll
=
QVBoxLayout()
vbxAll.addWidget(gbxTest)
vbxAll.addLayout(hbxAddNew)
gbxDetails
=
QGroupBox()
gbxDetails.setTitle(
'Details'
)
gbxDetails.setLayout(vbxAll)
hbxFinal
=
QHBoxLayout()
hbxFinal.addWidget(gbxDetails)
self
.setLayout(hbxFinal)
def
HandleSubmit(
self
):
if
self
.HideSet:
self
.HideSet
=
False
self
.lblHidden.setText('')
else
:
self
.HideSet
=
True
self
.lblHidden.setText(
'Menu Submit'
)
def
ClearValues(
self
):
pass
class
MainWindow(QMainWindow):
def
__init__(
self
):
super
(MainWindow,
self
).__init__()
self
.setWindowTitle(
'Main'
)
self
.CurntDir
=
osGetcwd()
WinLeft
=
150
; WinTop
=
150
; WinWidth
=
340
; WinHight
=
220
self
.setGeometry(WinLeft, WinTop, WinWidth, WinHight)
self
.CenterPane
=
CenterPanel(
self
)
self
.setCentralWidget(
self
.CenterPane)
self
.MenuBar
=
MenuToolBar(
self
)
self
.SetStatusBar(
self
)
self
.setStyle(QStyleFactory.create(
'Cleanlooks'
))
def
SetStatusBar(
self
, parent):
StatusMsg
=
''
parent.StatBar
=
parent.statusBar()
if
len
(StatusMsg) <
1
:
StatusMsg
=
'Ready'
parent.StatBar.showMessage(StatusMsg)
def
MenuSubmit(
self
):
self
.CenterPane.HandleSubmit()
def
MenuReset(
self
):
self
.StatBar.showMessage(
'Main Menu Reset Action'
)
def
MenuOkay(
self
):
pass
if
__name__
=
=
"__main__"
:
MainThred
=
QApplication([])
MainGui
=
MainWindow()
MainGui.show()
sysExit(MainThred.exec_())