当前位置: 首页>>代码示例>>Python>>正文


Python translator._函数代码示例

本文整理汇总了Python中mnemosyne.libmnemosyne.translator._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: backup_old_dir

    def backup_old_dir(self):  # pragma: no cover
        join = os.path.join
        # We only do this on OSX, since on the other platforms, we use a
        # different directory anyway.
        if sys.platform == "darwin":
            home = os.path.expanduser("~")
            old_data_dir = join(unicode(home), "Library", "Mnemosyne")
            backup_dir = join(unicode(home), "Library", "Mnemosyne_1")
            # Work around os.path.exists seeming to give wrong results on
            # OSX 10.6 (but not 10.7).
            if os.path.exists(join(old_data_dir, "default.db")):
                # Data was already backed up.
                return
            if os.path.exists(old_data_dir):
                if not os.path.exists(backup_dir):
                    old_files = sorted(os.listdir(old_data_dir))
                    shutil.move(old_data_dir, backup_dir)
                    new_files = sorted(os.listdir(backup_dir))
                    assert old_files == new_files
                    self.main_widget().show_information(\
                _("Your old 1.x files are now stored here:\n\n" + backup_dir))
                else:
                    self.main_widget().show_error(\
_("Tried to backup your old 1.x files to %s, but that directory already exists.") \
                    % (backup_dir,))
                    sys.exit()
开发者ID:tbabej,项目名称:mnemosyne,代码行数:26,代码来源:upgrade1.py

示例2: show_save_file_as_dialog

    def show_save_file_as_dialog(self):
        self.stopwatch().pause()
        if self.config()["single_database_help_shown"] == False:
            self.main_widget().show_information(_(self.single_database_help))
            self.config()["single_database_help_shown"] = True
        self.flush_sync_server()
        suffix = self.database().suffix
        old_path = expand_path(self.config()["last_database"], self.config().data_dir)
        old_media_dir = self.database().media_dir()
        filename = self.main_widget().get_filename_to_save(path=old_path,
            filter=_("Mnemosyne databases") + " (*%s)" % suffix)
        if not filename:
            self.stopwatch().unpause()
            return
        if filename.endswith("config.db"):
            self.main_widget().show_information(\
_("The configuration database cannot be used to store cards."))
            self.stopwatch().unpause()
            return          
        if not filename.endswith(suffix):
            filename += suffix
        try:
            self.database().save(filename)
            new_media_dir = self.database().media_dir()
            if old_media_dir == new_media_dir:
                return
            if os.path.exists(new_media_dir):
                shutil.rmtree(new_media_dir)
            shutil.copytree(old_media_dir, new_media_dir)
            self.log().saved_database()
        except RuntimeError, error:
            self.main_widget().show_error(unicode(error.message))
            self.stopwatch().unpause()
            return
开发者ID:tbabej,项目名称:mnemosyne,代码行数:34,代码来源:default_controller.py

示例3: show_download_source_dialog

    def show_download_source_dialog(self):

        """The following code is here to be able to enforce the AGPL licence.

        If you run Mnemosyne as a service over the network, you need to provide
        users the option to download your modified version of libmnemosyne and
        the Mnemosyne HTML server.

        The recommended way to do this is to provide a link at the bottom of
        the webpage saying "Flash cards by Mnemosyne", with "Mnemosyne" a link
        taking you to a page with download instructions for the copy of
        Mnemosyne you are using.

        Even if you are using an unmodified version of Mnemosyne, you should
        still host a copy of that source code on your site, in order to set an
        example for people who do modify the source.

        """

        self.stopwatch().pause()
        self.flush_sync_server()
        self.main_widget().show_information(\
            _("For instructions on how to download Mnemosyne's source,") + \
            " " + _("go to http://www.mnemosyne-proj.org"))
        self.stopwatch().unpause()
开发者ID:tbabej,项目名称:mnemosyne,代码行数:25,代码来源:default_controller.py

