Ejemplo n.º 1
0
#

from PyQt5 import QtCore, QtGui

from mnemosyne.libmnemosyne.plugin import Plugin


class HideToolbarPlugin(Plugin):

    name = "Hide toolbar"
    description = "Hide the main toolbar"
    supported_API_level = 2

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)

    def activate(self):
        Plugin.activate(self)
        self.main_widget().tool_bar.setVisible(False)

    def deactivate(self):
        Plugin.deactivate(self)
        self.main_widget().tool_bar.setVisible(True)


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(HideToolbarPlugin)

Ejemplo n.º 2
0

class ResponsiveVoiceTTSPlugin(Plugin):

    name = "Responsive Voice TTS"
    description = "Add ResponsiveVoice text-to-speech."
    supported_API_level = 2

    def activate(self):
        Plugin.activate(self)
        self.component = ResponsiveVoicePronouncer(\
            component_manager=self.component_manager)
        self.component_manager.register(self.component)
        # TODO: refactor this to plugin.py
        gui_module_name = "mnemosyne.pyqt_ui.pronouncer_dlg"
        gui_class_name = "PronouncerDlg"
        gui_class = getattr(\
            importlib.import_module(gui_module_name), gui_class_name)
        self.component_manager.add_gui_to_component(\
            "ResponsiveVoicePronouncer", gui_class)

    def deactivate(self):
        Plugin.deactivate(self)
        self.component_manager.unregister(self.component)


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ResponsiveVoiceTTSPlugin)
Ejemplo n.º 3
0
                self.main_widget.show_error("Unable to open ", filename)
            self.last_filename = filename
            i = text.lower().find(self.tag_name + " src", i + 1)
        return text


class CustomTagPlugin(Plugin):

    name = "Custom tag"
    description = "Intercepts custom tags like <my_tag src=\"filename\"> and runs them in an external program.\n\nEdit the source to customise."
    components = [CustomTag]
    supported_API_level = 3

    def activate(self):
        Plugin.activate(self)
        self.render_chain("default").\
            register_filter(CustomTag, in_front=False)
        # Other chain you might want to add to is e.g. "card_browser".

    def deactivate(self):
        Plugin.deactivate(self)
        self.render_chain("default").\
            unregister_filter(CustomTag)


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin

register_user_plugin(CustomTagPlugin)
Ejemplo n.º 4
0
class RedCardTypeWdgt(GenericCardTypeWdgt):

    component_type = "card_type_widget"
    used_for = FrontToBack

    def __init__(self, **kwds):
        super().__init__(**kwds)
        for edit_box in self.edit_boxes:
            p = QtGui.QPalette()
            p.setColor(QtGui.QPalette.Active, QtGui.QPalette.Base, \
                       QtGui.QColor("red"))
            edit_box.setPalette(p)


# Wrap it into a Plugin and then register the Plugin.

class RedPlugin(Plugin):
    
    name = "Red"
    description = "Red widget for front-to-back cards"
    components = [RedCardTypeWdgt]
    supported_API_level = 2

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(RedPlugin)




Ejemplo n.º 5
0
    name = "My html staticsics"

    def prepare_statistics(self, variant):
        card = self.review_controller().card
        self.html = """<html<body>
        <style type="text/css">
        table { height: 100%;
                margin-left: auto; margin-right: auto;
                text-align: center}
        body  { background-color: white;
                margin: 0;
                padding: 0;
                border: thin solid #8F8F8F; }
        </style></head><table><tr><td>"""
        self.html += "There are lies, damn lies and statistics."
        self.html += "</td></tr></table></body></html>"


# Wrap it into a Plugin and then register the Plugin.


class MyHtmlStatisticsPlugin(Plugin):
    name = "Html statistics example"
    description = "Example plugin for html statistics"
    components = [MyHtmlStatistics]


