import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtCore
import getHomeWork
import datetime as dt
class QCustomQWidget(QWidget):
def __init__(self, parent=None):
super(QCustomQWidget, self).__init__(parent)
self.allQVBoxLayout = QVBoxLayout()
self.reportTitleQLabel = QLabel() # レポート名 :
self.timeEndConstQLabel = QLabel("提出期限")
self.timeEndQLabel = QLabel()
self.courseNameQLabel = QLabel()
self.secondQHBoxLayout = QHBoxLayout() # 提出期限 : xx/xx hh:mm | 講座名 : pokepoke
self.secondQHBoxLayout.addWidget(self.timeEndConstQLabel, 0)
self.secondQHBoxLayout.addWidget(self.timeEndQLabel, 1)
self.secondQHBoxLayout.addWidget(self.courseNameQLabel, 2)
self.allQVBoxLayout.addWidget(self.reportTitleQLabel, 0)
self.allQVBoxLayout.addLayout(self.secondQHBoxLayout, 1)
self.setLayout(self.allQVBoxLayout)
# setStyleSheet
self.reportTitleQLabel.setStyleSheet('font-size: 20pt;')
# self.reportNameQLabel.setStyleSheet('''color: rgb(0,255, 0);''')
self.timeEndQLabel.setStyleSheet('font-size: 20pt;')
def set_course_name_text(self, text):
self.courseNameQLabel.setText("講座名 : " + text)
def set_time_end_text(self, text):
self.timeEndQLabel.setText(text)
def set_task_title_text(self, text, task_type: int):
if task_type == 0:
self.reportTitleQLabel.setText("レポート名 : " + text)
else:
self.reportTitleQLabel.setText("テスト名 : " + text)
class exampleQMainWindow(QMainWindow):
def __init__(self, user_email, user_password):
super(exampleQMainWindow, self).__init__()
# Create QListWidget
self.myQListWidget = QListWidget(self)
task_list = getHomeWork.get_task_list(user_email=user_email, user_password=user_password)
# report_list = getHomeWork.get_dummy_report_list(user_email=user_email, user_password=user_password)
task_list.sort(key=lambda each_report:
dt.datetime.strptime(each_report.task_time_end, '%Y/%m/%d %H:%M'))
for task in task_list:
myQCustomQWidget = QCustomQWidget()
myQCustomQWidget.set_course_name_text(task.course_name)
myQCustomQWidget.set_task_title_text(text=task.task_title, task_type=task.task_type)
report_time_end_only_monthandday = task.task_time_end[
task.task_time_end.index("/") + 1:] # 2020/04/21 → 04/21
myQCustomQWidget.set_time_end_text(report_time_end_only_monthandday)
# Create QListWidgetItem
myQListWidgetItem = QListWidgetItem(self.myQListWidget)
# Set size hint
myQListWidgetItem.setSizeHint(myQCustomQWidget.sizeHint())
# Add QListWidgetItem into QListWidget
self.myQListWidget.addItem(myQListWidgetItem)
self.myQListWidget.setItemWidget(myQListWidgetItem, myQCustomQWidget)
self.setCentralWidget(self.myQListWidget)
def main():
app = QApplication(sys.argv)
my_email = ''
my_password = ''
view = exampleQMainWindow(user_email=my_email, user_password=my_password)
view.show()
view.resize(750, 350)
sys.exit(app.exec_())
if __name__ == '__main__':
main()