示例4: edit_card_and_sisters

 def edit_card_and_sisters(self, card, new_fact_data, new_card_type,
         new_tag_names, correspondence):
     db = self.database()
     sch = self.scheduler()
     assert new_card_type.is_fact_data_valid(new_fact_data)
     # Determine the current tags in use for the sister cards. This
     # needs to be done before e.g. editing a cloze card creates new
     # cards which are as yet untagged.
     fact = db.fact(card.fact._id, is_id_internal=True)
     current_sister_cards = self.database().cards_from_fact(fact)
     current_tag_strings = set([sister_card.tag_string() \
         for sister_card in current_sister_cards])        
     # Change the card type if needed. This does not take into account
     # changes to fact yet, which will come just afterwards.
     result = self._change_card_type(card.fact, card.card_type,
         new_card_type, correspondence, new_fact_data)
     if result in [-2, -1]:  # Error, aborted.
         return result
     # When there was no card type conversion possible, the cards had to
     # be recreated from the new fact data. In that case, it is needed to
     # reload the fact from the database.
     fact = db.fact(card.fact._id, is_id_internal=True)
     # Update fact and create, delete and update cards.
     new_cards, edited_cards, deleted_cards = \
         new_card_type.edit_fact(fact, new_fact_data)
     fact.data = new_fact_data
     db.update_fact(fact)
     for deleted_card in deleted_cards:
         if self.review_controller().card == deleted_card:
             self.review_controller().card = None
         sch.remove_from_queue_if_present(deleted_card)
         db.delete_card(deleted_card)
     for new_card in new_cards:
         db.add_card(new_card)
     for edited_card in edited_cards:
         db.update_card(edited_card)
     if new_cards and self.review_controller().learning_ahead == True:
         self.review_controller().reset()
     # Apply new tags and modification time to cards and save them back to
     # the database. Note that this makes sure there is an EDITED_CARD log
     # entry for each sister card, which is needed when syncing with a
     # partner that does not have the concept of facts.
     tag_for_current_card_only = False
     if len(current_tag_strings) > 1:
         tag_for_current_card_only = bool(self.main_widget().show_question(
         _("This card has different tags than its sister cards. Update tags for current card only or for all sister cards?"),
         _("Current card only"), _("All sister cards"), "") == 0)
     old_tags = set()
     tags = db.get_or_create_tags_with_names(new_tag_names)
     modification_time = int(time.time())
     for sister_card in self.database().cards_from_fact(fact):
         sister_card.modification_time = modification_time
         if sister_card == card or not tag_for_current_card_only:
             old_tags = old_tags.union(sister_card.tags)
             sister_card.tags = tags
         db.update_card(sister_card)
     for tag in old_tags:
         db.delete_tag_if_unused(tag)
     db.save()
     return 0
开发者ID:tbabej,项目名称:mnemosyne,代码行数:60,代码来源:default_controller.py

示例5: delete_facts_and_their_cards

 def delete_facts_and_their_cards(self, facts, progress_bar=True):
     assert len(facts) == len([fact.id for fact in facts])
     db = self.database()
     w = self.main_widget()
     if progress_bar:
         w.set_progress_text(_("Deleting cards..."))
         w.set_progress_range(len(facts))
         w.set_progress_update_interval(50)
     for fact in facts:
         for card in db.cards_from_fact(fact):
             self.scheduler().remove_from_queue_if_present(card)
             db.delete_card(card, check_for_unused_tags=False)
         db.delete_fact(fact)
         if progress_bar:
             w.increase_progress(1)
     tags = db.tags()
     if progress_bar:
         w.set_progress_text(_("Checking for unused tags..."))
         w.set_progress_range(len(tags))
     tags = db.tags()
     for tag in tags:
         db.delete_tag_if_unused(tag)
         if progress_bar:
             w.increase_progress(1)
     db.save()
     if progress_bar:
         w.close_progress()
开发者ID:tbabej,项目名称:mnemosyne,代码行数:27,代码来源:default_controller.py

示例6: initialise_card_types_combobox

 def initialise_card_types_combobox(self, current_card_type_name):
     # We calculate card_type_by_name here because these names can change
     # if the user chooses another translation.
     self.card_type_by_name = {}
     self.card_type = None
     self.card_type_index = 0
     self.card_type_widget = None
     self.previous_tags = None
     self.previous_card_type_name = current_card_type_name
     db_sorted_card_types = self.database().sorted_card_types()
     for card_type in db_sorted_card_types:
         if _(card_type.name) == current_card_type_name:
             self.card_type = card_type
             self.card_type_index = self.card_types_widget.count()
         self.card_type_by_name[_(card_type.name)] = card_type
         self.card_types_widget.addItem(_(card_type.name))
     if not self.card_type:
         self.card_type = db_sorted_card_types[0]
         self.card_type_index = 0
     self.card_types_widget.setCurrentIndex(self.card_type_index)
     # Now that the combobox is filled, we can connect the signal.
     self.card_types_widget.currentIndexChanged[QtCore.QString].\
         connect(self.card_type_changed)
     self.correspondence = {}  # Used when changing card types.
     self.update_card_widget()
开发者ID:tbabej,项目名称:mnemosyne,代码行数:25,代码来源:add_cards_dlg.py

示例7: initialise

    def initialise(self, data_dir=None, config_dir=None,
                   filename=None, automatic_upgrades=True, debug_file=None, 
                   server_only=False):

        """The automatic upgrades of the database can be turned off by setting
        'automatic_upgrade' to False. This is mainly useful for the testsuite.

        """

        if debug_file:
            self.component_manager.debug_file = open(debug_file, "w", 0)
        self.register_components()
        # Upgrade from 1.x if needed.
        if automatic_upgrades:
            from mnemosyne.libmnemosyne.upgrades.upgrade1 import Upgrade1
            Upgrade1(self.component_manager).backup_old_dir()
        if data_dir:
            self.config().data_dir = data_dir
            self.config().config_dir = data_dir
        if config_dir:
            self.config().config_dir = config_dir
        # Upgrade config if needed.
        if automatic_upgrades:
            from mnemosyne.libmnemosyne.upgrades.upgrade3 import Upgrade3
            Upgrade3(self.component_manager).run() 
        self.activate_components()
        register_component_manager(self.component_manager,
            self.config()["user_id"])
        self.execute_user_plugin_dir()
        self.activate_saved_plugins()
        # If we are only running a sync or a review server, do not yet load
        # the database to prevent threading access issues.
        if server_only:
            if filename:
                self.config()["last_database"] = \
                    contract_path(filename, self.config().data_dir)
            return
        # Loading the database should come after all user plugins have been
        # loaded, since these could be needed e.g. for a card type in the
        # database.
        if filename and not filename.endswith(".db"):
            from mnemosyne.libmnemosyne.translator import _
            self.main_widget().show_error(\
                _("Command line argument is not a *.db file."))
            sys.exit()
        self.load_database(filename)
        # Only now that the database is loaded, we can start writing log
        # events to it. This is why we log started_scheduler and
        # loaded_database manually.
        try:
            self.log().started_program()
        except Exception, e:
            if "lock" in str(e):
                from mnemosyne.libmnemosyne.translator import _
                self.main_widget().show_error(\
                 _("Another copy of Mnemosyne is still running.") + "\n" + \
                 _("Continuing is impossible and will lead to data loss!"))
                sys.exit()
            else:
                raise e
开发者ID:tbabej,项目名称:mnemosyne,代码行数:60,代码来源:__init__.py