from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(MyHtmlStatisticsPlugin)
Ejemplo n.º 6
0
            return
        self.activate()
        # Pie charts look better on a square canvas.
        self.axes.set_aspect('equal')
        labels = ["Unseen" if self.page.y[0] > 0 else ""] + \
            ["Grade %d" % (g-1) if self.page.y[g] > 0 \
            else "" for g in range(1, 7)]
        colors = ["w", "r", "m", "y", "g", "c", "b"]
        # Only print percentage on wedges > 5%.
        autopct = lambda x: "%1.1f%%" % x if x > 5 else ""
        self.axes.pie(self.page.y,
                      labels=labels,
                      colors=colors,
                      shadow=True,
                      autopct=autopct)
        self.axes.set_title("Number of cards")


# Wrap it into a Plugin and then register the Plugin.


class PieChartPlugin(Plugin):
    name = "Pie chart grades"
    description = "Show the grade statistics in a pie chart"
    components = [MyGrades, PieChartWdgt]
    supported_API_level = 3


from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(PieChartPlugin)
Ejemplo n.º 7
0
class MyHtmlStatistics(HtmlStatisticsPage):

    name = "My html staticsics"
        
    def prepare_statistics(self, variant):
        card = self.review_controller().card
        self.html = """<html<body>
        <style type="text/css">
        table { height: 100%;
                margin-left: auto; margin-right: auto;
                text-align: center}
        body  { background-color: white;
                margin: 0;
                padding: 0;
                border: thin solid #8F8F8F; }
        </style></head><table><tr><td>"""  
        self.html += "There are lies, damn lies and statistics."
        self.html += "</td></tr></table></body></html>"


# Wrap it into a Plugin and then register the Plugin.

class MyHtmlStatisticsPlugin(Plugin):
    name = "Html statistics example"
    description = "Example plugin for html statistics"
    components = [MyHtmlStatistics]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(MyHtmlStatisticsPlugin)
Ejemplo n.º 8
0
            render_chain.renderer_for_card_type(card.card_type).\
                update(card.card_type)
        return text


class CatColorPlugin(Plugin):

    name = "Category Colors"
    description = "Change the background color depending on the category"
    components = [CatColorReplacer]
    supported_API_level = 2

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)

    def activate(self):
        Plugin.activate(self)
        self.render_chain("default").\
            register_filter(CatColorReplacer, in_front=True)

    def deactivate(self):
        Plugin.deactivate(self)
        self.render_chain("default").\
            unregister_filter(CatColorReplacer)


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(CatColorPlugin)
Ejemplo n.º 9
0
#
# after_repetition.py <*****@*****.**>
#

from mnemosyne.libmnemosyne.hook import Hook
from mnemosyne.libmnemosyne.plugin import Plugin


class Grade5DetectionHook(Hook):

    used_for = "after_repetition"

    def run(self, card):
        if card.grade == 5:
            self.main_widget().information_box("This was an easy card!")


class AfterRepetitionPlugin(Plugin):
    
    name = "Grade 5 detection"
    description = "Notice when a card is given grade 5."   
    components = [Grade5DetectionHook]
      

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(AfterRepetitionPlugin)


Ejemplo n.º 10
0
from PyQt4 import QtCore, QtGui
from mnemosyne.libmnemosyne.plugin import Plugin

class HideToolbarPlugin(Plugin):

    name = "Hide toolbar"
    description = "Hide the main toolbar"

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)

    def activate(self):
        Plugin.activate(self)
        self.main_widget().tool_bar.setVisible(False)

    def deactivate(self):
        Plugin.deactivate(self)
        self.main_widget().tool_bar.setVisible(True)


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(HideToolbarPlugin)
Ejemplo n.º 11
0
class RedCardTypeWdgt(GenericCardTypeWdgt):

    component_type = "card_type_widget"
    used_for = FrontToBack

    def __init__(self, component_manager, parent):
        card_type = FrontToBack(component_manager)
        GenericCardTypeWdgt.__init__(self, component_manager,
                                     parent, card_type)
        for edit_box in self.edit_boxes:
            p = QtGui.QPalette()
            p.setColor(QtGui.QPalette.Active, QtGui.QPalette.Base, \
                       QtGui.QColor("red"))
            edit_box.setPalette(p)


