class SideBar(QWidget): def __init__(self, parent=None): super(SideBar, self).__init__(parent) self.initModule() self.setModule() def initModule(self): self.newBtn = Button() self.setBtn = Button() self.dataBtn = Button() self.aboutBtn = Button() self.layout = QVBoxLayout() self.layout.addWidget(self.newBtn, 1, Qt.AlignCenter) self.layout.addWidget(self.setBtn, 1, Qt.AlignCenter) self.layout.addWidget(self.dataBtn, 1, Qt.AlignCenter) self.layout.addWidget(self.aboutBtn, 1, Qt.AlignCenter) self.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(20) self.setLayout(self.layout) def setModule(self): self.newBtn.setMinimumSize(30, 30) self.newBtn.setMaximumSize(30, 30) self.setBtn.setMinimumSize(30, 30) self.setBtn.setMaximumSize(30, 30) self.dataBtn.setMinimumSize(30, 30) self.dataBtn.setMaximumSize(30, 30) self.aboutBtn.setMinimumSize(30, 30) self.aboutBtn.setMaximumSize(30, 30) self.newBtn.setStyleSheet(css.sidebar_new) self.setBtn.setStyleSheet(css.sidebar_set) self.dataBtn.setStyleSheet(css.sidebar_data) self.aboutBtn.setStyleSheet(css.sidebar_about)
class AboutMemo(QWidget): def __init__(self, parent=None): super(AboutMemo, self).__init__(parent) self.initModule() self.setModule() self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) self.move(QPoint(0, 0)) self.btn.clicked.connect(self.hide) def initModule(self): self.setWindowTitle(u'关于') self.setWindowIcon(QIcon(css.AppIconPath)) self.layout = QVBoxLayout() self.label1 = QLabel() self.label2 = QLabel() self.btn = Button() self.layout.addWidget(self.label1, 2, Qt.AlignCenter) self.layout.addSpacing(6) self.layout.addWidget(self.label2, 2, Qt.AlignCenter) self.layout.addSpacing(3) self.layout.addWidget(self.btn, 2, Qt.AlignCenter) self.setLayout(self.layout) def setModule(self): self.label1.setMinimumWidth(800) self.label1.setMaximumWidth(800) self.label1.setWordWrap(True) self.label1.setText(css.about) self.label1.setTextInteractionFlags(Qt.TextSelectableByMouse) self.label1.setOpenExternalLinks(True) self.label1.setStyleSheet(css.aboutmemo_label) self.label2.setMinimumWidth(800) self.label2.setMaximumWidth(800) self.label2.setText(css.about_website) self.label2.setOpenExternalLinks(True) self.label2.setStyleSheet(css.aboutmemo_label) self.btn.setMinimumSize(45, 45) self.btn.setMaximumSize(45, 45) self.btn.setStyleSheet(css.aboutmemo_btn)
class MainPage(QWidget): def __init__(self, parent=None): super(MainPage, self).__init__(parent) self.initModule() self.setModule() def initModule(self): #create widget self.homeBtn = Button() self.homeLabel = QLabel() self.layout = QVBoxLayout() #add to layout self.layout.addWidget(self.homeBtn, 1, Qt.AlignCenter) self.layout.addWidget(self.homeLabel, 1, Qt.AlignCenter) self.setContentsMargins(0, 0, 0, 0) self.setLayout(self.layout) def setModule(self): self.setContentsMargins(0, 0, 0, 0) #set widgets's size self.homeLabel.setMinimumSize(75, 75) self.homeLabel.setMaximumSize(75, 75) self.homeBtn.setMinimumSize(37, 45) self.homeBtn.setMaximumSize(37, 45) #set style self.homeBtn.setStyleSheet(css.mainpage_btn) self.normalIcon() def delatingIcon(self): self.homeLabel.setStyleSheet(css.mainpage_label_chg) def normalIcon(self): self.homeLabel.setStyleSheet(css.mainpage_label) def getTrashPos(self): return self.homeLabel
class Memo(QWidget): def __init__(self, parent=None, data=None): super(Memo, self).__init__(parent) self.initData(parent) self.initModule(data) self.setModule(data) # data self.loadInfo(data) #button self.doneBtn.clicked.connect(self.done) self.labelEdit.sureBtn.clicked.connect(self.save) def initData(self, parent): self.pw = parent self.data = parent.data def initModule(self, data): self.layout = QHBoxLayout() self.label = Label(data) self.labelEdit = Edit(self) self.labelEdit.hide() self.doneBtn = Button() self.layout.addWidget(self.label, 1, Qt.AlignLeft) self.layout.addSpacing(10) self.layout.addWidget(self.labelEdit, 1, Qt.AlignLeft) self.layout.addWidget(self.doneBtn, 1, Qt.AlignLeft) self.layout.setContentsMargins(1, 10, 1, 10) self.layout.setSpacing(1) self.setLayout(self.layout) def setModule(self, data): self.setMinimumWidth(400) #set size self.label.setMargin(2) self.label.setWordWrap(True) #auto newline self.label.setMinimumWidth(340) self.label.setMaximumWidth(340) self.label.setMinimumHeight(50) self.labelEdit.setMinimumHeight(50) self.labelEdit.setMaximumHeight(50) self.doneBtn.setMinimumSize(45, 45) self.doneBtn.setMaximumSize(45, 45) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) # set style self.doneBtn.setStyleSheet(css.memo_btn_no) self.no = True self.label.setStyleSheet( css.memo_label.replace('fc', data['font_color']).replace( 'bgc', data['background_color'])) def loadInfo(self, data): self.id = data['id'] if 'content' in data: content = data['content'] else: content = 'It is empty!' self.label.setText(content) self.labelEdit.setText(content) if data['font_bold'] == 'Bold': font = QFont(data['font'], data['font_size'], QFont.Bold) else: font = QFont(data['font'], data['font_size'], 50) self.label.setFont(font) def done(self): if self.no: self.doneBtn.setStyleSheet(css.memo_btn_yes) self.no = False else: self.doneBtn.setStyleSheet(css.memo_btn_no) self.no = True def save(self): txt = self.labelEdit.document() self.label.setText(txt.toPlainText()) self.label.show() self.doneBtn.show() self.labelEdit.hide() self.saveData(txt.toPlainText()) def saveData(self, data): self.data['memo_data'][self.id - 1]['content'] = data write(self.data) def deleteData(self, data): self.data['memo_data'].pop(data - 1) self.data['memo_num'] -= 1 write(self.data) def keyPressEvent(self, QKeyEvent): if QKeyEvent.key() == 0x01000004: self.save() # elif QKeyEvent.key() == 0x60: # print(2) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.moveFlag = True self.positon = event.globalPos() - self.pos() def mouseMoveEvent(self, event): self.move(event.globalPos() - self.positon) can = self.pw.getTrashPos() flag = self.Collide(can, self) if flag and self.moveFlag: self.deleteMemo(True) else: self.deleteMemo(False) def mouseReleaseEvent(self, event): can = self.pw.getTrashPos() flag = self.Collide(can, self) if flag and self.moveFlag: self.deleteMemo(False) self.moveFlag = False self.hide() self.deleteData(self.id) else: self.hide() self.show() def mouseDoubleClickEvent(self, QMouseEvent): if QMouseEvent.button() == Qt.LeftButton: self.label.hide() self.doneBtn.hide() self.labelEdit.show() self.grabKeyboard() def Collide(self, widgetp, widgetc): dict1 = {} dict1['size'] = widgetp.size() dict1['pos'] = widgetp.pos() dict2 = {} dict2['size'] = widgetc.size() dict2['pos'] = widgetc.pos() pTopLeftX = dict1['pos'].x() pTopLeftY = dict1['pos'].y() pBottomRightX = dict1['pos'].x() + dict1['size'].width() pBottomRightY = dict1['pos'].y() + dict1['size'].height() childX = dict2['pos'].x() childY = dict2['pos'].y() if childX < pBottomRightX and childX > pTopLeftX and childY < pBottomRightY and childY > pTopLeftY: return True else: return False def deleteMemo(self, flag): if flag: self.pw.mainpage.delatingIcon() else: self.pw.mainpage.normalIcon() def editFinish(self): self.EditFinish.emit() def editing(self): self.Editing.emit()
class MainPage(QWidget): def __init__(self, parent=None): super(MainPage, self).__init__(parent) self.parent = parent self.initModule() self.setModule() def initModule(self): #create widget self.homeBtn = Button() self.homeLabel = QLabel() self.layout = QVBoxLayout() #add to layout self.layout.addWidget(self.homeBtn, 1, Qt.AlignCenter) self.layout.addWidget(self.homeLabel, 1, Qt.AlignCenter) self.setContentsMargins(0,0,0,0) self.setLayout(self.layout) self.setContextMenuPolicy(Qt.DefaultContextMenu) self.skinDialog() def setModule(self): self.setContentsMargins(0,0,0,0) #set widgets's size self.homeLabel.setMinimumSize(75,75) self.homeLabel.setMaximumSize(75,75) self.homeBtn.setMinimumSize(37,45) self.homeBtn.setMaximumSize(37,45) #set style self.homeBtn.setStyleSheet(css.mainpage_btn) self.normalIcon() def delatingIcon(self): self.homeLabel.setStyleSheet(css.mainpage_label_chg) def normalIcon(self): self.homeLabel.setStyleSheet(css.mainpage_label) def getTrashPos(self): return self.homeLabel def restartMemo(self): qApp.exit(888) def contextMenuEvent(self, QContextMenuEvent): self.menu = QMenu() self.hideAction = QAction(u'隐藏', self) self.hideAction.triggered.connect(self.homeLabel.hide) self.skinAction = QAction(u'一键换肤', self) self.skinAction.triggered.connect(self.skinChange) self.restartAction = QAction(u'重启', self) self.restartAction.triggered.connect(self.restartMemo) self.trayAction = QAction(u'最小化', self) self.trayAction.triggered.connect(self.parent.hide) self.quitAction = QAction(u"退出", self) self.quitAction.triggered.connect(qApp.quit) self.menu.addAction(self.hideAction) self.menu.addAction(self.skinAction) self.menu.addAction(self.restartAction) self.menu.addAction(self.trayAction) self.menu.addAction(self.quitAction) self.menu.exec_(QCursor.pos()) self.menu.show() def skinDialog(self): self.skin = QDialog() self.skin.setWindowTitle('一键换肤简单版') self.skin.setWindowIcon(QIcon(css.AppIconPath)) self.skin.setWindowFlags(Qt.WindowStaysOnTopHint) self.skin.resize(300,200) self.path = QLineEdit() self.selBtn = Button('选取图片') self.combobox = QComboBox() self.sureBtn = Button('一键更换') self.aboutlabel = QLabel('换肤前建议将img文件夹备份,换肤后文件直接覆盖无法复原。。懒得整复原程序了。。') self.skinl = QVBoxLayout() self.skinl.addWidget(self.path) self.skinl.addWidget(self.selBtn) self.skinl.addWidget(self.combobox) self.skinl.addWidget(self.sureBtn) self.skinl.addWidget(self.aboutlabel) self.skin.setLayout(self.skinl) self.skin.hide() self.selBtn.clicked.connect(self.openImage) self.sureBtn.clicked.connect(self.skinChangeFinished) self.combobox.addItems(['主图标', '主控按钮', '添加memo按钮', '设置按钮', '数据统计按钮', '关于按钮', '完成按钮', '未完成按钮']) def skinChange(self): self.skin.show() def skinChangeFinished(self): index = self.combobox.currentIndex() fname = '1.png' if index == 0: fname = 'huaji.png' transparent_back(self.pathIn, 'huaji_chg.png') elif index == 1: fname = 'homeBtn.png' transparent_back(self.pathIn, 'homeBtn_chg.png') elif index == 2: fname = 'newBtn.png' elif index == 3: fname = 'setBtn.png' elif index == 4: fname = 'dataBtn.png' elif index == 5: fname = 'aboutBtn.png' elif index == 6: fname = 'yesBtn.png' elif index == 7: fname = 'noBtn.png' transparent_back(self.pathIn, fname) self.restartMemo() def openImage(self): filename, filetype = QFileDialog.getOpenFileName(self, "选取文件", "D:/", "All Files(*);;PNG Files(*.png)") self.path.setText(filename) self.pathIn = filename
class Memo(QWidget): def __init__(self, parent=None, data=None): super(Memo, self).__init__(parent) self.initData(parent) self.initModule(data) self.setModule(data) # data self.loadInfo(data) self.funcLink(parent) def initData(self,parent): self.pw = parent self.data = parent.data date = QDate.currentDate() self.date = date.toString(Qt.ISODate) self.statistics = readStatistics(css.statistics, self.date) def funcLink(self, parent): # button self.doneBtn.clicked.connect(self.done) self.labelEdit.sureBtn.clicked.connect(self.save) parent.showMemo.connect(self.memoDisplay) def initModule(self, data): self.layout = QHBoxLayout() self.label = Label(data) self.labelEdit = Edit(self) self.labelEdit.hide() self.doneBtn = Button() self.layout.addWidget(self.label, 1, Qt.AlignLeft) self.layout.addSpacing(10) self.layout.addWidget(self.labelEdit, 1, Qt.AlignLeft) self.layout.addWidget(self.doneBtn, 1, Qt.AlignLeft) self.layout.setContentsMargins(1, 10, 1, 10) self.layout.setSpacing(1) self.setLayout(self.layout) def setModule(self, data): self.setMinimumWidth(400) #set size self.label.setMargin(2) self.label.setWordWrap(True) #auto newline self.label.setMinimumWidth(340) self.label.setMaximumWidth(340) self.label.setMinimumHeight(50) self.labelEdit.setMinimumHeight(50) self.labelEdit.setMaximumHeight(50) self.doneBtn.setMinimumSize(45, 45) self.doneBtn.setMaximumSize(45, 45) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) # set style self.label.setStyleSheet(css.memo_label.replace('fc', data['font_color']).replace('bgc', data['background_color'])) def loadInfo(self, data): self.id = data['id'] if 'content' in data: content = data['content'] else: content = 'It is empty!' self.label.setText(content) self.labelEdit.setText(content) if 'if_done' in data and data['if_done'] and data['if_done'][-1] == self.date: self.doneBtn.setStyleSheet(css.memo_btn_yes) self.no = False self.updateFinished() else: self.doneBtn.setStyleSheet(css.memo_btn_no) self.no = True self.updateUnfinished() if data['font_bold'] == 'Bold': font = QFont(data['font'], data['font_size'], QFont.Bold) else: font = QFont(data['font'], data['font_size'], 50) self.label.setFont(font) def done(self): if self.no: self.doneBtn.setStyleSheet(css.memo_btn_yes) self.no = False self.doneWrite() else: self.doneBtn.setStyleSheet(css.memo_btn_no) self.no = True self.noWrite() def doneWrite(self): Ymd = self.date.split('-') list = self.data['memo_data'][self.id - 1]['if_done'] if list: if list[-1] != Ymd: self.data['memo_data'][self.id - 1]['if_done'].append(self.date) write(self.data) else: self.data['memo_data'][self.id - 1]['if_done'].append(self.date) write(self.data) self.updateFinished() def noWrite(self): list = self.data['memo_data'][self.id - 1]['if_done'] if list: if list[-1] == self.date: self.data['memo_data'][self.id - 1]['if_done'].pop() write(self.data) self.updateUnfinished() def updateUnfinished(self): if self.date not in self.statistics.keys(): self.statistics[self.date] = {'finished': [], 'unfinished': []} if self.id not in self.statistics[self.date]['unfinished']: self.statistics[self.date]['unfinished'].append(self.id) self.statistics[self.date]['unfinished'].sort() if self.id in self.statistics[self.date]['finished']: self.statistics[self.date]['finished'].remove(self.id) writeStatistics(self.statistics) def updateFinished(self): if self.date not in self.statistics.keys(): self.statistics[self.date] = {'finished': [], 'unfinished': []} if self.id not in self.statistics[self.date]['finished']: self.statistics[self.date]['finished'].append(self.id) self.statistics[self.date]['finished'].sort() if self.id in self.statistics[self.date]['unfinished']: self.statistics[self.date]['unfinished'].remove(self.id) writeStatistics(self.statistics) def updateDeleted(self, data): for key in self.statistics.keys(): if data in self.statistics[key]['finished']: self.statistics[key]['finished'].remove(data) writeStatistics(self.statistics) elif data in self.statistics[key]['unfinished']: self.statistics[key]['unfinished'].remove(data) writeStatistics(self.statistics) def save(self): txt = self.labelEdit.document() self.label.setText(txt.toPlainText()) self.label.show() self.doneBtn.show() self.labelEdit.hide() self.saveData(txt.toPlainText()) def saveData(self, data): self.data['memo_data'][self.id-1]['content'] = data write(self.data) def deleteData(self, data): self.data['memo_data'].pop(data-1) self.data['memo_num'] -= 1 write(self.data) def memoDisplay(self, val): op = QGraphicsOpacityEffect() if val: op.setOpacity(0.9999) self.setGraphicsEffect(op) else: op.setOpacity(0) self.setGraphicsEffect(op) def keyPressEvent(self, QKeyEvent): if QKeyEvent.key() == 0x01000004: self.save() # elif QKeyEvent.key() == 0x60: # print(2) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.moveFlag = True self.positon = event.globalPos() - self.pos() def mouseMoveEvent(self, event): self.move(event.globalPos() - self.positon) can = self.pw.getTrashPos() flag = self.Collide(can, self) if flag and self.moveFlag: self.deleteMemo(True) else: self.deleteMemo(False) def mouseReleaseEvent(self, event): can = self.pw.getTrashPos() flag = self.Collide(can, self) if flag and self.moveFlag: self.deleteMemo(False) self.moveFlag = False self.hide() self.deleteData(self.id) self.updateDeleted(self.id) else: self.hide() self.show() def mouseDoubleClickEvent(self, QMouseEvent): if QMouseEvent.button() == Qt.LeftButton: self.label.hide() self.doneBtn.hide() self.labelEdit.show() self.labelEdit.setFocus() self.grabKeyboard() def Collide(self, widgetp, widgetc): dict1 = {} dict1['size'] = widgetp.size() dict1['pos'] = widgetp.pos() dict2 = {} dict2['size'] = widgetc.size() dict2['pos'] = widgetc.pos() pTopLeftX = dict1['pos'].x() pTopLeftY = dict1['pos'].y() pBottomRightX = dict1['pos'].x() + dict1['size'].width() pBottomRightY = dict1['pos'].y() + dict1['size'].height() childX = dict2['pos'].x() childY = dict2['pos'].y() if childX < pBottomRightX and childX > pTopLeftX and childY < pBottomRightY and childY > pTopLeftY: return True else: return False def deleteMemo(self, flag): if flag: self.pw.mainpage.delatingIcon() else: self.pw.mainpage.normalIcon() def editFinish(self): self.EditFinish.emit() def editing(self): self.Editing.emit()