示例8: add_card_type_from_log_entry

 def add_card_type_from_log_entry(self, log_entry):
     already_imported = self.con.execute(\
         "select count() from card_types where id=?",
         (log_entry["o_id"], )).fetchone()[0] != 0
     if "name" not in log_entry:
         log_entry["name"] = "dummy"  # Added and immediately deleted.
     same_name_in_database = self.con.execute(\
         "select count() from card_types where name=? and id!=?",
         (log_entry["name"], log_entry["o_id"] )).fetchone()[0] == 1
     if same_name_in_database:
         # Merging with the card type which is already in the database
         # is more difficult, as then the card type links in the cards
         # would need to be updated.
         if self.importing:  # Don't interrupt sync with dialog.
             self.main_widget().show_information(\
 _("Card type '%s' already in database, renaming new card type to '%s (1)'" \
             % (log_entry["name"], log_entry["name"])))
         log_entry["name"] += " (1)"
     if already_imported and self.importing:
         log_entry["type"] = EventTypes.EDITED_CARD_TYPE
         return self.update_card_type(\
             self.card_type_from_log_entry(log_entry))
     try:
         card_type = self.card_type_from_log_entry(log_entry)
         self.activate_plugins_for_card_type_with_id(card_type.id)
         self.add_card_type(card_type)
     except sqlite3.IntegrityError:
         # Leftover from old bug, should not reoccur.
         self.main_widget().show_information(\
 _("Creating same card type twice during sync. Inform the developpers."))            
开发者ID:tbabej,项目名称:mnemosyne,代码行数:30,代码来源:SQLite_sync.py

示例9: __init__

 def __init__(self, component_manager, parent):
     ConfigurationWidget.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     sync_port = self.config()["sync_server_port"]
     web_port = self.config()["web_server_port"]
     self.sync_server_initially_running = self.is_server_running(sync_port)
     self.web_server_initially_running = self.is_server_running(web_port)
     self.run_sync_server.setChecked(self.config()["run_sync_server"])
     self.sync_port.setValue(sync_port)
     self.username.setText(self.config()["remote_access_username"])
     self.password.setText(self.config()["remote_access_password"])
     self.check_for_edited_local_media_files.setChecked(\
         self.config()["check_for_edited_local_media_files"])
     self.run_web_server.setChecked(self.config()["run_web_server"])
     self.web_port.setValue(web_port)
     if self.is_server_running(sync_port):
         self.sync_server_status.setText(_("Sync server running on ") + \
             localhost_IP() + " .")
     else:
         self.sync_server_status.setText(_("Sync server NOT running."))
     if self.is_server_running(web_port):
         self.web_server_status.setText(_("Web server running on ") + \
            "http://" + localhost_IP() + ":" + str(web_port) + " .")
     else:
         self.web_server_status.setText(_("Web server NOT running."))
开发者ID:tbabej,项目名称:mnemosyne,代码行数:26,代码来源:configuration_wdgt_servers.py

示例10: build_plugin_list

 def build_plugin_list(self):
     plugin_dir = os.path.join(self.config().data_dir, "plugins")
     self.can_be_deleted = [filename.rsplit(".", 1)[0] for \
         filename in os.listdir(plugin_dir) \
         if filename.endswith(".manifest")]
     self.plugin_list.clear()
     self.previously_active = {}
     self.plugin_with_name = {}
     for plugin in self.plugins():
         list_item = QtGui.QListWidgetItem(_(plugin.name))
         list_item.setFlags(list_item.flags() \
             | QtCore.Qt.ItemIsUserCheckable)
         self.plugin_with_name[_(plugin.name)] = plugin
         active = \
             plugin.__class__.__name__ in self.config()["active_plugins"]
         self.previously_active[_(plugin.name)] = active
         if active:
             list_item.setCheckState(QtCore.Qt.Checked)
         else:
             list_item.setCheckState(QtCore.Qt.Unchecked)
         self.plugin_list.addItem(list_item)
     self.plugin_list.setCurrentRow(self.last_selected_row)
     self.plugin_description.setText(_(self.plugins()[0].description))
     self.delete_button.setEnabled(\
         self.plugins()[0].__class__.__name__ in self.can_be_deleted)
开发者ID:tbabej,项目名称:mnemosyne,代码行数:25,代码来源:manage_plugins_dlg.py

