Esempio n. 1
0
def exe():
    if platform.system() == 'Darwin':
        subprocess.run([sys.executable, 'setup.py', 'py2app'], check=True)

        import dmgbuild
        dmgbuild.build_dmg('dsremap-%s.dmg' % str(Meta.appVersion()),
                           Meta.appName(), 'dmgbuild-settings.py')
    elif platform.system() == 'Windows':
        subprocess.run([sys.executable, 'setup.py', 'build'], check=True)
        distdir = r'build\exe.win-%s-%s' % (platform.machine().lower(),
                                            '%d.%d' % sys.version_info[:2])
        with codecs.getwriter('utf-8')(open('installer.nsi', 'wb')) as dst:
            with codecs.getreader('utf-8')(open('installer.nsi.in',
                                                'rb')) as src:
                for line in src:
                    dst.write(
                        line.replace('@APPNAME@', Meta.appName()).replace(
                            '@APPVERSION@', str(Meta.appVersion())).replace(
                                '@DISTDIR@',
                                distdir).replace('@WEBSITE@', Meta.appSite()))
        import winreg
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE', 0,
                             winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
        try:
            path = winreg.QueryValue(key, 'NSIS')
        except:
            raise RuntimeError(
                'Cannot find NSIS in registry, is it installed ?')
        finally:
            winreg.CloseKey(key)
        # Assuming NSIS 3.x here
        subprocess.run([
            os.path.join(path, 'makensis.exe'), '/INPUTCHARSET', 'UTF8',
            'installer.nsi'
        ],
                       check=True)
    elif platform.system() == 'Linux':
        with codecs.getwriter('utf-8')(open('appimage.yml', 'wb')) as dst:
            with codecs.getreader('utf-8')(open('appimage.yml.in',
                                                'rb')) as src:
                for line in src:
                    dst.write(line.replace('@VERSION@',
                                           str(Meta.appVersion())))
        subprocess.run(
            ['appimage-builder', '--recipe', 'appimage.yml', '--skip-test'],
            check=True)
    else:
        raise RuntimeError('Unsupported platform')
Esempio n. 2
0
def setup():
    logging.TRACE = 5

    def trace(self, fmt, *args, **kwargs):
        if self.isEnabledFor(logging.TRACE):
            self._log(logging.TRACE, fmt, args, **kwargs)  # pylint: disable=W0212

    logging.Logger.trace = trace
    logging.addLevelName(logging.TRACE, 'TRACE')
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)-15s %(levelname)-8s %(name)-15s %(message)s')

    if platform.system() == 'Darwin':
        localeName = str(QtCore.QLocale.system().uiLanguages()[0]).replace(
            '-', '_')
    else:
        localeName = str(QtCore.QLocale.system().name())

    try:
        locale.setlocale(locale.LC_ALL, localeName)
    except locale.Error as exc:
        logger = logging.getLogger('dsremap')
        logger.error('Cannot set locale to "%s": %s', localeName, exc)

    trans = gettext.translation(Meta.appName(),
                                localedir=Meta.messages(),
                                languages=[localeName],
                                fallback=True)
    trans.install()
Esempio n. 3
0
    def __init__(self):
        super().__init__([])
        self.setApplicationName(Meta.appName())
        self.setApplicationVersion(str(Meta.appVersion()))
        self.setOrganizationDomain(Meta.appDomain())
        self.setWindowIcon(QtGui.QIcon(':icons/gamepad.svg'))

        # Builtin messages.
        trans = QtCore.QTranslator(self)
        path = QtCore.QLibraryInfo.location(
            QtCore.QLibraryInfo.TranslationsPath)
        trans.load(QtCore.QLocale.system(), 'qtbase', '_', path)
        self.installTranslator(trans)
Esempio n. 4
0
# Mock imports from Meta
class PyQt5:
    class QtCore:
        pass

    class QtGui:
        pass


sys.modules['PyQt5'] = PyQt5

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
from dsrlib.meta import Meta

project = Meta.appName()
copyright = '2020-2021, %s' % Meta.appAuthor()
author = Meta.appAuthor()

# The short X.Y version
version = '%d.%d' % Meta.appVersion()[:2]
# The full version, including alpha/beta/rc tags
release = str(Meta.appVersion())

# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     super().__init__(
         *args,
         text=_('About {appname}...').format(appname=Meta.appName()),
         **kwargs)
     self.setMenuRole(self.AboutRole)
Esempio n. 6
0
    setup(app=['dsremap.py'],
          options={
              'py2app': {
                  'iconfile': os.path.join('icons', 'dsremap.icns')
              }
          },
          setup_requires=['py2app'],
          data_files=data_files)

