def __init__(self, *args, **kwargs): super(KwWorkFontDialog, self).__init__(*args, **kwargs) #fontIds = [] #for font_fname in free_font_path_generator(): # fontIds = QFontDatabase.addApplicationFont(font_fname) #QFontDatabase.removeAllApplicationFonts() fontFreeFilterChecker = QCheckBox(u'Вільні') fontNoFreeFilterChecker = QCheckBox(u'Невільні') fontRating5FilterChecker = QCheckBox(u'Найкращі') fontRating4FilterChecker = QCheckBox(u'Добрі') fontRating3FilterChecker = QCheckBox(u'Задовільні') fontUseStrict_FilterChecker = QCheckBox(u'Діловодство, наука') fontUseWriting_FilterChecker = QCheckBox(u'Рукопис') fontUseFantasy_FilterChecker = QCheckBox(u'Декорації, реклама') fontFamilyListView = QListView() fontFamilyListView.setMinimumWidth(250) #fontFamilyModel = QStringListModel([str(fontDatabase.sty)]) fontStyleListView = QListView() fontStyleListView.setFixedWidth(150) fontSizeListView = QListView() fontSizeListView.setFixedWidth(60) fontSizeModel = QStringListModel([ str(v) for v in (6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72) ]) fontSizeListView.setModel(fontSizeModel) fontSizeListView.setEditTriggers(QAbstractItemView.NoEditTriggers) fontSampleWidget = QLabel(u'ІіЇїРр') fontSampleWidget.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken) fontSampleWidget.setStyleSheet(r'''QLabel { font: normal normal 72pt "Consolas"; padding: 3px; qproperty-alignment: AlignCenter; color: black; background-color: white; }''') sampleGroup = QGroupBox(u'Зразок:') sampleLayout = QHBoxLayout(sampleGroup) sampleLayout.addWidget(fontSampleWidget) fontFilterLayout = QHBoxLayout() fontAccessFilterGroup = QGroupBox(u'Доступність:') fontAccessFilterLayout = QVBoxLayout(fontAccessFilterGroup) fontAccessFilterLayout.addWidget(fontFreeFilterChecker) fontAccessFilterLayout.addWidget(fontNoFreeFilterChecker) fontAccessFilterLayout.addStretch() fontFilterLayout.addWidget(fontAccessFilterGroup) fontUseFilterGroup = QGroupBox(u'Призначення:') fontUseFilterLayout = QVBoxLayout(fontUseFilterGroup) fontUseFilterLayout.addWidget(fontUseStrict_FilterChecker) fontUseFilterLayout.addWidget(fontUseWriting_FilterChecker) fontUseFilterLayout.addWidget(fontUseFantasy_FilterChecker) fontFilterLayout.addWidget(fontUseFilterGroup) fontRatingFilterGroup = QGroupBox(u'Оцінка:') fontRatingFilterLayout = QVBoxLayout(fontRatingFilterGroup) fontRatingFilterLayout.addWidget(fontRating5FilterChecker) fontRatingFilterLayout.addWidget(fontRating4FilterChecker) fontRatingFilterLayout.addWidget(fontRating3FilterChecker) fontFilterLayout.addWidget(fontRatingFilterGroup) fontLayout = QGridLayout() familyLayout = QVBoxLayout() familyLayout.setSpacing(3) familyLayout.addWidget(QLabel(u'Шрифт:')) familyLayout.addWidget(fontFamilyListView) fontLayout.addLayout(familyLayout, 0, 0) styleLayout = QVBoxLayout() styleLayout.setSpacing(3) styleLayout.addWidget(QLabel(u'Стиль:')) styleLayout.addWidget(fontStyleListView) fontLayout.addLayout(styleLayout, 0, 1) sizeLayout = QVBoxLayout() sizeLayout.setSpacing(3) sizeLayout.addWidget(QLabel(u'Розмір:')) sizeLayout.addWidget(fontSizeListView) fontLayout.addLayout(sizeLayout, 0, 2) fontLayout.addWidget(sampleGroup, 1, 0, 1, 3) bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) layout = QVBoxLayout(self) testButton = QPushButton(u'Тестова: відкрити шрифт') testButton.clicked.connect(lambda: QFontDialog.getFont()) layout.addWidget(testButton) layout.addLayout(fontFilterLayout) layout.addLayout(fontLayout) layout.addSpacing(5) layout.addWidget(bbox) self.setWindowTitle(u'Вибір шрифта') self.setWindowFlags(self.windowFlags() ^ Qt.WindowContextHelpButtonHint) # Налаштування. fontMaxPointSize = fontSizeListView.font() # print(QFontDatabase.families()) fontMaxPointSize.setPointSize(72) fm = QFontMetrics(fontMaxPointSize) fontSampleWidget.setMinimumHeight( fm.size(Qt.TextSingleLine | Qt.TextShowMnemonic, u'Їр').height()) fontSizeListView.setCurrentIndex( fontSizeModel.match(fontSizeModel.index(0, 0), Qt.DisplayRole, fontSizeListView.font().pointSize())[0]) fontFreeFilterChecker.setChecked(True) fontUseStrict_FilterChecker.setChecked(True) fontRating5FilterChecker.setChecked(True) fontRating4FilterChecker.setChecked(True)
class JsonEdit(QWidget): def __init__(self, dataPath, ico, parent=None, flags=Qt.WindowCloseButtonHint): super(JsonEdit, self).__init__(parent, flags) self.setStyleSheet( '''JsonEdit{background:#272626}QLabel{color:#ffffff;font-family:"Microsoft YaHei", SimHei, SimSun;font:11pt;} QPushButton{border:0px;background:#4d4d4d;color:#ffffff;font-family: "Microsoft YaHei", SimHei, SimSun;font:11pt;} QPushButton:pressed{background:#606162;font:10pt;} QPushButton:checked{background:#70bbe4;} QPushButton:hover{border-style:solid;border-width:1px;border-color:#ffffff;} QLineEdit{background-color:#4d4d4d;color:#ffffff;font-family:"Microsoft YaHei", SimHei, SimSun;font:11pt;border:0px;padding-left:5px} QLineEdit:hover{border-style:solid;border-width:1px;border-color:#ffffff;padding-left:4px;} QListView{background-color:#4d4d4d;color:#ffffff;font-family:"Microsoft YaHei", SimHei, SimSun;font:12pt;} QComboBox:hover{border-style:solid;border-width:1px;border-color:#ffffff;padding-left:4px;} QComboBox{background-color:#4d4d4d;color:#ffffff;font-family:"Microsoft YaHei", SimHei, SimSun;font:11pt;padding-left:5px;border:0px;} QComboBox:drop-down{width:0px;} QComboBox:down-arrow{width:0px} QComboBox:selected{background-color:#606162;} QComboBox:QAbstractItemView::item{font-family:"Microsoft YaHei", SimHei, SimSun;font:11pt;} QComboBox:QAbstractItemView::item:selected{background-color:#606162;} QInputDialog{background-color:#272626;} QScrollBar:vertical{width:8px;background:rgba(0,0,0,0%);margin:0px,0px,0px,0px;padding-top:0px;padding-bottom:0px;} QScrollBar:handle:vertical{width:8px;background:rgba(0,0,0,25%);border-radius:0px;min-height:20;} QScrollBar:handle:vertical:hover{width:8px;background:rgba(0,0,0,50%);border-radius:0px;min-height:20;} QScrollBar:add-line:vertical{height:0px;width:0px;subcontrol-position:bottom;} QScrollBar:sub-line:vertical{height:0px;width:0px;subcontrol-position:top;} QScrollBar:add-page:vertical,QScrollBar:sub-page:vertical{background:rgba(0,0,0,10%);border-radius:0px;} QScrollBar:horizontal{height:8px;background:rgba(0,0,0,0%);margin:0px,0px,0px,0px;padding-top:0px;padding-bottom:0px;} QScrollBar:handle:horizontal{width:8px;background:rgba(0,0,0,25%);border-radius:0px;min-height:20;} QScrollBar:handle:horizontal:hover{width:8px;background:rgba(0,0,0,50%);border-radius:0px;min-height:20;} QScrollBar:add-line:horizontal{height:0px;width:0px;subcontrol-position:bottom;} QScrollBar:sub-line:horizontal{height:0px;width:0px;subcontrol-position:top;} QScrollBar:add-page:horizontal,QScrollBar:sub-page:horizontal{background:rgba(0,0,0,10%);border-radius:0px;}''' ) self.setWindowIcon(QIcon(ico)) self.isshow = False self.isBootyMode = False self.bootyName = '固源岩' self.selPanel = BootyChoice(self, ico) self.json = dataPath + '/schedule.json' self.scheduleAdd = { 'part': 'MAIN', 'chap': '', 'objLevel': '', 'times': '' } self.transEX = { 'ex1': '切尔诺伯格', 'ex2': '龙门外环', 'ex3': '龙门市区', 'ex4': '当期委托' } self.partList = ['主线', '物资筹备', '芯片搜索', '剿灭作战'] self.partListJson = ['MAIN', 'RS', 'PR', 'EX'] self.mainChapList = [ '序章', '第一章', '第二章', '第三章', '第四章', '第五章', '第六章', '第七章', '第八章' ] self.rsChapList = ['战术演习', '粉碎防御', '空中威胁', '货物运送', '资源保障'] self.prChapList = ['医疗重装', '术士狙击', '辅助先锋', '特种近卫'] self.exChapList = ['切尔诺伯格', '龙门外环', '龙门市区', '当期委托'] self.chapList = [ self.mainChapList, self.rsChapList, self.prChapList, self.exChapList ] self.selIndex = None self.grid = QGridLayout() self.lsv = QListView() #计划显示框 self.lsv.setFixedWidth(200) self.lsv.clicked.connect(self.clickSchedule) self.lsv.setContextMenuPolicy(Qt.CustomContextMenu) self.lsv.customContextMenuRequested.connect(self.lsvRearrange) self.actMoveUp = QAction('上移') self.actMoveUp.triggered.connect(self.moveUpLine) self.actMoveDown = QAction('下移') self.actMoveDown.triggered.connect(self.moveDownLine) self.actEdit = QAction('修改次数/个数') self.actEdit.triggered.connect(self.editLine) self.actDel = QAction('删除') self.actDel.triggered.connect(self.delLine) self.slm = QStringListModel() self.partCb = QComboBox() self.partCb.addItems(self.partList) self.partCb.activated[int].connect(self.changeChapList) self.partCb.setFixedSize(80, 40) self.partCb.setView(QListView()) self.chapCb = QComboBox() self.chapCb.addItems(self.mainChapList) self.chapCb.activated[int].connect(self.changeLevel1List) self.chapCb.setFixedSize(100, 40) self.chapCb.setView(QListView()) self.level1Cb = QComboBox() self.level1Cb.setFixedSize(60, 40) self.level1Cb.setView(QListView()) self.lineLable = QLabel() self.lineLable.setText('-') self.level2Edit = QLineEdit() self.level2Edit.setFixedSize(50, 40) self.timesLable = QLabel() self.timesLable.setText('次数:') self.timeEdit = QLineEdit() self.timeEdit.setFixedSize(50, 40) self.bootyModeBtn = QPushButton() self.bootyModeBtn.setCheckable(True) self.bootyModeBtn.setText('素材模式') self.bootyModeBtn.setFixedHeight(40) self.bootyModeBtn.clicked[bool].connect(self.setBootMode) self.bootySelBtn = QPushButton() self.bootySelBtn.setText('——') self.bootySelBtn.setFixedHeight(40) self.bootySelBtn.clicked.connect(self.selPanel.myShow) self.delBtn = QPushButton() self.delBtn.setText('删除') self.delBtn.clicked.connect(self.delLine) self.delBtn.setFixedHeight(40) self.clearBtn = QPushButton() self.clearBtn.setText('清空') self.clearBtn.clicked.connect(self.clearLine) self.clearBtn.setFixedHeight(40) self.addBtn = QPushButton() self.addBtn.setText('添加') self.addBtn.clicked.connect(self.addLine) self.addBtn.setFixedHeight(40) self.planCb = QComboBox() self.planCb.setFixedSize(200, 40) self.planCb.setView(QListView()) self.loadPlanBtn = QPushButton() self.loadPlanBtn.setText('加载配置') self.loadPlanBtn.setFixedHeight(40) self.loadPlanBtn.clicked.connect(self.loadPlan) self.addPlanBtn = QPushButton() self.addPlanBtn.setText('以当前配置新建') self.addPlanBtn.setFixedHeight(40) self.addPlanBtn.clicked.connect(self.addPlan) self.delPlanBtn = QPushButton() self.delPlanBtn.setText('删除此配置') self.delPlanBtn.setFixedHeight(40) self.delPlanBtn.clicked.connect(self.delPlan) self.listScheduleBefore = [] self.listSchedule = [] self.initJson() self.slm.setStringList(self.listSchedule) self.lsv.setModel(self.slm) self.lsv.setEditTriggers(QListView.NoEditTriggers) self.changeLevel1List(0) self.grid.addWidget(self.lsv, 0, 0, 3, 1) self.grid.addWidget(self.partCb, 0, 1, 1, 1) self.grid.addWidget(self.chapCb, 0, 2, 1, 1) self.grid.addWidget(self.level1Cb, 0, 3, 1, 1) self.grid.addWidget(self.lineLable, 0, 4, 1, 1) self.grid.addWidget(self.level2Edit, 0, 5, 1, 1) self.grid.addWidget(self.timesLable, 0, 6, 1, 1) self.grid.addWidget(self.timeEdit, 0, 7, 1, 1) self.grid.addWidget(self.bootyModeBtn, 1, 1, 1, 1) self.grid.addWidget(self.bootySelBtn, 1, 2, 1, 1) self.grid.addWidget(self.addBtn, 1, 3, 1, 5) self.grid.addWidget(self.delBtn, 2, 1, 1, 4) self.grid.addWidget(self.clearBtn, 2, 5, 1, 3) self.grid.addWidget(self.planCb, 3, 0, 1, 1) self.grid.addWidget(self.loadPlanBtn, 3, 1, 1, 1) self.grid.addWidget(self.addPlanBtn, 3, 2, 1, 3) self.grid.addWidget(self.delPlanBtn, 3, 5, 1, 3) self.setLayout(self.grid) self.setWindowTitle('路线规划') #self.resize(600,400) self.myTimer() #self.show() def editerShow(self): if not self.isVisible(): self.show() cp = QDesktopWidget().availableGeometry().center() self.move(int(cp.x() - self.width() / 2), int(cp.y() - self.height() / 2)) def myTimer(self): self.updateTimer = QTimer() self.updateTimer.timeout.connect(self.updateList) self.updateTimer.start(10) def lsvRearrange(self): self.selIndex = self.lsv.currentIndex().row() rightClickMeun = QMenu() rightClickMeun.setStyleSheet( '''QMenu {color:#ffffff;font-family: "Microsoft YaHei", SimHei, SimSun;font:10pt; background-color:#272626; margin:3px;} QMenu:item {padding:8px 32px;} QMenu:item:selected { background-color: #3f4140;} QMenu:icon{padding: 8px 20px;} QMenu:separator{background-color: #7C7C7C; height:1px; margin-left:2px; margin-right:2px;}''' ) rightClickMeun.addAction(self.actMoveUp) rightClickMeun.addAction(self.actMoveDown) rightClickMeun.addAction(self.actEdit) rightClickMeun.addAction(self.actDel) rightClickMeun.exec_(QCursor.pos()) def initJson(self): with open(self.json, 'r', encoding='UTF-8') as s: data = s.read() self.jsonAll = loads(data)["main"] self.selPlan = self.jsonAll[0] self.allPlanList = self.selPlan['allplan'].split('|') #配置选单显示 self.planCb.addItems(self.allPlanList) self.jsonDict = self.jsonAll[0]['sel'] self.selList = self.jsonDict.copy() self.refreshJsonView() def refreshJsonView(self): self.listSchedule = [] for eachDict in self.selList: temp = eachDict['objLevel'] if 'ex' in temp: temp = self.transEX[temp] if eachDict['chap'] == 'LS': temp = temp.replace('S', 'LS') if isinstance(eachDict['times'], dict): self.listSchedule.append('{0}({1}共{2}个)'.format( temp, eachDict['times']['bootyName'], eachDict['times']['bootyNum'])) else: self.listSchedule.append('{0}(共{1}次)'.format( temp, eachDict['times'])) def updateJson(self): self.jsonAll[0]['sel'] = self.selList.copy() self.jsonAll[0]['allplan'] = '|'.join(self.allPlanList) #self.jsonAll[0]['selno'] = str(self.selNo) tempNewJson = {'main': self.jsonAll} newData = dumps(tempNewJson, sort_keys=True, indent=4, separators=(',', ': '), ensure_ascii=False) with open(self.json, 'w', encoding='UTF-8') as j: j.write(newData) def updateList(self): if self.listSchedule != self.listScheduleBefore: self.listScheduleBefore = self.listSchedule.copy() self.slm.setStringList(self.listSchedule) self.updateJson() def changeChapList(self, indexI): self.scheduleAdd['part'] = self.partListJson[indexI] self.chapCb.clear() self.chapCb.addItems(self.chapList[indexI]) self.changeLevel1List(0) def changeLevel1List(self, indexI): self.level1Cb.clear() selChap = self.chapCb.currentText() self.level2Edit.setReadOnly(False) levelList = [] if '章' in selChap: self.scheduleAdd['chap'] = str(int(indexI)) if int(indexI) != 8: levelList.append(f'{int(indexI)}') if int(indexI) != 0 and int(indexI) != 1: if int(indexI) != 8: levelList.append(f'S{int(indexI)}') elif int(indexI) == 8: levelList.extend([ f'R{int(indexI)}', f'M{int(indexI)}', f'JT{int(indexI)}' ]) elif selChap == '战术演习': self.scheduleAdd['chap'] = 'LS' levelList.append('LS') elif selChap == '粉碎防御': self.scheduleAdd['chap'] = 'AP' levelList.append('AP') elif selChap == '空中威胁': self.scheduleAdd['chap'] = 'CA' levelList.append('CA') elif selChap == '货物运送': self.scheduleAdd['chap'] = 'CE' levelList.append('CE') elif selChap == '资源保障': self.scheduleAdd['chap'] = 'SK' levelList.append('SK') elif selChap == '医疗重装': self.scheduleAdd['chap'] = 'A' levelList.append('PR-A') elif selChap == '术士狙击': self.scheduleAdd['chap'] = 'B' levelList.append('PR-B') elif selChap == '辅助先锋': self.scheduleAdd['chap'] = 'C' levelList.append('PR-C') elif selChap == '特种近卫': self.scheduleAdd['chap'] = 'D' levelList.append('PR-D') else: if selChap == '切尔诺伯格': self.scheduleAdd['chap'] = 'external' self.scheduleAdd['objLevel'] = 'ex1' elif selChap == '龙门外环': self.scheduleAdd['chap'] = 'external' self.scheduleAdd['objLevel'] = 'ex2' elif selChap == '龙门市区': self.scheduleAdd['chap'] = 'external' self.scheduleAdd['objLevel'] = 'ex3' elif selChap == '当期委托': self.scheduleAdd['chap'] = 'external' self.scheduleAdd['objLevel'] = 'ex4' self.level2Edit.clear() self.level2Edit.setReadOnly(True) self.level1Cb.addItems(levelList) def addLine(self): tempLevel = self.level2Edit.text() if 'EX' != self.scheduleAdd['part']: self.scheduleAdd['objLevel'] = '' tempTimes = self.timeEdit.text() self.scheduleAdd['times'] = '' if tempLevel != '': part1 = self.level1Cb.currentText() if part1 == 'LS': part1 = 'S' if tempLevel.isdecimal(): self.scheduleAdd['objLevel'] = part1 + '-' + tempLevel if tempTimes.isdecimal(): if self.isBootyMode: self.scheduleAdd['times'] = { 'bootyName': self.bootyName, 'bootyNum': tempTimes } else: self.scheduleAdd['times'] = tempTimes if self.scheduleAdd['objLevel'] != '' and self.scheduleAdd[ 'times'] != '': self.selList.append(self.scheduleAdd.copy()) self.refreshJsonView() def clickSchedule(self, qModelIndex): self.selIndex = qModelIndex.row() def delLine(self): if self.selIndex != None: self.listSchedule.pop(self.selIndex) self.selList.pop(self.selIndex) self.selIndex = None def moveUpLine(self): if self.selIndex != 0 and self.selIndex != None: #temp = self.listSchedule[self.selIndex - 1] self.listSchedule[self.selIndex - 1], self.listSchedule[self.selIndex] = \ self.listSchedule[self.selIndex], self.listSchedule[self.selIndex - 1] self.selList[self.selIndex - 1], self.selList[self.selIndex] = \ self.selList[self.selIndex], self.selList[self.selIndex - 1] self.selIndex = None def moveDownLine(self): if self.selIndex != (len(self.listSchedule) - 1) and self.selIndex != None: #temp = self.listSchedule[self.selIndex - 1] self.listSchedule[self.selIndex + 1], self.listSchedule[self.selIndex] = \ self.listSchedule[self.selIndex], self.listSchedule[self.selIndex + 1] self.selList[self.selIndex + 1], self.selList[self.selIndex] = \ self.selList[self.selIndex], self.selList[self.selIndex + 1] self.selIndex = None def editLine(self): if self.selIndex != None: if isinstance(self.selList[self.selIndex]['times'], dict): newNum, isOk = QInputDialog.getText(self, '修改', '请输入新的掉落物个数') if isOk: self.selList[self.selIndex]['times']['bootyNum'] = newNum else: newNum, isOk = QInputDialog.getText(self, '修改', '请输入新的次数') self.selList[self.selIndex]['times'] = newNum self.refreshJsonView() self.selIndex = None def clearLine(self): self.listSchedule.clear() self.selList.clear() def loadPlan(self): if self.planCb.currentIndex() != 0: self.jsonDict = self.jsonAll[self.planCb.currentIndex() + 1][ self.allPlanList[self.planCb.currentIndex()]] self.selList = self.jsonDict.copy() self.refreshJsonView() def addPlan(self): planName, ok = QInputDialog.getText(self, '配置名称', '请输入配置名称:') if ok: if '|' in planName: planName.replace('|', '·') self.allPlanList.append(planName) tempDict = dict() tempDict[planName] = self.selList.copy() self.jsonAll.append(tempDict) self.updateJson() self.planCb.clear() self.planCb.addItems(self.allPlanList) def delPlan(self): if self.planCb.currentIndex() != 0: self.allPlanList.pop(self.planCb.currentIndex()) self.jsonAll.pop(self.planCb.currentIndex() + 1) self.updateJson() self.planCb.clear() self.planCb.addItems(self.allPlanList) def setBootMode(self, isChecked): self.isBootyMode = isChecked if self.isBootyMode: self.timesLable.setText('个数:') self.bootySelBtn.setText('选择掉落物') else: self.timesLable.setText('次数:') self.bootySelBtn.setText('———') def test(self): self.listSchedule.append('add') print(self.listSchedule)