示例#1
0
 def test_store_variables(self):
     db = statistics.DB()
     db.set_variable('database_version', 2)
     self.assertEqual(db.get_variable('database_version'), 2)
     db.set_variable('database_version', 3)
     self.assertEqual(db.get_variable('database_version'), 3)
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'database_version', '3')
     db.set_variable('textvar', 'this is кофе')
     self.assertEqual(db.get_variable('textvar'), 'this is кофе')
     # Variables should not change type
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'textvar', 5)
     # Variables should not change type
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'textvar', 5.5)
     # Variables should not change type
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'textvar', True)
     # only str is allowed, not str
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'str_text', b'bytestring')
     db.set_variable('known_number', 3.14159265)
     self.assertEqual(db.get_variable('known_number'), 3.14159265)
     self.assertRaises(db.VariableUndefinedError,
         db.get_variable, 'e')
     db.del_variable('known_number')
     self.assertRaises(db.VariableUndefinedError,
         db.del_variable, 'does_not_exist')
示例#2
0
 def test_store_variables(self):
     db = statistics.DB()
     db.set_variable('database_version', 2)
     self.assertEquals(db.get_variable('database_version'), 2)
     db.set_variable('database_version', 3)
     self.assertEquals(db.get_variable('database_version'), 3)
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'database_version', '3')
     db.set_variable('textvar', u'this is кофе')
     self.assertEquals(db.get_variable('textvar'), u'this is кофе')
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'textvar', 5)
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'textvar', 5.5)
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'textvar', True)
     self.assertRaises(db.VariableTypeError,
         db.set_variable, 'str_text', 'string')
     db.set_variable('known_number', 3.14159265)
     self.assertEquals(db.get_variable('known_number'), 3.14159265)
     self.assertRaises(db.VariableUndefinedError,
         db.get_variable, 'e')
     db.del_variable('known_number')
     self.assertRaises(db.VariableUndefinedError,
         db.del_variable, 'does_not_exist')
示例#3
0
 def open_profile_manager(self, widget=None):
     p = ChangeProfileDialog(self, solfege.app.m_options.profile)
     if p.run() == Gtk.ResponseType.ACCEPT:
         prof = p.get_profile()
     else:
         # The user presses cancel. This will use the same profile as
         # before, but if the user has renamed the active profile, then
         # we need to use the new name.
         prof = p.m_default_profile
     p.destroy()
     solfege.app.reset_exercise()
     solfege.app.m_options.profile = prof
     solfege.db.conn.commit()
     solfege.db.conn.close()
     if prof is None:
         prof = ''
     solfege.db = statistics.DB(None, profile=prof)
     cfg.set_string("app/last_profile", prof)
     self.display_frontpage()
示例#4
0
def start_gui(datadir):
    if not options.profile:
        if cfg.get_bool("app/noprofilemanager"):
            options.profile = cfg.get_string("app/last_profile")
        elif do_profiles():
            if solfege.splash_win:
                solfege.splash_win.hide()
            p = ProfileManager(cfg.get_string("app/last_profile"))
            ret = p.run()
            if ret == Gtk.ResponseType.ACCEPT:
                options.profile = p.get_profile()
                cfg.set_string("app/last_profile",
                               "" if not options.profile else options.profile)
            elif ret in (Gtk.ResponseType.CLOSE,
                         Gtk.ResponseType.DELETE_EVENT):
                Gtk.main_quit()
                return
            p.destroy()
            if solfege.splash_win:
                solfege.splash_win.show()

    cfg.set_bool('config/no_random', bool(options.no_random))

    lessonfile.infocache = lessonfile.InfoCache()

    def f(s):
        if solfege.splash_win:
            solfege.splash_win.show_progress(s)

    if solfege.splash_win:
        solfege.splash_win.show_progress(_("Opening statistics database"))
    try:
        solfege.db = statistics.DB(f, profile=options.profile)
    except sqlite3.OperationalError, e:
        solfege.splash_win.hide()
        gu.dialog_ok(
            _(u"Failed to open the statistics database:\n«%s»") %
            str(e).decode(sys.getfilesystemencoding(), 'replace'),
            secondary_text=
            _("Click OK to exit the program. Then try to quit all other instances of the program, or reboot the computer. You can only run one instance of GNU Solfege at once."
              ))
        sys.exit()