if platform.system() == 'Windows':
    from cx_Freeze import setup, Executable

    options = {
        'include_files': [
            (r'res\avrdude.conf', r'resources\avrdude.conf'),
            (r'res\configurations', r'resources\configurations'),
            (r'i18n', r'resources\i18n'),
        ]
    }

    setup(name=Meta.appName(),
          version=str(Meta.appVersion()),
          description=Meta.appName(),
          options={'build_exe': options},
          executables=[
              Executable('dsremap.py',
                         base='Win32GUI',
                         icon=r'icons\dsremap.ico')
          ])
Esempio n. 7
0
    def __init__(self):  # pylint: disable=R0915
        super().__init__()

        self._manager = QtNetwork.QNetworkAccessManager(self)

        self._workspace = Workspace()
        self.setCentralWidget(
            WorkspaceView(self, mainWindow=self, workspace=self._workspace))
        self._workspace.load()
        self._devenum = DeviceEnumerator()

        self.setWindowTitle(
            _('{appName} v{appVersion}').format(appName=Meta.appName(),
                                                appVersion=str(
                                                    Meta.appVersion())))
        self.statusBar()

        filemenu = QtWidgets.QMenu(_('File'), self)
        filemenu.addAction(
            uicommands.ExportConfigurationUICommand(
                self, mainWindow=self, container=self.centralWidget()))
        filemenu.addAction(
            uicommands.ImportConfigurationUICommand(self,
                                                    mainWindow=self,
                                                    workspace=self._workspace))
        filemenu.addAction(
            uicommands.ExportBytecodeUICommand(self,
                                               mainWindow=self,
                                               workspace=self._workspace,
                                               container=self.centralWidget()))
        self.menuBar().addMenu(filemenu)

        editmenu = QtWidgets.QMenu(_('Edit'), self)
        editmenu.addAction(uicommands.UndoUICommand(self, mainWindow=self))
        editmenu.addAction(uicommands.RedoUICommand(self, mainWindow=self))
        editmenu.addAction(
            uicommands.ShowSettingsDialogUICommand(self, mainWindow=self))
        self.menuBar().addMenu(editmenu)

        devmenu = uicommands.DeviceMenu(self,
                                        mainWindow=self,
                                        workspace=self._workspace,
                                        enumerator=self._devenum)
        self.menuBar().addMenu(devmenu)

        uploadmenu = uicommands.UploadMenu(self,
                                           mainWindow=self,
                                           container=self.centralWidget(),
                                           workspace=self._workspace,
                                           enumerator=self._devenum)
        self.menuBar().addMenu(uploadmenu)

        helpmenu = QtWidgets.QMenu(_('Help'), self)
        helpmenu.addAction(
            uicommands.ShowAboutDialogUICommand(self, mainWindow=self))
        helpmenu.addAction(uicommands.OpenDocsUICommand(self, mainWindow=self))
        self.menuBar().addMenu(helpmenu)

        with Settings().grouped('UIState') as settings:
            if settings.contains('WindowGeometry'):
                self.restoreGeometry(settings.value('WindowGeometry'))
            else:
                self.resize(1280, 600)
            self.centralWidget().loadState(settings)

        self.raise_()
        self.show()

        settings = Settings()
        if settings.isFirstVersionLaunch():
            QtGui.QDesktopServices.openUrl(QtCore.QUrl(
                Meta.documentationUrl()))

        self.check()

        def gotChangelog(downloader):
            self._changelogDl = None
            try:
                _unused, text = downloader.result()
            except AbortedError:
                self.logger.info('Changelog download aborted')
                return
            except (DownloadError, SSLError) as exc:
                self.logger.exception('Cannot download changelog: %s', exc)
                return

            changelog = Changelog(text)
            if changelog.changesSince(Meta.appVersion()):
                win = ChangelogView(self, changelog)
                win.show()
                win.raise_()

        self._changelogDl = StringDownloader(self,
                                             self.manager(),
                                             callback=gotChangelog)
        self._changelogDl.get(Meta.changelogUrl())
Esempio n. 8
-1
    def __init__(self, parent):
        super().__init__(parent)

        self.setWindowTitle(
            _('{appname} v{appversion}').format(appname=Meta.appName(),
                                                appversion=str(
                                                    Meta.appVersion())))

        iodev = QtCore.QFile(':/about.html')
        iodev.open(iodev.ReadOnly)
        try:
            about = bytes(iodev.readAll()).decode('utf-8')
        finally:
            iodev.close()
        about = about.format(author=Meta.appAuthor())

        text = QtWidgets.QTextBrowser(self)
        text.setHtml(about)
        text.setOpenExternalLinks(True)

        btn = QtWidgets.QPushButton(_('Done'), self)

        bld = LayoutBuilder(self)
        with bld.vbox() as vbox:
            vbox.addWidget(text)
            with bld.hbox() as buttons:
                buttons.addStretch(1)
                buttons.addWidget(btn)

        btn.clicked.connect(self.accept)

        self.resize(800, 600)