# Wrap it into a Plugin and then register the Plugin.

class RedPlugin(Plugin):
    
    name = "Red"
    description = "Red widget for front-to-back cards"
    components = [RedCardTypeWdgt]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(RedPlugin)




Ejemplo n.º 12
0
class ReverseArabicPlugin(Plugin):

    name = "Reverse Arabic"
    description = "Reverse the Arabic in the web server, to compensate for the fact that the Android browser renders Arabic from left to right."
    components = [ReverseArabic]

    def activate(self):
        Plugin.activate(self)
        try:
            self.render_chain("web_server").\
                register_filter(ReverseArabic, in_front=False)
            self.render_chain("web_server").\
                unregister_filter(NonLatinFontSizeIncrease)
        except KeyError:  # The web server chain is not active.
            pass

    def deactivate(self):
        Plugin.deactivate(self)
        try:
            self.render_chain("web_server").\
                unregister_filter(ReverseArabic)
            self.render_chain("web_server").\
                register_filter(NonLatinFontSizeIncrease, in_front=False)
        except KeyError:  # The web server chain is not active.
            pass

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ReverseArabicPlugin)
Ejemplo n.º 13
0
            try:
                subprocess.call(self.tag_program + [filename])
            except:
                self.main_widget.show_error("Unable to open ", filename)
            self.last_filename = filename
            i = text.lower().find(self.tag_name + " src", i + 1)
        return text


class CustomTagPlugin(Plugin):

    name = "Custom tag"
    description = "Intercepts custom tags like <my_tag src=\"filename\"> and runs them in an external program.\n\nEdit the source to customise."
    components = [CustomTag]

    def activate(self):
        Plugin.activate(self)
        self.render_chain("default").\
            register_filter(CustomTag, in_front=False)
        # Other chain you might want to add to is e.g. "card_browser".

    def deactivate(self):
        Plugin.deactivate(self)
        self.render_chain("default").\
            unregister_filter(CustomTag)

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(CustomTagPlugin)
Ejemplo n.º 14
0
        self.vlayout.addLayout(self.hlayout)
            
    def reset_to_defaults(self):
        self.my_value.setValue(10)
        
    def apply(self):
        self.config()["my_value"] = self.my_value.value()


# The actual plugin.

class SettingsExamplePlugin(Plugin):
    
    name = "Settings example"
    description = "Example on how to store settings for your plugin"
    components = [MyPluginConfiguration, MyConfigurationWdgt]
    
    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)
        
    def activate(self):
        Plugin.activate(self)
        self.main_widget().show_information("My value is %d" % \
                                           self.config()["my_value"]) 


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(SettingsExamplePlugin)
Ejemplo n.º 15
0
    name = "Reverse Arabic"
    description = "Reverse the Arabic in the web server, to compensate for the fact that the Android browser renders Arabic from left to right."
    components = [ReverseArabic]

    def activate(self):
        Plugin.activate(self)
        try:
            self.render_chain("web_server").\
                register_filter(ReverseArabic, in_front=False)
            self.render_chain("web_server").\
                unregister_filter(NonLatinFontSizeIncrease)
        except KeyError:  # The web server chain is not active.
            pass

    def deactivate(self):
        Plugin.deactivate(self)
        try:
            self.render_chain("web_server").\
                unregister_filter(ReverseArabic)
            self.render_chain("web_server").\
                register_filter(NonLatinFontSizeIncrease, in_front=False)
        except KeyError:  # The web server chain is not active.
            pass


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ReverseArabicPlugin)
Ejemplo n.º 16
0
    
        self.auto_focus_grades = False

        # Change shortcuts for the grade buttons.

        self.grade_0_button.setShortcut("q")
        self.grade_1_button.setShortcut("w")
        self.grade_2_button.setShortcut("e")
        self.grade_3_button.setShortcut("r")
        self.grade_4_button.setShortcut("t")
        self.grade_5_button.setShortcut("y")

        # Some more examples.

        #self.grade_0_button.setShortcut("Enter") # Numerical keypad
        #self.grade_1_button.setShortcut("Space")
        #self.grade_2_button.setShortcut("Return") 


