Skip to content
Snippets Groups Projects
Commit 03cb39f1 authored by Garrett Bates's avatar Garrett Bates
Browse files

Added calendar dialog with display for day of year; integrated into menubar for main window.

parent e40316b0
No related branches found
No related tags found
1 merge request!3Main UI and miscellaneous associated widgets
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'calendar.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class Ui_CalendarDialog(object):
def setupUi(self, Dialog):
if not Dialog.objectName():
Dialog.setObjectName(u"Dialog")
Dialog.resize(400, 300)
self.verticalLayout = QVBoxLayout(Dialog)
self.verticalLayout.setObjectName(u"verticalLayout")
self.calendarWidget = QCalendarWidget(Dialog)
self.calendarWidget.setObjectName(u"calendarWidget")
self.verticalLayout.addWidget(self.calendarWidget)
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.label = QLabel(Dialog)
self.label.setObjectName(u"label")
self.horizontalLayout.addWidget(self.label)
self.julianDateLineEdit = QLineEdit(Dialog)
self.julianDateLineEdit.setObjectName(u"julianDateLineEdit")
self.julianDateLineEdit.setReadOnly(True)
self.horizontalLayout.addWidget(self.julianDateLineEdit)
self.buttonBox = QDialogButtonBox(Dialog)
self.buttonBox.setObjectName(u"buttonBox")
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
self.horizontalLayout.addWidget(self.buttonBox)
self.verticalLayout.addLayout(self.horizontalLayout)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QMetaObject.connectSlotsByName(Dialog)
# setupUi
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Calendar", None))
self.label.setText(QCoreApplication.translate("Dialog", u"Julian Date:", None))
# retranslateUi
import sys
import pathlib
from PySide2 import QtCore, QtGui, QtWidgets
from calendar_ui import Ui_CalendarDialog
class CalendarDialog(QtWidgets.QDialog, Ui_CalendarDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
# Connect the "clicked" signal from the QCalendar to our
# custom slot
self.calendarWidget.clicked.connect(self.onDatePicked)
@QtCore.Slot(QtCore.QDate)
def onDatePicked(self, date):
# This slot retrieves the day of year format from the
# date that the user clicked on in the calendar,
# and sends it to the read-only line edit in the same widget
# If the original functionality of the Calendar is required
# or preferred, I will replace this with a subclass or completely
# custom calendar widget in the near future.
doy = date.dayOfYear()
self.julianDateLineEdit.setText(str(doy))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
wnd = CalendarDialog()
wnd.show()
sys.exit(app.exec_())
...@@ -3,6 +3,7 @@ import sys ...@@ -3,6 +3,7 @@ import sys
import pathlib import pathlib
from PySide2 import QtCore, QtGui, QtWidgets from PySide2 import QtCore, QtGui, QtWidgets
from main_ui import Ui_MainWindow from main_ui import Ui_MainWindow
from calendardialog import CalendarDialog
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
""" """
...@@ -20,6 +21,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): ...@@ -20,6 +21,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
cwd = os.path.dirname(pathlib.Path().absolute()) cwd = os.path.dirname(pathlib.Path().absolute())
self.currentDirectoryChanged.emit(cwd) self.currentDirectoryChanged.emit(cwd)
self.action_Calendar.triggered.connect(self.open_calendar)
@QtCore.Slot() @QtCore.Slot()
def readSelectedFile(self): def readSelectedFile(self):
print('Reading currently selected file.') print('Reading currently selected file.')
...@@ -46,6 +49,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): ...@@ -46,6 +49,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
currentDirectoryChanged = QtCore.Signal(str) currentDirectoryChanged = QtCore.Signal(str)
@QtCore.Slot()
def open_calendar(self):
calendar = CalendarDialog(self)
calendar.show()
if __name__ == '__main__': if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Calendar</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCalendarWidget" name="calendarWidget"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Julian Date:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="julianDateLineEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>391</x>
<y>291</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>391</x>
<y>291</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment