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 SettingBar(QDialog): def __init__(self, parent=None): super(SettingBar, self).__init__(parent) # data self.pw = parent self.data = parent.data self.isDesk = False #init self.initModule() self.setModule() self.funcLink() # self.setWindowFlags(Qt.FramelessWindowHint) # self.setAttribute(Qt.WA_TranslucentBackground) def funcLink(self): self.btn1.clicked.connect(self.fontSetting) self.btn2.clicked.connect(self.colorSetting) self.btn3.clicked.connect(self.bgcolorSetting) self.settingBtn.clicked.connect(self.updateSetting) self.isup_checkbox.stateChanged.connect(self.upstateSetting) self.shortcut_checkbox.stateChanged.connect(self.createDeskIcon) self.autohide_checkbox.stateChanged.connect(self.autohideSetting) def initModule(self): self.setWindowTitle(u'设置') self.setWindowIcon(QIcon(css.setBtnPath)) self.layout = QVBoxLayout() self.fontlayout = QHBoxLayout() self.label1 = QLabel(u'字体设置') self.btn1 = Button(u'设置') self.fontlayout.addWidget(self.label1) self.fontlayout.addSpacing(6) self.fontlayout.addWidget(self.btn1) self.colorlayout = QHBoxLayout() self.label2 = QLabel(u'字体颜色') self.btn2 = Button(u'设置') self.colorlayout.addWidget(self.label2) self.colorlayout.addSpacing(6) self.colorlayout.addWidget(self.btn2) self.bgcolorlayout = QHBoxLayout() self.label5 = QLabel(u'背景颜色') self.btn3 = Button(u'设置') self.bgcolorlayout.addWidget(self.label5) self.bgcolorlayout.addSpacing(6) self.bgcolorlayout.addWidget(self.btn3) self.opacitylayout1 = QHBoxLayout() self.label3 = QLabel(u'透明度设置:') self.text1 = QTextEdit(str(self.data['set_data']['label_opacity'])) self.opacitylayout1.addWidget(self.label3) self.opacitylayout1.addWidget(self.text1) self.opacitylayout2 = QHBoxLayout() self.label4 = QLabel(u'触碰透明度:') self.text2 = QTextEdit(str(self.data['set_data']['touch_opacity'])) self.opacitylayout2.addWidget(self.label4) self.opacitylayout2.addWidget(self.text2) self.setuplayout = QGridLayout() self.isup_checkbox = QCheckBox(u'悬浮窗置顶') self.setuplayout.addWidget(self.isup_checkbox, 0, 0) self.shortcut_checkbox = QCheckBox(u'快捷方式') self.setuplayout.addWidget(self.shortcut_checkbox, 0, 1) self.autohide_checkbox = QCheckBox(u'边缘自动隐藏') self.setuplayout.addWidget(self.autohide_checkbox, 1, 0) self.settingBtn = Button(u'重启生效哦!') self.layout.addLayout(self.fontlayout) self.layout.addLayout(self.colorlayout) self.layout.addLayout(self.bgcolorlayout) self.layout.addLayout(self.opacitylayout1) self.layout.addLayout(self.opacitylayout2) self.layout.addLayout(self.setuplayout) self.layout.addWidget(self.settingBtn, 1, Qt.AlignCenter) self.setLayout(self.layout) def setModule(self): self.text1.setMaximumSize(55, 30) self.text2.setMaximumSize(55, 30) self.btn1.setMaximumSize(55, 30) self.btn2.setMaximumSize(55, 30) self.btn3.setMaximumSize(55, 30) self.settingBtn.setStyleSheet(css.restart_btn) #read setting record if self.data['ui_data']['is_up']: self.isup_checkbox.setChecked(True) if self.data['ui_data']['auto_hide']: self.autohide_checkbox.setChecked(True) def updateSetting(self): if self.isDesk: self.createIcon() #opacity set self.data['set_data']['label_opacity'] = float( self.text1.toPlainText()) self.data['set_data']['touch_opacity'] = float( self.text2.toPlainText()) write(self.data) self.close() qApp.exit(888) def createDeskIcon(self): if self.shortcut_checkbox.isChecked(): self.shortcut_checkbox.setChecked(True) self.isDesk = True else: self.shortcut_checkbox.setChecked(False) def createIcon(self): pathExe = sys.executable pathIcon = QStandardPaths.writableLocation( QStandardPaths.DesktopLocation) + "/" + "Memo.lnk" if not os.path.exists(pathIcon): QFile.link(pathExe, pathIcon) def upstateSetting(self): if self.isup_checkbox.isChecked(): self.isup_checkbox.setChecked(True) self.data['ui_data']['is_up'] = True else: self.isup_checkbox.setChecked(False) self.data['ui_data']['is_up'] = False def autohideSetting(self): if self.autohide_checkbox.isChecked(): self.autohide_checkbox.setChecked(True) self.data['ui_data']['auto_hide'] = True else: self.autohide_checkbox.setChecked(False) self.data['ui_data']['auto_hide'] = False def fontSetting(self): font, ok = QFontDialog.getFont() info = font.toString().split(',') # QFont Object => list if ok: self.data['set_data']['font'] = info[0] self.data['set_data']['font_size'] = int(info[1]) self.data['set_data']['font_bold'] = info[10] def colorSetting(self): color = QColorDialog.getColor() if color.isValid(): self.data['set_data']['font_color'] = color.name() def bgcolorSetting(self): color = QColorDialog.getColor() if color.isValid(): self.data['set_data']['background_color'] = color.name()
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 SettingBar(QDialog): def __init__(self, parent=None): super(SettingBar, self).__init__(parent) # data self.pw = parent self.data = parent.data #init self.initModule() self.setModule() self.center() # self.setWindowFlags(Qt.FramelessWindowHint) # self.setAttribute(Qt.WA_TranslucentBackground) self.btn1.clicked.connect(self.fontSetting) self.btn2.clicked.connect(self.colorSetting) self.btn3.clicked.connect(self.bgcolorSetting) self.settingBtn.clicked.connect(self.updateSetting) def initModule(self): self.setWindowTitle(u'设置') self.setWindowIcon(QIcon(css.setBtnPath)) self.layout = QVBoxLayout() self.fontlayout = QHBoxLayout() self.colorlayout = QHBoxLayout() self.bgcolorlayout = QHBoxLayout() self.opacitylayout1 = QHBoxLayout() self.opacitylayout2 = QHBoxLayout() self.label1 = QLabel(u'字体设置') self.btn1 = Button(u'设置') self.fontlayout.addWidget(self.label1) self.fontlayout.addSpacing(6) self.fontlayout.addWidget(self.btn1) self.label2 = QLabel(u'字体颜色') self.btn2 = Button(u'设置') self.colorlayout.addWidget(self.label2) self.colorlayout.addSpacing(6) self.colorlayout.addWidget(self.btn2) self.label5 = QLabel(u'背景颜色') self.btn3 = Button(u'设置') self.bgcolorlayout.addWidget(self.label5) self.bgcolorlayout.addSpacing(6) self.bgcolorlayout.addWidget(self.btn3) self.label3 = QLabel(u'透明度设置:') self.text1 = QTextEdit(str(self.data['set_data']['label_opacity'])) self.opacitylayout1.addWidget(self.label3) self.opacitylayout1.addWidget(self.text1) self.label4 = QLabel(u'触碰透明度:') self.text2 = QTextEdit(str(self.data['set_data']['touch_opacity'])) self.opacitylayout2.addWidget(self.label4) self.opacitylayout2.addWidget(self.text2) self.settingBtn = Button(u'重启生效哦!') self.layout.addLayout(self.fontlayout) self.layout.addLayout(self.colorlayout) self.layout.addLayout(self.bgcolorlayout) self.layout.addLayout(self.opacitylayout1) self.layout.addLayout(self.opacitylayout2) self.layout.addWidget(self.settingBtn, 1, Qt.AlignCenter) self.setLayout(self.layout) def setModule(self): self.text1.setMaximumSize(55, 30) self.text2.setMaximumSize(55, 30) self.btn1.setMaximumSize(55, 30) self.btn2.setMaximumSize(55, 30) self.btn3.setMaximumSize(55, 30) self.settingBtn.setStyleSheet(css.restart_btn) def updateSetting(self): #opacity set self.data['set_data']['label_opacity'] = float( self.text1.toPlainText()) self.data['set_data']['touch_opacity'] = float( self.text2.toPlainText()) write(self.data) self.close() qApp.exit(888) def fontSetting(self): font, ok = QFontDialog.getFont() info = font.toString().split(',') # QFont Object => list if ok: self.data['set_data']['font'] = info[0] self.data['set_data']['font_size'] = int(info[1]) self.data['set_data']['font_bold'] = info[10] def colorSetting(self): color = QColorDialog.getColor() if color.isValid(): self.data['set_data']['font_color'] = color.name() def bgcolorSetting(self): color = QColorDialog.getColor() if color.isValid(): self.data['set_data']['background_color'] = color.name() def center(self): desktop = QApplication.desktop() x = (desktop.width() - self.width()) / 2 - self.width() y = (desktop.height() - self.height()) / 2 - self.height() self.move(QPoint(x, y))
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()