class ShortcutsPlugin(Plugin):

    name = "Custom shortcuts"
    description = "Customise review widget shortcuts."
    components = [MyReviewWdgt]


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ShortcutsPlugin)
Ejemplo n.º 17
0
    # Recognition.
    v1 = FactView(_("Recognition"), "3::1")
    v1.q_fact_keys = ["f"]
    v1.a_fact_keys = ["p_1", "m_1", "n"]
    v1.q_fact_key_decorators = {"f": "What is the translation of ${f}?"}
    
    # Production.
    v2 = FactView(_("Production"), "3::2")
    v2.q_fact_keys = ["m_1"]
    v2.a_fact_keys = ["f", "p_1", "n"]
    v2.q_fact_key_decorators = {"m_1": "How do you say ${m_1}?"}
    
    fact_views = [v1, v2]
    

# Wrap it into a Plugin and then register the Plugin.

class DecoratedVocabularyPlugin(Plugin):
    
    name = "Decorated vocabulary"
    description = "Vocabulary card type with some extra text"
    components = [DecoratedVocabulary]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(DecoratedVocabularyPlugin)




Ejemplo n.º 18
0
    def reset_to_defaults(self):
        self.my_value.setValue(10)

    def apply(self):
        self.config()["my_value"] = self.my_value.value()


# The actual plugin.


class SettingsExamplePlugin(Plugin):

    name = "Settings example"
    description = "Example on how to store settings for your plugin"
    components = [MyPluginConfiguration, MyConfigurationWdgt]

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)

    def activate(self):
        Plugin.activate(self)
        self.main_widget().show_information("My value is %d" % \
                                           self.config()["my_value"])


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(SettingsExamplePlugin)
Ejemplo n.º 19
0
from mnemosyne.libmnemosyne.hook import Hook
from mnemosyne.libmnemosyne.plugin import Plugin


class BackupHook(Hook):

    used_for = "after_backup"

    def run(self, backup_name):
        # Upload regular backup to a server.
        os.system("scp %s my.safe.server.com:" % backup_name)
        # Dump database to a text file (requires Python 2.6).
        with open('dump.sql', 'w') as f:
            for line in self.database().con.iterdump():
                f.write('%s\n' % line)


class BackupPlugin(Plugin):
    
    name = "Extra backup"
    description = "Move your backups to a safe place."   
    components = [BackupHook]
      

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(BackupPlugin)


Ejemplo n.º 20
0
work with future versions. [2]

[1] http://mnemosyne-proj.org/
[2] https://code.launchpad.net/~kevang/mnemosyne-proj/number_keys_show_answer
"""

from mnemosyne.libmnemosyne.plugin import Plugin
from mnemosyne.pyqt_ui.review_wdgt import ReviewWdgt


class ClumsyFingersReviewWdgt(ReviewWdgt):

    def __init__(self, component_manager):
        ReviewWdgt.__init__(self, component_manager)
    
        self.auto_focus_grades = False
        self.number_keys_show_answer = False


class ClumsyFingersPlugin(Plugin):

    name = "Clumsy Fingers"
    description = "Disable redundant shortcuts: space bar only shows answer, number keys only grade"
    components = [ClumsyFingersReviewWdgt]


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ClumsyFingersPlugin)
Ejemplo n.º 21
0
        elif hasattr(self.page, "LAST_6_MONTHS") and \
            variant == self.page.LAST_6_MONTHS:
            xticks = range(-180, -19, 20) + [0]
            xticklabels = ticklabels_neg(-180, -19, 20) + ["0"]
        elif hasattr(self.page, "LAST_YEAR") and \
            variant == self.page.LAST_YEAR:
            xticks = range(-360, -59, 60) + [0]
            xticklabels = ticklabels_neg(-360, -59, 60) + ["0"]
        else:
            raise AttributeError, "Invalid variant"
        # Plot data.
        self.axes.plot(self.page.x, self.page.y)
        self.axes.set_title(self.title)
        self.axes.set_xlabel(_("Days"))
        self.axes.set_xticks(xticks)
        self.axes.set_xticklabels(xticklabels)
        xmin, xmax = min(self.page.x), max(self.page.x)
        self.axes.set_xlim(xmin=xmin - 0.5, xmax=xmax + 0.5)

# Wrap it into a Plugin and then register the Plugin.

class AvgGradePlugin(Plugin):
    name = "Average grades"
    description = "Average grade given to scheduled cards as a function of time"
    components = [AvgGrade, AvgGradeWdgt]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(AvgGradePlugin)

Ejemplo n.º 22
0
    def run(self, text, card, fact_key, **render_args):
        if fact_key == 'p_1': # p_1 stands for pronunciation in cards of type
                              # "Vocabulary"
            return num2dia(text)
        else:
            return text


class Pyn2DPlugin(Plugin):

    name = "Pyn2D"
    description = "Convert Hanyu Pinyin with numbers to diacritics"
    components = [Pyn2D]

    def activate(self):
        Plugin.activate(self)
        self.render_chain("default").\
            register_filter(Pyn2D, in_front=False)
        # Other chain you might want to add to is e.g. "card_browser".

    def deactivate(self):
        Plugin.deactivate(self)
        self.render_chain("default").\
            unregister_filter(Pyn2D)

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(Pyn2DPlugin)
Ejemplo n.º 23
0
        super().__init__(**kwds)
    
        self.auto_focus_grades = False

        # Change shortcuts for the grade buttons.
        self.grade_0_button.setShortcut("q")
        self.grade_1_button.setShortcut("w")
        self.grade_2_button.setShortcut("e")
        self.grade_3_button.setShortcut("r")
        self.grade_4_button.setShortcut("t")
        self.grade_5_button.setShortcut("y")

        # Some more examples.
        
        #self.grade_0_button.setShortcut("Enter") # Numerical keypad
        #self.grade_1_button.setShortcut("Space")
        #self.grade_2_button.setShortcut("Return") 


class ShortcutsPlugin(Plugin):

    name = "Custom shortcuts"
    description = "Customise review widget shortcuts."
    components = [MyReviewWdgt]
    supported_API_level = 2

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ShortcutsPlugin)
Ejemplo n.º 24
0
space bar behavior is functional. The modified number key behavior is hoped to
work with future versions. [2]

[1] http://mnemosyne-proj.org/
[2] https://code.launchpad.net/~kevang/mnemosyne-proj/number_keys_show_answer
"""

from mnemosyne.libmnemosyne.plugin import Plugin
from mnemosyne.pyqt_ui.review_wdgt import ReviewWdgt


class ClumsyFingersReviewWdgt(ReviewWdgt):
    def __init__(self, component_manager):
        ReviewWdgt.__init__(self, component_manager)

        self.auto_focus_grades = False
        self.number_keys_show_answer = False


class ClumsyFingersPlugin(Plugin):

    name = "Clumsy Fingers"
    description = "Disable redundant shortcuts: space bar only shows answer, number keys only grade"
    components = [ClumsyFingersReviewWdgt]


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(ClumsyFingersPlugin)
Ejemplo n.º 25
0
        for cursor in db.con.execute(""" select _id from cards where active=0
          and tags like '%{}%' order by _id limit ?""".\
          format(inactive_tag_names_contain),
          (number_of_cards_to_activate, )).fetchall():
            card = db.card(cursor[0], is_id_internal=True)
            card.tags.add(enabled_tag)
            db.update_card(card)
        db.save()