示例11: save_set

 def save_set(self):
     criterion = self.tab_widget.currentWidget().criterion()
     if criterion.is_empty():
         self.main_widget().show_error(_("This set can never contain any cards!"))
         return
     CardSetNameDlg(self.component_manager, criterion, self.criteria_by_name.keys(), self).exec_()
     if not criterion.name:  # User cancelled.
         return
     if criterion.name in self.criteria_by_name.keys():
         answer = self.main_widget().show_question(_("Update this set?"), _("&OK"), _("&Cancel"), "")
         if answer == 1:  # Cancel.
             return
         original_criterion = self.criteria_by_name[criterion.name]
         criterion._id = original_criterion._id
         criterion.id = original_criterion.id
         self.database().update_criterion(criterion)
     else:
         self.database().add_criterion(criterion)
     self.update_saved_sets_pane()
     item = self.saved_sets.findItems(criterion.name, QtCore.Qt.MatchExactly)[0]
     self.saved_sets.setCurrentItem(item)
     if self.config()["showed_help_on_renaming_sets"] == False:
         self.main_widget().show_information(
             _("You can right-click on the name of a saved set to rename or delete it.")
         )
         self.config()["showed_help_on_renaming_sets"] = True
开发者ID:tbabej,项目名称:mnemosyne,代码行数:26,代码来源:activate_cards_dlg.py

示例12: run

    def run(self):
        # Use shown_question here, since this is implemented to block.
        answer = self.main_widget().show_question(\
_("About to archive old logs to improve running speed. Depending on the size of your database and the speed of your device, this can take 10 minutes or more. Please leave Mnemosyne running in the foreground."),
        _("OK, proceed"), "", "")
        if answer == 0:
            DatabaseMaintenance.run(self)
开发者ID:tbabej,项目名称:mnemosyne,代码行数:7,代码来源:database_maintenance.py

示例13: grade_answer

    def grade_answer(self, grade):

        """Note that this also pulls in a new question."""
        
        card_to_grade = self.card
        old_grade = card_to_grade.grade
        self.update_counters(old_grade, grade)
        self.rep_count += 1
        if self.scheduler().allow_prefetch():
            self.new_question()
            interval = self.scheduler().grade_answer(card_to_grade, grade)
            self.database().update_card(card_to_grade, repetition_only=True)
            if self.rep_count % self.config()["save_after_n_reps"] == 0:
                self.database().save()
        else:
            interval = self.scheduler().grade_answer(card_to_grade, grade)
            self.database().update_card(card_to_grade, repetition_only=True)
            if self.rep_count % self.config()["save_after_n_reps"] == 0:
                self.database().save()
            self.new_question()     
        if self.config()["show_intervals"] == "status_bar":
            import math
            days = int(math.ceil(interval / (24.0 * 60 * 60)))
            self.widget.update_status_bar(_("Returns in") + " " + \
                  str(interval) + _(" day(s)."))
开发者ID:bartosh,项目名称:pomni,代码行数:25,代码来源:SM2_controller.py

示例14: reset_to_defaults

 def reset_to_defaults(self):
     answer = self.main_widget().show_question(\
         _("Reset current tab to defaults?"), _("&Yes"), _("&No"), "")
     if answer == 1:
         return
     self.order.setCurrentIndex(0)
     self.store_state.setCheckState(QtCore.Qt.Checked)
开发者ID:tbabej,项目名称:mnemosyne,代码行数:7,代码来源:configuration_wdgt_cramming.py

示例15: next_rep_string

 def next_rep_string(self, days):
     if days == 0:
         return '\n' + _("Next repetition: today.")
     elif days == 1:
         return '\n' + _("Next repetition: tomorrow.")
     else:
         return '\n' + _("Next repetition in ") + str(days) + _(" days.")
开发者ID:tbabej,项目名称:mnemosyne,代码行数:7,代码来源:SM2_controller.py


注:本文中的mnemosyne.libmnemosyne.translator._函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。