def importSettings(self):
        # restore settings from the settings file if the settings exist
        settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)
        if settings.contains('digits'):
            # these value have been written by the program, so then should be ok
            self.digits = int(settings.value('digits'))
            self.rows = int(settings.value('rows'))
            self.timeout = int(settings.value('timeout'))
            self.flash = int(settings.value('flash'))
            self.hands_free = eval(settings.value('hands_free').capitalize())
            self.neg = eval(settings.value('neg').capitalize())
            if settings.contains('no_plus_sign'):
                self.no_plus_sign = eval(settings.value('no_plus_sign').capitalize())

        # GUI settings
        if settings.contains('GUI/fullscreen'):
            self.fullscreen = eval(settings.value('GUI/fullscreen').capitalize())
        if settings.contains('GUI/font'):
            font = str(settings.value('GUI/font'))
            self.ui.label.setFont(QtGui.QFont(font, 72, QtGui.QFont.Bold))
        if settings.contains('GUI/font_color'):
            self.font_color = str(settings.value('GUI/font_color'))
        if settings.contains('GUI/background_color'):
            self.background_color = str(settings.value('GUI/background_color'))

        # Sound settings
        if settings.contains('Sound/speech'):
            self.speech = eval(settings.value('Sound/speech').capitalize())
        if settings.contains('Sound/one_digit'):
            self.one_digit = eval(settings.value('Sound/one_digit').capitalize())
        if settings.contains('Sound/annoying_sound'):
            self.annoying_sound = eval(settings.value('Sound/annoying_sound').capitalize())
        global LANG
        if settings.contains('Sound/lang'):
            LANG = str(settings.value('Sound/lang'))
            if LANG.find('_') > 0:
                LANG = LANG.replace('_','-').lower()

        # uuid
        self.uuid = ''
        if settings.contains('uuid'):
            self.uuid = str(settings.value('uuid'))
        else:
            import uuid
            self.uuid = str(uuid.uuid4())
        if self.uuid.lower() not in ('', 'no', 'none', 'false', 'opt-out', 'optout'):
            # call home
            try:
                settings.setValue('uuid', QtCore.QVariant(self.uuid))
                url = 'https://www.sorobanexam.org/mentalcalculation/ping?uuid=%s&version=%s' % (self.uuid, appVersion)
                ret = urllib.request.urlopen(url)
                if ret.getcode() == 200:
                    latest_version = json.loads(ret.read())['latest']
                    if latest_version > appVersion:
                        self.ui.statusbar.showMessage('A new version is available at www.sorobanexam.org/anzan.html')
                # stop tracking if url returns 404
                if ret.getcode() == 404:
                    settings.setValue('uuid', QtCore.QVariant('opt-out'))
            except urllib.error.URLError:
                pass
    def importSettings(self):
        # restore settings from the settings file if the settings exist
        settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)
        if settings.contains('digits'):
            # these value have been written by the program, so then should be ok
            self.digits = int(settings.value('digits'))
            self.rows = int(settings.value('rows'))
            self.timeout = int(settings.value('timeout'))
            self.flash = int(settings.value('flash'))
            self.hands_free = eval(settings.value('hands_free').capitalize())
            self.neg = eval(settings.value('neg').capitalize())
            if settings.contains('no_plus_sign'):
                self.no_plus_sign = eval(settings.value('no_plus_sign').capitalize())

        # GUI settings
        if settings.contains('GUI/fullscreen'):
            self.fullscreen = eval(settings.value('GUI/fullscreen').capitalize())
        if settings.contains('GUI/font'):
            font = str(settings.value('GUI/font'))
            self.ui.label.setFont(QtGui.QFont(font, 72, QtGui.QFont.Bold))
        if settings.contains('GUI/font_color'):
            self.font_color = str(settings.value('GUI/font_color'))
        if settings.contains('GUI/background_color'):
            self.background_color = str(settings.value('GUI/background_color'))

        # Sound settings
        if settings.contains('Sound/speech'):
            self.speech = eval(settings.value('Sound/speech').capitalize())
        if settings.contains('Sound/one_digit'):
            self.one_digit = eval(settings.value('Sound/one_digit').capitalize())
        if settings.contains('Sound/annoying_sound'):
            self.annoying_sound = eval(settings.value('Sound/annoying_sound').capitalize())
        global LANG
        if settings.contains('Sound/lang'):
            LANG = str(settings.value('Sound/lang'))
            if LANG.find('_') > 0:
                LANG = LANG.replace('_','-').lower()

        # uuid
        self.uuid = ''
        if settings.contains('uuid'):
            self.uuid = str(settings.value('uuid'))
        else:
            import uuid
            self.uuid = str(uuid.uuid4())
        if self.uuid.lower() not in ('', 'no', 'none', 'false', 'opt-out', 'optout'):
            # call home
            try:
                settings.setValue('uuid', QtCore.QVariant(self.uuid))
                url = 'https://www.sorobanexam.org/mentalcalculation/ping?uuid=%s&version=%s' % (self.uuid, appVersion)
                ret = urllib.request.urlopen(url)
                if ret.getcode() == 200:
                    latest_version = json.loads(ret.read().decode('utf-8'))['latest']
                    if latest_version > appVersion:
                        self.ui.statusbar.showMessage('A new version is available at www.sorobanexam.org/anzan.html')
                # stop tracking if url returns 404
                if ret.getcode() == 404:
                    settings.setValue('uuid', QtCore.QVariant('opt-out'))
            except urllib.error.URLError:
                pass
    def updateFullScreen(self):
        self.fullscreen = not self.fullscreen
        settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)
        settings.setValue('GUI/fullscreen', QtCore.QVariant(self.fullscreen))

        if self.fullscreen:
            self.showFullScreen()
        else:
            self.showNormal()
    def updateFullScreen(self):
        self.fullscreen = not self.fullscreen
        settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)
        settings.setValue('GUI/fullscreen', QtCore.QVariant(self.fullscreen))

        if self.fullscreen:
            self.showFullScreen()
        else:
            self.showNormal()
    def changeSettings(self):
        if not self.started:
            mysettings = {}
            mysettings['flash'] = self.flash
            mysettings['timeout'] = self.timeout
            mysettings['digits'] = self.digits
            mysettings['rows'] = self.rows
            mysettings['speech'] = self.speech
            mysettings['fullscreen'] = self.fullscreen
            mysettings['hands_free'] = self.hands_free
            mysettings['one_digit'] = self.one_digit
            mysettings['neg'] = self.neg
            s = Settings(mysettings, parent=self)
            s.ui.cb_fullscreen.stateChanged.connect(self.updateFullScreen)
            ok, mysettings = s.exec_()
            if ok:
                self.flash = mysettings['flash']
                self.timeout = mysettings['timeout']
                if mysettings['digits'] != self.digits:
                    # resize font
                    font = self.ui.label.font()
                    # width is the size of of '+9999' in the current font
                    width = QtGui.QFontMetrics(font).width('+'+'9'*(mysettings['digits']+2))
                    # the factor to multiply by to use the max. space
                    factor = float(self.ui.gb_number.width())/width
                    newPointSize = min(int(font.pointSize()*factor), self.ui.gb_number.height())
                    font.setPointSize(newPointSize)
                    self.ui.label.setFont(font)
                self.digits = mysettings['digits']
                self.rows = mysettings['rows']
                self.speech = mysettings['speech']
                self.one_digit = mysettings['one_digit']
                self.hands_free = mysettings['hands_free']
                self.neg = mysettings['neg']
                # always save settings when closing the settings dialog
                settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)
                settings.setValue('digits', QtCore.QVariant(self.digits))
                settings.setValue('rows', QtCore.QVariant(self.rows))
                settings.setValue('timeout', QtCore.QVariant(self.timeout))
                settings.setValue('flash', QtCore.QVariant(self.flash))
                settings.setValue('hands_free', QtCore.QVariant(self.hands_free))
                settings.setValue('neg', QtCore.QVariant(self.neg))
                settings.setValue('no_plus_sign', QtCore.QVariant(self.no_plus_sign))

                settings.setValue('GUI/font_color', QtCore.QVariant(self.font_color if self.font_color is not None else '#000000'))
                settings.setValue('GUI/background_color', QtCore.QVariant(self.background_color \
                        if self.background_color is not None else 'transparent'))

                settings.setValue('Sound/lang', QtCore.QVariant(LANG))
                settings.setValue('Sound/one_digit', QtCore.QVariant(self.one_digit))
                settings.setValue('Sound/speech', QtCore.QVariant(self.speech))
                settings.setValue('Sound/annoying_sound', QtCore.QVariant(self.annoying_sound))

                # disable replay button
                self.ui.pb_replay.setEnabled(False)
    def changeSettings(self):
        if not self.started:
            mysettings = {}
            mysettings['flash'] = self.flash
            mysettings['timeout'] = self.timeout
            mysettings['digits'] = self.digits
            mysettings['rows'] = self.rows
            mysettings['speech'] = self.speech
            mysettings['fullscreen'] = self.fullscreen
            mysettings['hands_free'] = self.hands_free
            mysettings['one_digit'] = self.one_digit
            mysettings['neg'] = self.neg
            s = Settings(mysettings, parent=self)
            s.ui.cb_fullscreen.stateChanged.connect(self.updateFullScreen)
            ok, mysettings = s.exec_()
            if ok:
                self.flash = mysettings['flash']
                self.timeout = mysettings['timeout']
                if mysettings['digits'] != self.digits:
                    # resize font
                    font = self.ui.label.font()
                    # width is the size of of '+9999' in the current font
                    width = QtGui.QFontMetrics(font).width('+'+'9'*(mysettings['digits']+2))
                    # the factor to multiply by to use the max. space
                    factor = float(self.ui.gb_number.width())/width
                    newPointSize = min(int(font.pointSize()*factor), self.ui.gb_number.height())
                    font.setPointSize(newPointSize)
                    self.ui.label.setFont(font)
                self.digits = mysettings['digits']
                self.rows = mysettings['rows']
                self.speech = mysettings['speech']
                self.one_digit = mysettings['one_digit']
                self.hands_free = mysettings['hands_free']
                self.neg = mysettings['neg']
                # always save settings when closing the settings dialog
                settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)
                settings.setValue('digits', QtCore.QVariant(self.digits))
                settings.setValue('rows', QtCore.QVariant(self.rows))
                settings.setValue('timeout', QtCore.QVariant(self.timeout))
                settings.setValue('flash', QtCore.QVariant(self.flash))
                settings.setValue('hands_free', QtCore.QVariant(self.hands_free))
                settings.setValue('neg', QtCore.QVariant(self.neg))
                settings.setValue('no_plus_sign', QtCore.QVariant(self.no_plus_sign))

                settings.setValue('GUI/font_color', QtCore.QVariant(self.font_color if self.font_color is not None else '#000000'))
                settings.setValue('GUI/background_color', QtCore.QVariant(self.background_color \
                        if self.background_color is not None else 'transparent'))

                settings.setValue('Sound/lang', QtCore.QVariant(LANG))
                settings.setValue('Sound/one_digit', QtCore.QVariant(self.one_digit))
                settings.setValue('Sound/speech', QtCore.QVariant(self.speech))
                settings.setValue('Sound/annoying_sound', QtCore.QVariant(self.annoying_sound))

                # disable replay button
                self.ui.pb_replay.setEnabled(False)
Ejemplo n.º 7
0
    def importSettings(self):
        # restore settings from the settings file if the settings exist
        settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, '%s' % appName, '%s' % appName)

        if settings.contains('digits'):
            # these value have been written by the program, so then should be ok
            self.digits = settings.value('digits').toInt()[0]
            self.rows = settings.value('rows').toInt()[0]
            self.timeout = settings.value('timeout').toInt()[0]
            self.flash = settings.value('flash').toInt()[0]
            self.hands_free = settings.value('hands_free').toBool()
            self.neg = settings.value('neg').toBool()
            if settings.contains('no_plus_sign'):
                self.no_plus_sign = settings.value('no_plus_sign').toBool()
        if 'Espeak' in settings.childGroups():
            global ESPEAK_CMD, ESPEAK_LANG, ESPEAK_SPEED, IS_ESPEAK_INSTALLED
            # test for every option
            if not IS_ESPEAK_INSTALLED and settings.contains('Espeak/cmd'):
                ESPEAK_CMD = str(settings.value('Espeak/cmd').toString()).strip('"')
                IS_ESPEAK_INSTALLED = os.path.isfile(ESPEAK_CMD)
            if settings.contains('Espeak/lang'):
                ESPEAK_LANG = str(settings.value('Espeak/lang').toString())
                if ESPEAK_LANG.find('_') > 0:
                    ESPEAK_LANG = ESPEAK_LANG[:ESPEAK_LANG.index('_')]
            if settings.contains('Espeak/speed'):
                a,b = settings.value('Espeak/speed').toInt()
                # check if it's good
                if b:
                    ESPEAK_SPEED = a

        # GUI settings
        self.fullscreen = settings.value('GUI/fullscreen').toBool()
        if settings.contains('GUI/font'):
            font = str(settings.value('GUI/font').toString())
            self.ui.label.setFont(QtGui.QFont(font, 72, QtGui.QFont.Bold))
        if settings.contains('GUI/font_color'):
            self.font_color = str(settings.value('GUI/font_color').toString())
        if settings.contains('GUI/background_color'):
            self.background_color = str(settings.value('GUI/background_color').toString())

        # Sound settings
        self.speech = settings.value('Sound/speech').toBool()
        self.one_digit = settings.value('Sound/one_digit').toBool()
        if settings.contains('Sound/annoying_sound'):
            self.annoying_sound = settings.value('Sound/annoying_sound').toBool()

        # uuid
        self.uuid = ''
        if settings.contains('uuid'):
            self.uuid = str(settings.value('uuid').toString())
        else:
            import uuid
            self.uuid = str(uuid.uuid4())
        if self.uuid not in ('', 'no', 'none', 'false', 'No', 'None', 'False', 'opt-out', 'optout'):
            # call home
            try:
                settings.setValue('uuid', QtCore.QVariant(self.uuid))
                import urllib
                ret = urllib.urlopen('http://sorobanexam.org/mentalcalculation/ping?uuid=%s' % self.uuid)
                # stop tracking if url returns 404
                if ret.getcode() == 404:
                    settings.setValue('uuid', QtCore.QVariant('opt-out'))
            except IOError:
                pass