class ActivateHookPlugin(Plugin):

    name = "Activate cards on rollover"
    description = "Trickles in a number of cards on rollover. Parameters are set in the Python script."
    components = [ActivateHook]
    supported_API_level = 3


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
plugin = register_user_plugin(ActivateHookPlugin)

# Since this is typically run on a server with GUI, we automatically
# activate it here.

# TODO: after the first activation, this will actually result in this
# plugin to be activated twice, but this has no effect in this case.

plugin.activate()
#
# after_repetition.py <*****@*****.**>
#

from mnemosyne.libmnemosyne.hook import Hook
from mnemosyne.libmnemosyne.plugin import Plugin


class Grade5DetectionHook(Hook):

    used_for = "after_repetition"

    def run(self, card):
        if card.grade == 5:
            self.main_widget().show_information("This was an easy card!")


class AfterRepetitionPlugin(Plugin):
    
    name = "Grade 5 detection"
    description = "Notice when a card is given grade 5."   
    components = [Grade5DetectionHook]
    supported_API_level = 2
    

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(AfterRepetitionPlugin)

Ejemplo n.º 27
0
class PieChartWdgt(PlotStatisticsWdgt):
    
    used_for = MyGrades
    
    def show_statistics(self, variant):
        if not self.page.y:
            self.display_message(_("No stats available."))
            return
        # Pie charts look better on a square canvas.
        self.figure.set_size_inches(self.figure.get_figheight(),
                                    self.figure.get_figheight())   
        labels = ["Unseen" if self.page.y[0] > 0 else ""] +\
            ["Grade %d" % (g-1) if self.page.y[g] > 0 else "" for g in range(1, 7)]
        colors = ["w", "r", "m", "y", "g", "c", "b"]
        # Only print percentage on wedges > 5%.
        autopct = lambda x: "%1.1f%%" % x if x > 5 else ""
        self.axes.pie(self.page.y, labels=labels, colors=colors,
                      shadow=True, autopct=autopct)
        self.axes.set_title("Number of cards")

# Wrap it into a Plugin and then register the Plugin.

class PieChartPlugin(Plugin):
    name = "Pie chart grades"
    description = "Show the grade statistics in a pie chart"
    components = [MyGrades, PieChartWdgt]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(PieChartPlugin)

Ejemplo n.º 28
0
#

from PyQt5 import QtCore, QtGui, QtWidgets

from mnemosyne.libmnemosyne.plugin import Plugin


class LockDownPlugin(Plugin):

    name = "Lock down the UI"
    description = "Hides the menu bar and the icon bar. The only way to remove this plugin later is by deleting 'lock_down.py' from Mnemosyne's plugin directory'"
    supported_API_level = 2

    def activate(self):
        Plugin.activate(self)
        self.main_widget().menuBar().hide()
        self.main_widget().tool_bar.hide()

    def deactivate(self):
        Plugin.deactivate(self)
        self.main_widget().menuBar().show()
        self.main_widget().findChild(QtWidgets.QToolBar).show()
        self.main_widget().tool_bar.show()


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin

register_user_plugin(LockDownPlugin)
Ejemplo n.º 29
0
from mnemosyne.libmnemosyne.plugin import Plugin


class AlignImgTop(Filter):

    def run(self, text, card, fact_key, **render_args):
        return text.replace("<img", "<img align=\"top\"")


class AlignImgTopPlugin(Plugin):

    name = "Top align images"
    description = "Align all your images to the top"
    components = [AlignImgTop]

    def activate(self):
        Plugin.activate(self)
        self.render_chain("default").\
            register_filter(AlignImgTop, in_front=False)
        # Other chain you might want to add to is e.g. "card_browser".

    def deactivate(self):
        Plugin.deactivate(self)
        self.render_chain("default").\
            unregister_filter(AlignImgTop)

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(AlignImgTopPlugin)
Ejemplo n.º 30
0
            language_code=language_id,
            ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)
        audio_config = texttospeech.types.AudioConfig(
            audio_encoding=texttospeech.enums.AudioEncoding.MP3)
        response = client.synthesize_speech(synthesis_input, voice,
                                            audio_config)

        filename = expand_path("__GTTS__TMP__.mp3",
                               self.database().media_dir())
        with open(filename, 'wb') as mp3_file:
            mp3_file.write(response.audio_content)
        return filename


