Пример #1
0
    def openProfileMenu(self, position):
        selectedItems = self.profileList.selectedItems()
        if selectedItems:
            menu = QtWidgets.QMenu()

            selectedItemsData = [
                item.data(0, Qt.UserRole) for item in selectedItems
            ]
            selectedProfiles = [
                selectedItemData['profileName']
                for selectedItemData in selectedItemsData
            ]

            syncAction = QtWidgets.QAction(QtGui.QIcon(':/MO/gui/next'),
                                           self.__tr('&Sync mod order'), self)
            syncAction.setEnabled(True)
            menu.addAction(syncAction)

            action = menu.exec_(self.profileList.mapToGlobal(position))

            try:
                if action == syncAction:
                    for profileName in selectedProfiles:
                        profileInfo = self.__profileInfo[profileName]
                        modListPath = os.path.join(profileInfo['path'],
                                                   'modlist.txt')
                        modListBackupPath = modListPath + '.' + datetime.datetime.now(
                        ).strftime('%Y%m%d%H%M%S%f')

                        qDebug(
                            self.__tr("Backing up to {}".format(
                                Dc.ensureUnicode(modListBackupPath))))
                        shutil.copy(modListPath, modListBackupPath)

                        selectedModListInfo = self.getModListInfoByPath(
                            modListPath)
                        mergedModListInfo = dict(self.__modListInfo,
                                                 **selectedModListInfo)

                        for modName in self.__modListInfo.keys():
                            mergedModListInfo[modName][
                                'index'] = self.__modListInfo[modName]['index']

                        qDebug(
                            self.__tr("Updating {} mod order".format(
                                Dc.ensureUnicode(modListPath))))
                        with open(modListPath, 'w') as modListFile:
                            for modName, modListEntry in sorted(
                                    mergedModListInfo.items(),
                                    key=lambda x: x[1]['index']):
                                modListFile.write(modListEntry['symbol'] +
                                                  modListEntry['name'] + '\n')

                    self.refreshProfileList()
            except Exception, e:
                qCritical(e.message)
Пример #2
0
 def getPluginStateByName(self, name):
     if name in self.__pluginInfo:
         pluginInfo = self.__pluginInfo[name]
         if (os.path.isfile(
                 os.path.join(pluginInfo['dirname'],
                              pluginInfo['filename']))):
             return Dc.PluginState(Dc.PluginState.ACTIVE)
         if (os.path.isfile(
                 os.path.join(pluginInfo['dirname'],
                              pluginInfo['filename'] + '.mohidden'))):
             return Dc.PluginState(Dc.PluginState.INACTIVE)
     else:
         qWarning(
             self.__tr("Plugin {} missing".format(Dc.ensureUnicode(name))))
     return Dc.PluginState(Dc.PluginState.MISSING)
Пример #3
0
 def getMergedModPluginsState(self, name):
     if name in self.__mergedModInfo:
         plugins = self.__mergedModInfo[name]['plugins']
         pluginstates = [
             self.getPluginStateByName(plugin) for plugin in plugins
         ]
         if (all((pluginstate in [Dc.PluginState.ACTIVE])
                 for pluginstate in pluginstates)):
             return Dc.ModPluginsState.ACTIVE
         elif (all((pluginstate in
                    [Dc.PluginState.MISSING, Dc.PluginState.INACTIVE])
                   for pluginstate in pluginstates)):
             return Dc.ModPluginsState.INACTIVE
         elif (any((pluginstate in
                    [Dc.PluginState.MISSING, Dc.PluginState.INACTIVE])
                   for pluginstate in pluginstates)):
             return Dc.ModPluginsState.MIXED
     else:
         qWarning(
             self.__tr("Merged mod {} missing".format(
                 Dc.ensureUnicode(name))))
     return Dc.ModPluginsState.UNKNOWN
Пример #4
0
 def __tr(self, str):
     return Dc.ensureUnicode(
         QCoreApplication.translate("MergePluginsHide", str))
Пример #5
0
 def __tr(self, str):
     return Dc.ensureUnicode(
         QCoreApplication.translate("SyncModOrderWindow", str))