# -*- coding: iso-8859-1 -*- ### # Importe PyQT5 ### import shutil import string from PyQt5 import QtCore as qtc from PyQt5 import QtWidgets as qtw from PyQt5 import QtGui as qtg from screens.ui_SteamModManager import Ui_SteamModManagerFrame from screens.ui_ModpackTabWidget import Ui_ModpackTabWidget from screens.ui_ModPackWidget import Ui_modPackWidget from screens.ui_ModItemWidget import Ui_modWidget from screens.ui_dialog_modPackDetials import Ui_Dialog_ModPackDetails from functools import partial class modPackItem(qtg.QStandardItem):#,qtw.QWidget """Custom Item für ModPack Einträge""" packWidget: qtw.QWidget ui:Ui_modPackWidget def __init__(self, packName:str='', description:str='',tags:str='',image_path:str='./assets/ring.png'): super().__init__() fnt = qtg.QFont('Calibri',12) fnt.setBold(True) self.setEditable(False) self.setForeground(qtg.QColor(0,0,0)) self.setFont(fnt) self.setText(packName) modPack_image = qtg.QImage(image_path) self.setData(modPack_image.scaled(64,64,qtc.Qt.AspectRatioMode.KeepAspectRatioByExpanding),qtc.Qt.ItemDataRole.DecorationRole) self.packWidget = qtw.QWidget() self.ui = Ui_modPackWidget() self.ui.setupUi(self.packWidget) self.ui.label_modPackName.setText(packName) self.ui.label_modDescription.setText(description) tag_str = "" for tag in tags.split(' ,;'): tag_str = "["+tag+"] " self.ui.label_modPackTags.setText(tag_str) class modItem(qtg.QStandardItem): """Custom Item für Mod Einträge""" #TODO Default Mod Item Icon einbauen def __init__(self,txt:str='',image_path:str='./assets/gem.png'): super().__init__() fnt = qtg.QFont('Calibri',12) fnt.setBold(False) self.setEditable(False) self.setForeground(qtg.QColor(0,0,0)) self.setFont(fnt) self.setText(txt) mod_image = qtg.QImage(image_path) self.setData(mod_image.scaled(64,64,qtc.Qt.AspectRatioMode.KeepAspectRatioByExpanding),qtc.Qt.ItemDataRole.DecorationRole) class SteamModManager_Dialog(qtw.QDialog): window: Ui_SteamModManagerFrame treeModel: qtg.QStandardItemModel rootNode: qtg.QStandardItem def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.window = Ui_SteamModManagerFrame() self.window.setupUi(self) self.window.label_footer.setText("") self.treeModel = qtg.QStandardItemModel() self.rootNode = self.treeModel.invisibleRootItem() #modPack = modPackItem('Dont Starve Together') #testMod = modItem("TestMod") #modPack.appendRow(testMod) #self.rootNode.appendRow(modPack) self.window.tView_modPacks.setModel(self.treeModel) self.window.tView_modPacks.expandAll() #modPackWidget = qtw.QWidget() #ui = Ui_modPackWidget() #ui.setupUi(modPackWidget) #self.window.tView_modPacks.setIndexWidget(self.treeModel.index(0,0),modPackWidget) ### # Buttons im Screen mit Funktionen verknüpfen ### self.window.tbtn_addModPack.clicked.connect(self.handle_addModPack_clicked) def populate_modPackTree(self): pass def save_modPackTree_to_xml(self): pass def handle_addModPack_clicked(self): self.setFooterText("") #debug #modPack2 = modPackItem('Dont Starve Together2') #self.rootNode.appendRow(modPack2) self.modPackDetailWidget=None self.modPackDetailWidget = qtw.QWidget() self.modPackDetail_ui=None self.modPackDetail_ui = Ui_Dialog_ModPackDetails() self.modPackDetail_ui.setupUi(self.modPackDetailWidget) self.modPackDetail_ui.tBtn_confirm.clicked.connect(partial(self.handle_modPackDetailsPopUp_confirm_clicked)) self.modPackDetail_ui.tBtn_cancel.clicked.connect(self.handle_modPackDetailsPopUp_cancel_clicked) self.modPackDetailWidget.show() def handle_modPackDetailsPopUp_cancel_clicked(self): self.setFooterText("") self.modPackDetailWidget.destroy() def handle_modPackDetailsPopUp_confirm_clicked(self): self.setFooterText("") #plausibility checks if self.modPackDetail_ui.edit_modpackName.text().strip() != "": #ui = Ui_ModpackTabWidget() #ui.setupUi(self.modTab) #ui.label_modpackName.setText(self.modPackDetail_ui.edit_modpackName.text().strip()) #modVLayout = qtw.QVBoxLayout(ui.scroll_modArea) #grpBox = qtw.QGroupBox() #grpBox.setLayout(modVLayout) #ui.scroll_modArea.setWidget(grpBox) #ui.scroll_modArea.setWidgetResizable(True) #ui.scroll_modArea.setFixedHeight(200) #self.list_modLayouts.append(modVLayout) #ui.label_modpackName.textChanged.connect(partial(self.setModpackName,ui)) #ui.tBtn_addmod.clicked.connect(self.addNewModItem) #edit_modpackName = self.modPackDetailWidget.findChild(qtw.QWidget, name="edit_modpackName") #self.window.MainTabWidget.addTab(self.modTab,edit_modpackName.text()) #self.window.MainTabWidget.addTab(customTabbar(),"+") edit_modpackName = self.modPackDetailWidget.findChild(qtw.QWidget, name="edit_modpackName") edit_description = self.modPackDetailWidget.findChild(qtw.QWidget, name="edit_modpack_description") edit_tags = self.modPackDetailWidget.findChild(qtw.QWidget, name="edit_modpack_tags") modPack = modPackItem(edit_modpackName.text(),edit_description.text(),edit_tags.text()) self.rootNode.appendRow(modPack) self.window.tView_modPacks.setIndexWidget(self.treeModel.index(0,0),modPack.packWidget) self.modPackDetailWidget.destroy() else: self.setFooterText("Error: Modpack-Name cannot be empty.") self.modPackDetailWidget.destroy() def setModpackName(self,modPack_ui:Ui_ModpackTabWidget): self.window.MainTabWidget.setTabText(self.window.MainTabWidget.currentIndex(),modPack_ui.edit_modpackName.displayText()) #def setModpackDescription(self,modPack_ui:Ui_ModpackTabWidget): # modPack_ui.edit_modpack_description.setText() #def setModpackTags(self,modPack): # pass def addNewModItem(self): self.setFooterText("") modWidget = qtw.QWidget() ui_mod = Ui_modWidget() ui_mod.setupUi(modWidget) ui_mod.tBtn_deleteMod.clicked.connect(partial(self.closeModItem,modWidget)) self.list_modLayouts[self.window.MainTabWidget.currentIndex()].addWidget(modWidget) def closeModItem(self,widget:qtw.QWidget): self.setFooterText("") widget.setParent(None) def edit_modName(self,modItem): pass def setFooterText(self, text: str) -> str: """ Write footer-line for Status-Messages Args: text (str): Input-Text for display Returns: str: returns displayed text """ self.window.label_footer.setText(text) return text