class GoogleCloudTTSPlugin(Plugin):

    name = "Google Cloud TTS"
    description = "Add Google Cloud text-to-speech."
    components = [GoogleCloudPronouncer]
    gui_for_component = {
        "GoogleCloudPronouncer":
        [("mnemosyne.pyqt_ui.pronouncer_dlg", "PronouncerDlg")]
    }
    supported_API_level = 3


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(GoogleCloudTTSPlugin)
Ejemplo n.º 31
0
    name = "Hello world"
    description = "Add a menu item to the help menu"

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)
        self.action_hello = None

    def activate(self):
        Plugin.activate(self)
        self.action_hello = QtGui.QAction(self.main_widget())
        self.action_hello.setText("Hello world")
        self.main_widget().menu_Help.addAction(self.action_hello)
        QtCore.QObject.connect(self.action_hello, QtCore.SIGNAL("activated()"), self.hello_world)

    def deactivate(self):
        Plugin.deactivate(self)
        if self.action_hello:
            self.main_widget().menu_Help.removeAction(self.action_hello)
            self.actionHello = None

    def hello_world(self):
        self.main_widget().show_information("Hi there!")


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin

register_user_plugin(HelloWorldPlugin)
Ejemplo n.º 32
0
# lock_down.py <*****@*****.**>
#

from PyQt4 import QtCore, QtGui

from mnemosyne.libmnemosyne.plugin import Plugin


class LockDownPlugin(Plugin):

    name = "Lock down the UI"
    description = "Hides the menu bar and the icon bar. The only way to remove this plugin later is by deleting 'lock_down.py' from Mnemosyne's plugin directory'"

    def activate(self):
        Plugin.activate(self)
        self.main_widget().menuBar().hide()
        self.main_widget().tool_bar.hide()

    def deactivate(self):
        Plugin.deactivate(self)
        self.main_widget().menuBar().show()
        self.main_widget().findChild(QtGui.QToolBar).show()
        self.main_widget().tool_bar.show()


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin

register_user_plugin(LockDownPlugin)
Ejemplo n.º 33
0
        self.threshold = QtGui.QSpinBox(self)
        self.threshold.setMaximum(5)
        self.horizontalLayout.addWidget(self.threshold)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.parent_saved_sets = parent.saved_sets
        self.threshold.valueChanged.connect(self.criterion_changed)
        self.threshold.setValue(5)

    def display_criterion(self, criterion):
        self.threshold.setValue(criterion.threshold)

    def criterion(self):
        criterion = GradesCriterion(self.component_manager)
        criterion.threshold = self.threshold.value()
        return criterion

    def criterion_changed(self):
        self.parent_saved_sets.clearSelection()

# Wrap it into a Plugin and then register the Plugin.

from mnemosyne.libmnemosyne.plugin import Plugin

class GradesCriterionPlugin(Plugin):
    name = "Activity criterion example"
    description = "Example plugin for grade-based criterion."
    components = [GradesCriterion, GradesCriterionApplier, GradesCriterionWdgt]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(GradesCriterionPlugin)
Ejemplo n.º 34
0
    # The keys we inherit from Vocabulary, we just override the FactViews.

    # Recognition.
    v1 = FactView(_("Recognition"), "3::1")
    v1.q_fact_keys = ["f"]
    v1.a_fact_keys = ["p_1", "m_1", "n"]
    v1.q_fact_key_decorators = {"f": "What is the translation of ${f}?"}

    # Production.
    v2 = FactView(_("Production"), "3::2")
    v2.q_fact_keys = ["m_1"]
    v2.a_fact_keys = ["f", "p_1", "n"]
    v2.q_fact_key_decorators = {"m_1": "How do you say ${m_1}?"}

    fact_views = [v1, v2]


