Как получить текущий DateTime для отображения в моем приложении gui? - PullRequest
0 голосов
/ 09 апреля 2020

Я GUI нуб, пытающийся создать приложение GUI для выполнения базового c преобразования (из координат в шейп-файл). В данный момент я пытаюсь добавить DateTime в интерфейс. У меня есть это как метод (DisplayDateTime) в коде, но он не показывает.

import os, sys

from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout, QLineEdit, QPushButton, QMessageBox, QVBoxLayout 
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtCore import Qt, QTimer, QDateTime

class ConverterWidget(QWidget): 

    def __init__(self): 
        super(ConverterWidget,self).__init__() 

        self.setWindowTitle("Coords2Shp") 
        self.resize(500, 200) 

        self.setWindowIcon(QIcon('pythonlogo.JPG'))  

        self.gridLayout = QGridLayout(self) 

        self.labelCoordinates = QLabel('Enter coordinates here... [( , ), ( , )]: ') 
        self.gridLayout.addWidget(self.labelCoordinates, 0, 0) 

        self.labelEpsgCode = QLabel('Input epsg code: ')
        self.gridLayout.addWidget(self.labelEpsgCode, 1, 0) 

        self.entryCoordinates = QLineEdit() 
        self.gridLayout.addWidget(self.entryCoordinates, 0, 1) 

        self.entryEpsgCode = QLineEdit() 
        self.gridLayout.addWidget(self.entryEpsgCode, 1, 1) 

        self.convertButton = QPushButton('Create shapefile') 
        self.gridLayout.addWidget(self.convertButton, 2, 1) 

        self.convertButton.clicked.connect(self.coords_2_geodf) 
        self.convertButton.clicked.connect(self.on_button_clicked)

        self.gridLayout.addWidget(self.lbl.setText(QDateTime.currentDateTime().toString()), 0, 3)

    def coords_2_geodf(self, coords, epsg_code):
        self.coords_gdf = gpd.GeoDataFrame()
        self.coords_poly = Polygon(self.coords)
        #coords_poly

        self.coords_gdf.loc[0, 'geometry'] = self.coords_poly
        self.coords_gdf.crs = self.from_epsg(epsg_code)
        #coords_gdf.crs


        #coords_gdf.to_file(entryOutputFilePath)
        return self.coords_gdf.plot()


    def on_button_clicked(self):
        self.alert = QMessageBox()
        self.alert.setWindowIcon(QIcon('pythonlogo.JPG'))
        self.alert.setText('Your shapefile has been created!')
        self.alert.exec_()

    def DisplayDateTime(self):
        layout = QVBoxLayout()
        fnt = QFont('Open Sans', 12, QFont.Bold)
        self.lbl = QLabel()
        self.lbl.setAlignment(Qt.AlignRight)
        self.lbl.setFont(fnt)
        layout.addWidget(self.lbl)
        self.setLayout(layout)

        self.timer =QTimer(self)
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.DisplayDateTime)
        self.timer.start() 
        self.lbl.setText(QDateTime.currentDateTime().toString())


    def closeEvent(self, event):
        reply = QMessageBox.question(self, 'Message',
            "Are you sure to quit?", QMessageBox.Yes | 
            QMessageBox.No, QMessageBox.No)

        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()   


app = QApplication([]) 
converter = ConverterWidget() 

converter.show() 
app.exec_() 

Я бы хотел, чтобы текущий DateTime отображался в верхнем правом углу интерфейса. Может кто-нибудь, пожалуйста, помогите мне?

...