From d1651421db6ac0850fed8414ec8d107d4173bffa Mon Sep 17 00:00:00 2001 From: liyp Date: Mon, 18 Apr 2022 21:18:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E5=BB=BA=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=9C=80=E8=A6=81=E8=BD=AC?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E7=8E=B0=E5=9C=A8=E6=98=AFunicode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.py | 11 ++++- resource/current.qss | 2 +- utils/CreateToDo.py | 9 ++-- utils/Sync.py | 1 - view/ImportantView.py | 2 + view/MyDayHeadLabel.py | 4 +- view/MyDayView.py | 2 + view/ToDoListItem.py | 7 --- view/ToDoListView.py | 109 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 131 insertions(+), 16 deletions(-) delete mode 100644 view/ToDoListItem.py create mode 100644 view/ToDoListView.py diff --git a/main/main.py b/main/main.py index 9479dc6..5017b73 100644 --- a/main/main.py +++ b/main/main.py @@ -3,8 +3,11 @@ import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt + +from utils.CreateToDo import CreateToDo from utils.QSSLoader import QSSLoader from view.ImportantView import Important +from view.ToDoListView import ToDoList from view.UserLabel import User from view.SelfListWidgetItem import SelfListWidgetItem from view.AddListLabel import AddListAction @@ -51,7 +54,7 @@ class MainWidget(QWidget): layout.addWidget(self.stackedWidget, 6) - self.one_day = SelfListWidgetItem('我的一天', 1, os.getcwd() + '/../images/sun.svg') + self.one_day = SelfListWidgetItem('我的一天', 0, os.getcwd() + '/../images/sun.svg') self.system_listWidget.setCurrentRow(1) # self.one_day.setSelected(True) self.important_item = SelfListWidgetItem('重要', 0, os.getcwd() + '/../images/star.svg') @@ -101,11 +104,15 @@ class MainWidget(QWidget): # 创建新的分组 def CreateNewItem(self): # 创建一个没有名字的item - item = SelfListWidgetItem('新建列表') + new_list = '新建列表' + create_todo = CreateToDo('ToDoList', new_list) + item = SelfListWidgetItem(new_list) item.setTextAlignment(Qt.AlignCenter) # 使得item是可以编辑的. item.setFlags(item.flags() | Qt.ItemIsEditable) self.system_listWidget.addItem(item) + todo_list = ToDoList(new_list) + self.stackedWidget.addWidget(todo_list) # 创建后就可以编辑item,用户自己起名字. # self.system_listWidget.editItem(item) self.system_listWidget.setItemWidget(item, item.widget) diff --git a/resource/current.qss b/resource/current.qss index 2168048..16d6789 100644 --- a/resource/current.qss +++ b/resource/current.qss @@ -214,7 +214,7 @@ QLabel#head_label{ min-height:150px; margin-left: 30px; color:white; - background-color:red; +/* background-color:red;*/ font-weight:bold; } diff --git a/utils/CreateToDo.py b/utils/CreateToDo.py index 0fb17a2..b8a75e5 100644 --- a/utils/CreateToDo.py +++ b/utils/CreateToDo.py @@ -24,7 +24,10 @@ class CreateToDo: uid = str(uuid.uuid4()) config_path = self.get_config_path() todo_list_path = config_path + '/{' + uid + '}' + # if not os.path.exists(todo_list_path): + # os.mkdir(todo_list_path) default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + print(default_time) if item_type == 'ToDoList': try: """ @@ -77,10 +80,10 @@ class CreateToDo: # print(platform.system()) if platform.system() == 'Linux': - print(os.environ['HOME'] + '.config/PyQtToDoList') + # print(os.environ['HOME'] + '/.config/PyQtToDoList') # print(os.path.expandvars('~')) - print(os.path.expandvars('$HOME') + '.config/PyQtToDoList') - return os.path.expandvars('$HOME') + '.config/PyQtToDoList' + # print(os.path.expandvars('$HOME') + '.config/PyQtToDoList') + return os.path.expandvars('$HOME') + '/.config/PyQtToDoList' elif platform.system() == 'Windows': print(os.getcwd() + 'config') return os.getcwd() + 'config' diff --git a/utils/Sync.py b/utils/Sync.py index 94ad787..e1c2697 100644 --- a/utils/Sync.py +++ b/utils/Sync.py @@ -30,7 +30,6 @@ class Sync: def upload_file(self, options): client = Client(options) - # client.execute_request('list') list1 = client.list('/') print(list1) exist = client.check('OpenTodoList') diff --git a/view/ImportantView.py b/view/ImportantView.py index 52cc47d..2ff7178 100644 --- a/view/ImportantView.py +++ b/view/ImportantView.py @@ -22,6 +22,7 @@ class Important(QWidget): head_layout = QHBoxLayout() head_widget = QWidget(self) + head_widget.setStyleSheet('background-color:gray') # todo : # head_widget.setMinimumHeight(175) @@ -48,6 +49,7 @@ class Important(QWidget): # layout.addStretch(0) layout.addWidget(head_widget, 2, Qt.AlignTop) # layout.addSpacing(1) + # layout.addStretch(1) # layout.addStretch(0) layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop) head_label = QLabel("重要") diff --git a/view/MyDayHeadLabel.py b/view/MyDayHeadLabel.py index 4482871..42a6060 100644 --- a/view/MyDayHeadLabel.py +++ b/view/MyDayHeadLabel.py @@ -26,13 +26,13 @@ class HeadLabel(QLabel): # self.title.setObjectName('title') # 设置字体大小 self.font = QFont() - self.font.setPointSize(32) + self.font.setPointSize(26) self.title.setFont(self.font) # todo: 需要调整布局,修复字体间距 # self.title.setObjectName('title') self.time_label = QLabel(str(month) + '月' + str(day) + '日,' + weekday[weekday_index]) - self.time_label.setStyleSheet('color:white;') + self.time_label.setStyleSheet('color:white;margin:0px') # self.time_label.setObjectName('time_label') layout.addWidget(self.title) diff --git a/view/MyDayView.py b/view/MyDayView.py index 9396c92..a542c87 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -30,6 +30,7 @@ class MyDay(QWidget): head_layout = QHBoxLayout() # 头部总布局 head_widget = QWidget(self) + head_widget.setStyleSheet('background-color:gray') # head_widget.setMinimumHeight(175) # head_widget.setMaximumHeight(180) @@ -52,6 +53,7 @@ class MyDay(QWidget): # head_left_layout = QVBoxLayout() layout.addWidget(head_widget, 2, Qt.AlignTop) + # layout.addStretch(1) # layout.addSpacing(1) self.head_label = HeadLabel() diff --git a/view/ToDoListItem.py b/view/ToDoListItem.py deleted file mode 100644 index cb427a3..0000000 --- a/view/ToDoListItem.py +++ /dev/null @@ -1,7 +0,0 @@ -from PyQt5.QtWidgets import * - - -class ToDoListItem(QListWidgetItem): - def __init__(self): - super(ToDoListItem, self).__init__() - self.widget = QWidget() diff --git a/view/ToDoListView.py b/view/ToDoListView.py new file mode 100644 index 0000000..97bf8c4 --- /dev/null +++ b/view/ToDoListView.py @@ -0,0 +1,109 @@ +import os +import sys +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5.QtCore import Qt + +from view.AddToDoLabel import AddToDoAction + + +class ToDoList(QWidget): + def __init__(self, list_name): + super(ToDoList, self).__init__() + self.setObjectName('important') + self.setAttribute(Qt.WA_StyledBackground) + # todo : 使用网格布局设置背景图 + self.setStyleSheet('#important{background-image:url("../images/10.jpg");border-radius: 10px;}') + + # 布局样式:最外面一个大的垂直布局,里面的最上面标题是一个水平布局,水平布局显示的是一个垂直布局和一个右边的选项,用来更换背景 + # 布局样式:继承QWidget,里面一个垂直布局,最上面一个QWidget用来设置头部布局 + # 头部QWidget里面一个水平布局,水平布局里面一个QWidget(方便设置整体位置),然后是一个 + layout = QVBoxLayout() + head_layout = QHBoxLayout() + + head_widget = QWidget(self) + # todo : + # head_widget.setMinimumHeight(175) + + self.todo_list = QListWidget() + self.todo_list.setObjectName('todo_list') + + # todo : 重写QLabel,实现添加功能 + # 添加ToDo的标签 + self.add_todo = AddToDoAction() + self.add_todo.setAlignment(Qt.AlignCenter) + # self.add_todo.setPlaceholderText('添加任务') + + # head_widget.setMaximumHeight(100) + # head_widget. + # head_widget.setObjectName('head_widget') + head_widget.setAttribute(Qt.WA_StyledBackground) + # self.setStyleSheet('#head_widget{margin:50px}') + + # head_widget.setPalette(palette) + + head_widget.setLayout(head_layout) + head_layout.setAlignment(Qt.AlignCenter) + # head_left_layout = QVBoxLayout() + # layout.addStretch(0) + layout.addWidget(head_widget, 2, Qt.AlignTop) + # layout.addSpacing(1) + # layout.addStretch(1) + # layout.addStretch(0) + layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop) + head_label = QLabel(list_name) + head_label.setObjectName('head_label') + font = QFont() + font.setPointSize(32) + head_label.setFont(font) + + layout.addStretch(1) + + head_layout.addWidget(head_label, 8) + layout.addStretch(1) + layout.addWidget(self.add_todo, 2, Qt.AlignHCenter) + + self.menu_image = QPushButton() + self.menu_image.setObjectName('menu_image') + self.menu_image.setFixedSize(30, 30) + # self.menu_image.setScaledContents(True) + pic_btn = QPixmap(os.getcwd() + "/../images/menu.png") + self.menu_image.setIcon(QIcon(pic_btn)) + # self.menu_image.setFixedSize(QPixmap(os.getcwd() + "/../images/menu.png").size()) + # head_layout.addLayout(head_left_layout) + head_layout.addWidget(self.menu_image, 2) + head_layout.addStretch(1) + + self.setLayout(layout) + # self.menu_image.clicked.connect(self.menu_action) + + button_menu = QMenu(self) + # 背景透明 + button_menu.setAttribute(Qt.WA_TranslucentBackground) + # 无边框、去掉自带阴影 + button_menu.setWindowFlags( + button_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint) + + self.menu_image.setMenu(button_menu) + + theme_label = QAction(self) + theme_label.setText('主题') + theme_label.setDisabled(True) + button_menu.addAction(theme_label) + button_menu.addSeparator() + # button_menu + for i in range(11): + label_action = QAction(self) + label_action.setIcon(QIcon('../images/' + str(i) + '.jpg')) + label_action.setText(str(i)) + label_action.triggered.connect(lambda: self.menu_action(str(i))) + button_menu.addAction(label_action) + # todo : 下面的方法实现点击更换主题的功能 + + def menu_action(self, count): + # 点击按钮 + # self.menu_label = ChangeTheme() + self.setStyleSheet('#important{background-image:url("../images/4.jpg");' + 'background-position: center; border-radius: 10px;' + '}') + print('选中:' + count)