# Wrap it into a Plugin and then register the Plugin.


class DecoratedVocabularyPlugin(Plugin):

    name = "Decorated vocabulary"
    description = "Vocabulary card type with some extra text"
    components = [DecoratedVocabulary]


from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(DecoratedVocabularyPlugin)
Ejemplo n.º 35
0
    name = "Hello world"
    description = "Add a menu item to the help menu"

    def __init__(self, component_manager):
        Plugin.__init__(self, component_manager)
        self.action_hello = None

    def activate(self):
        Plugin.activate(self)
        self.action_hello = QtGui.QAction(self.main_widget())
        self.action_hello.setText("Hello world")
        self.main_widget().menu_Help.addAction(self.action_hello)
        QtCore.QObject.connect(self.action_hello, QtCore.SIGNAL("activated()"),
                               self.hello_world)

    def deactivate(self):
        Plugin.deactivate(self)
        if self.action_hello:
            self.main_widget().menu_Help.removeAction(self.action_hello)
            self.actionHello = None

    def hello_world(self):
        self.main_widget().show_information("Hi there!")


# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(HelloWorldPlugin)
Ejemplo n.º 36
0
from mnemosyne.libmnemosyne.plugin import Plugin


class BackupHook(Hook):

    used_for = "after_backup"

    def run(self, backup_name):
        # Upload regular backup to a server.
        os.system("scp %s my.safe.server.com:" % backup_name)
        # Dump database to a text file (requires Python 2.6).
        with open('dump.sql', 'w') as f:
            for line in self.database().con.iterdump():
                f.write('%s\n' % line)


class BackupPlugin(Plugin):
    
    name = "Extra backup"
    description = "Move your backups to a safe place."   
    components = [BackupHook]
    supported_API_level = 3
      

# Register plugin.

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(BackupPlugin)


Ejemplo n.º 37
0
        self.parent_saved_sets = parent.saved_sets
        self.connect(self.threshold, QtCore.SIGNAL("valueChanged(int)"),
                     self.criterion_changed)
        
    def display_default_criterion(self):
        self.threshold.setValue(5)

    def display_criterion(self, criterion):
        self.threshold.setValue(criterion.threshold)

    def get_criterion(self):
        criterion = GradesCriterion(self.component_manager)
        criterion.threshold = self.threshold.value()
        return criterion
    
    def criterion_changed(self):
        self.parent_saved_sets.clearSelection()

# Wrap it into a Plugin and then register the Plugin.

from mnemosyne.libmnemosyne.plugin import Plugin

class GradesActivityCriterionPlugin(Plugin):
    name = "Activity criterion example"
    description = "Example plugin for grade-based activity criteria."
    components = [GradesCriterion, GradesCriterionApplier, GradesCriterionWdgt]

from mnemosyne.libmnemosyne.plugin import register_user_plugin
register_user_plugin(GradesActivityCriterionPlugin)

            f"status code {resp_sess.status_code} from {url}: {e}, payload: {full_comment}"
        )
    except:
        print("error occurred while trying to send data to Beeminder...")


class UpdateBeeminder(Hook):
    """
    If a card has a grade of 2 or higher, update a mnemosyne card
    tracking goal on Beeminder
    """
    used_for = "after_repetition"

    def run(self, card):
        if card.grade >= 2:
            submit(
                f"card grade was {card.grade}, fact_id: {card.fact._id}, tag: {card.tag_string()}"
            )


class AfterRepUpdBmndrPlugin(Plugin):
    """
    """
    name = "Update Beeminder after Rep"
    description = "Send data to Beeminder after card score >= 2"
    components = [UpdateBeeminder]
    supported_API_level = 3


register_user_plugin(AfterRepUpdBmndrPlugin)