示例#1
0
    def __init__(self, args, inifile):
        super().__init__(args)
        self._logger = logging.getLogger('pypipboyapp.main')

        self.startedFromWin32Launcher = False

        for i in range(0, len(args)):
            if args[i].lower() == '--startedfromwin32launcher':
                self.startedFromWin32Launcher = True

        # Prepare QSettings for application-wide use
        QtCore.QCoreApplication.setOrganizationName("PyPipboyApp")
        QtCore.QCoreApplication.setApplicationName("PyPipboyApp")
        if inifile:
            self._logger.info('Using ini-file "' + str(inifile) + '".')
            self.settings = QtCore.QSettings(inifile,
                                             QtCore.QSettings.IniFormat)
        elif platform.system() == 'Windows':
            self.settings = QtCore.QSettings(QtCore.QSettings.IniFormat,
                                             QtCore.QSettings.UserScope,
                                             "PyPipboyApp", "PyPipboyApp")
            # If there are no settings, copy existing settings from registry
            if len(self.settings.allKeys()) <= 0:
                registrySettings = QtCore.QSettings(
                    QtCore.QSettings.NativeFormat, QtCore.QSettings.UserScope,
                    "PyPipboyApp", "PyPipboyApp")
                for k in registrySettings.allKeys():
                    self.settings.setValue(k, registrySettings.value(k))
                    #registrySettings.remove(k)
                #registrySettings.sync()
        else:
            # Non-Windows OS already use the ini-format, they just use another file-extension. That's why we stick with nativeFormat.
            self.settings = QtCore.QSettings(QtCore.QSettings.NativeFormat,
                                             QtCore.QSettings.UserScope,
                                             "PyPipboyApp", "PyPipboyApp")

        # Init PyPipboy communication layer
        self.dataManager = PipboyDataManager()
        self.networkChannel = self.dataManager.networkchannel
        self.networkChannel.registerConnectionListener(
            self._onConnectionStateChange)
        # Connect internal signals
        self._signalAutodiscoveryFinished.connect(
            self._slotAutodiscoveryFinished)
        self.signalConnectToHost.connect(self.connectToHost)
        self._signalConnectToHostFinished.connect(
            self._slotConnectToHostFinished)
        self.signalShowWarningMessage.connect(self.showWarningMessage)
        self.signalRequestQuit.connect(self.requestQuit)
        self._signalFinishedCheckVersion.connect(
            self._slotFinishedCheckVersion)
        self._connectHostMessageBox = None
        self._connectHostThread = None
        self._iwcEndpoints = dict()
        self.widgetMenu = QtWidgets.QMenu()

        pipboyAppIcon = QtGui.QIcon()
        pipboyAppIcon.addFile(
            os.path.join('ui', 'res', 'PyPipBoyApp-Launcher.ico'))
        self.setWindowIcon(pipboyAppIcon)

        try:
            versionFile = open('VERSION', 'r')
            versionJSON = json.loads(versionFile.read())
            versionFile.close()
            self.PROGRAM_VERSION_MAJOR = versionJSON['major']
            self.PROGRAM_VERSION_MINOR = versionJSON['minor']
            self.PROGRAM_VERSION_REV = versionJSON['rev']
            self.PROGRAM_VERSION_SUFFIX = versionJSON['suffix']
        except Exception as e:
            self._logger.warn('Could not determine program version: ' + str(e))
示例#2
0
# -*- coding: utf-8 -*-

#
# Runs in an infinite loop and prints all received value updates to the console
#

from pypipboy.datamanager import PipboyDataManager, eValueUpdatedEventType
from pypipboy.types import eValueType

pipboy = PipboyDataManager()


# This callback will be executed for every new/updated/deleted value
# The argument is the PipboyValue instance representing the changed value and
# the event type
def valueUpdatedListener(value, eventtype):
    txt = str()
    if eventtype == eValueUpdatedEventType.NEW:
        txt += 'New'
    elif eventtype == eValueUpdatedEventType.UPDATED:
        txt += 'Updated'
    else:
        txt += 'Deleted'
    txt += ' Record(' + str(value.pipId) + '): '
    if eventtype != eValueUpdatedEventType.NEW:
        txt += value.pathStr() + ' => '
    if value.valueType == eValueType.BOOL:
        txt += 'bool( '
    elif value.valueType == eValueType.INT_8:
        txt += 'int8( '
    elif value.valueType == eValueType.UINT_8: