def __init__(self, component_manager, cards, tag_text, parent=None):

        """We need to provide tag_text explicitly, since it's possible that
        the cards have not yet been added to the database.

        """

        Component.__init__(self, component_manager)
        if parent is None:
            parent = self.main_widget()
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        QAOptimalSplit.__init__(self)
        self.used_for_reviewing = False
        self.setWindowFlags(self.windowFlags() \
            | QtCore.Qt.WindowMinMaxButtonsHint)
        self.setWindowFlags(self.windowFlags() \
            & ~ QtCore.Qt.WindowContextHelpButtonHint)
        self.tag_text = tag_text
        self.cards = cards
        self.index = 0
        state = self.config()["preview_cards_dlg_state"]
        if state:
            self.restoreGeometry(state)
        self.update_dialog()
 def __init__(self, component_manager):
     QtSql.QSqlTableModel.__init__(self)
     Component.__init__(self, component_manager)
     self.search_string = ""
     self.adjusted_now = self.scheduler().adjusted_now()
     try:
         self.date_format = locale.nl_langinfo(locale.D_FMT)
     except:
         self.date_format = "%m/%d/%y"
     self.background_colour_for_card_type_id = {}
     for card_type_id, rgb in \
         self.config()["background_colour"].iteritems():
         # If the card type has been deleted since, don't bother.
         if not card_type_id in self.component_manager.card_type_with_id:
             continue
         self.background_colour_for_card_type_id[card_type_id] = \
             QtGui.QColor(rgb)
     self.font_colour_for_card_type_id = {}
     for card_type_id in self.config()["font_colour"]:
         if not card_type_id in self.component_manager.card_type_with_id:
             continue
         first_key = \
             self.card_type_with_id(card_type_id).fact_keys_and_names[0][0]
         self.font_colour_for_card_type_id[card_type_id] = QtGui.QColor(\
             self.config()["font_colour"][card_type_id][first_key])
Example #3
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     QtCore.QObject.__init__(self)
     self.thread = None
     # Since we will overwrite the true main widget in the thread, we need
     # to save it here.
     self.true_main_widget = self.main_widget()
Example #4
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.data_dir = None
     self.config_dir = None
     self.keys_to_sync = []
     self.lock = threading.Lock()
     self.determine_dirs()
Example #5
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     assert self.name and self.description, \
         "A plugin needs a name and a description."
     self.instantiated_components = []
     self.registered_components = []
     self.review_reset_needed = False
Example #6
0
 def __init__(self, component_manager, id=None):
     Component.__init__(self, component_manager)
     self.name = ""
     if id is None:
         id = rand_uuid()
     self.id = id
     self._id = None
Example #7
0
 def activate(self):
     Component.activate(self)
     # Late import to speed up application startup.
     from cheroot import wsgi
     self.wsgi_server = wsgi.Server(\
         ("0.0.0.0", self.port), self.wsgi_app, server_name="localhost",
         numthreads=1, timeout=5)
Example #8
0
 def __init__(self, component_manager, ui, server_only=False):
     Component.__init__(self, component_manager)
     Server.__init__(self, self.config().machine_id(),
         self.config()["sync_server_port"], ui)
     self.server_only = server_only
     self.check_for_edited_local_media_files = \
         self.config()["check_for_edited_local_media_files"]
Example #9
0
 def __init__(self, component_manager, id=None):
     Component.__init__(self, component_manager)
     self.name = ""
     if id is None:
         id = rand_uuid()
     self.id = id
     self._id = None
Example #10
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     assert self.name and self.description, \
         "A plugin needs a name and a description."
     self.instantiated_components = []
     self.registered_components = []
     self.review_reset_needed = False
Example #11
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     QtCore.QObject.__init__(self)
     self.thread = None
     # Since we will overwrite the true main widget in the thread, we need
     # to save it here.
     self.true_main_widget = self.main_widget()
Example #12
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     global _
     _ = self
     # We install a dummy translator so that translatable stings can be
     # marked even if 'activate' has not yet been called.
     self._translator = lambda x: x
Example #13
0
 def __init__(self, component_manager, ui, server_only=False):
     Component.__init__(self, component_manager)
     Server.__init__(self, self.config().machine_id(),
         self.config()["sync_server_port"], ui)
     self.server_only = server_only
     self.check_for_edited_local_media_files = \
         self.config()["check_for_edited_local_media_files"]
Example #14
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     global _
     _ = self
     # We install a dummy translator so that translatable stings can be
     # marked even if 'activate' has not yet been called.
     self._translator = lambda x : x
Example #15
0
 def __init__(self, component_manager, id=None):
     Component.__init__(self, component_manager)
     self.name = ""
     if id is None:
         import uuid
         id = str(uuid.uuid4())
     self.id = id
     self._id = None
Example #16
0
 def deactivate(self):
     if self.scheduler():
         self.scheduler().deactivate()
         self.component_manager.unregister(self.scheduler())
     if self.review_controller():
         self.review_controller().deactivate()
         self.component_manager.unregister(self.review_controller())
     Component.deactivate(self)
Example #17
0
 def deactivate(self):
     if not self.thread:
         return
     self.unload_database()
     self.thread.stop()
     self.thread.wait()
     self.thread = None
     Component.deactivate(self)
Example #18
0
 def activate_components(self):
     Component.activate(self)  # Also activates GUI components.
     self.component_manager.register(\
         self.Scheduler(self.component_manager))
     self.scheduler().activate()
     self.log().started_scheduler()
     self.component_manager.register(\
         self.ReviewController(self.component_manager))
     self.review_controller().activate()
Example #19
0
 def activate_components(self):
     # Register dependent classes first.
     self.component_manager.register(\
         self.Scheduler(self.component_manager))
     self.scheduler().activate()
     self.log().started_scheduler()
     self.component_manager.register(\
         self.ReviewController(self.component_manager))
     self.review_controller().activate()
     Component.activate_gui_components(self)
 def __init__(self, component_manager, unused_media_files):
     Component.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, self.main_widget())
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags() \
         | QtCore.Qt.WindowMinMaxButtonsHint)
     self.setWindowFlags(self.windowFlags() \
         & ~ QtCore.Qt.WindowContextHelpButtonHint)
     self.unused_media_files = unused_media_files
     self.file_list.setText("\n".join(self.unused_media_files))
 def __init__(self, component_manager, unused_media_files):
     Component.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, self.main_widget())
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags() \
         | QtCore.Qt.WindowMinMaxButtonsHint)
     self.setWindowFlags(self.windowFlags() \
         & ~ QtCore.Qt.WindowContextHelpButtonHint)
     self.unused_media_files = unused_media_files
     self.file_list.setText("\n".join(self.unused_media_files))
Example #22
0
 def __init__(self, parent, component_manager):
     Component.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags() \
         | QtCore.Qt.WindowMinMaxButtonsHint)
     self.setWindowFlags(self.windowFlags() \
         & ~ QtCore.Qt.WindowContextHelpButtonHint)
     self.sorted_card_types = self.database().sorted_card_types()
     for card_type in self.sorted_card_types:
         self.parent_type.addItem(_(card_type.name))
Example #23
0
 def __init__(self, parent, component_manager):
     Component.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags() \
         | QtCore.Qt.WindowMinMaxButtonsHint)
     self.setWindowFlags(self.windowFlags() \
         & ~ QtCore.Qt.WindowContextHelpButtonHint)
     self.sorted_card_types = self.database().sorted_card_types()
     for card_type in self.sorted_card_types:
         self.parent_type.addItem(_(card_type.name))
Example #24
0
 def activate(self):
     Component.activate(self)
     self._timestamp = None
     self.upload_thread = None
     self.archive_old_log()
     self.start_logging()
     if self.config()["upload_science_logs"]:
         from mnemosyne.libmnemosyne.log_uploader import LogUploader
         self.upload_thread = LogUploader(self.component_manager)
         self.upload_thread.start()
     self.active = True
Example #25
0
    def __init__(self, component_manager):
        Component.__init__(self, component_manager)
        self.widgets = {}

        # enable functionality if gconf entry exists
        self.gconf = gconf.client_get_default()
        try:
            self.current = self.gconf.get_value(self.gconf_entry)
            self.enabled = True
        except (gobject.GError, ValueError):
            self.enabled = False
Example #26
0
 def activate(self):
     Component.activate(self)
     if self.config()["run_web_server"]:
         # Restart the thread to have the new settings take effect.
         self.deactivate()
         try:
             self.thread = ServerThread(
                 port=self.config()["web_server_port"],
                 data_dir=self.config().data_dir,
                 config_dir=self.config().config_dir,
                 filename=self.config()["last_database"],
                 component_manager=self.component_manager)
         except socket.error as exception:
             (errno, e) = exception.args
             if errno == 98:
                 self.main_widget().show_error(\
                     _("Unable to start web server.") + " " + \
 _("There still seems to be an old server running on the requested port.")\
                     + " " + _("Terminate that process and try again."))
                 self.thread = None
                 return
             elif errno == 13:
                 self.main_widget().show_error(\
                     _("Unable to start web server.") + " " + \
 _("You don't have the permission to use the requested port."))
                 self.thread = None
                 return
             else:
                 raise e
         self.thread.review_started_signal.connect(\
             self.unload_database)
         self.thread.review_ended_signal.connect(\
             self.load_database)
         self.thread.information_signal.connect(\
             self.threaded_show_information)
         self.thread.error_signal.connect(\
             self.threaded_show_error)
         self.thread.question_signal.connect(\
             self.threaded_show_question)
         self.thread.set_progress_text_signal.connect(\
             self.true_main_widget.set_progress_text)
         self.thread.set_progress_range_signal.connect(\
             self.true_main_widget.set_progress_range)
         self.thread.set_progress_update_interval_signal.connect(\
             self.true_main_widget.set_progress_update_interval)
         self.thread.increase_progress_signal.connect(\
             self.true_main_widget.increase_progress)
         self.thread.set_progress_value_signal.connect(\
             self.true_main_widget.set_progress_value)
         self.thread.close_progress_signal.connect(\
             self.true_main_widget.close_progress)
         self.thread.start()
Example #27
0
 def __init__(self, component_manager):
     # To have an nice syntax when defining renderers, we do the
     # instantiation here.
     Component.__init__(self, component_manager)
     self._filters = []
     for filter in self.filters:
         self._filters.append(filter(component_manager))
     self._renderers = []
     self._renderer_for_card_type = {}
     for renderer in self.renderers:
         renderer = renderer(component_manager)
         self._renderers.append(renderer)
         self._renderer_for_card_type[renderer.used_for] = renderer
Example #28
0
 def __init__(self, component_manager):
     # To have an nice syntax when defining renderers, we do the
     # instantiation here.
     Component.__init__(self, component_manager)
     self._filters = []
     for filter in self.filters:
         self._filters.append(filter(component_manager))
     self._renderers = []
     self._renderer_for_card_type = {}
     for renderer in self.renderers:
         renderer = renderer(component_manager)
         self._renderers.append(renderer)
         self._renderer_for_card_type[renderer.used_for] = renderer
Example #29
0
    def __init__(self, component_manager):
        Component.__init__(self, component_manager)
        QtGui.QDialog.__init__(self, self.main_widget())
        self.setupUi(self)

        self.model = PluginListModel(self.component_manager)
        self.plugins.setModel(self.model)
        self.plugins.resizeColumnToContents(0)    
        self.plugins.resizeColumnToContents(1)
        self.plugins.setTextElideMode(QtCore.Qt.ElideNone)
        self.plugins.setRootIsDecorated(False)
        self.plugins.setItemsExpandable(False)
        width, height = self.config()["plugins_dlg_size"]
        if width:
            self.resize(width, height)
Example #30
0
 def __init__(self, component_manager, port, data_dir, config_dir,
              filename, is_server_local=False):
     Component.__init__(self, component_manager)
     self.port = port
     self.data_dir = data_dir
     self.config_dir = config_dir
     self.filename = filename
     self.is_server_local = is_server_local
     # When restarting the server, make sure we discard info from the
     # browser resending the form from the previous session.
     self.is_just_started = True
     self.is_mnemosyne_loaded = False
     self.is_shutting_down = False
     self.wsgi_server = wsgiserver.CherryPyWSGIServer(\
         ("0.0.0.0", port), self.wsgi_app, server_name="localhost",
         numthreads=1, timeout=5)
Example #31
0
    def __init__(self, component_manager, path):
        Component.__init__(self, component_manager)
        self._cursor = None
        # Make sure we don't put a database on a network drive under Windows:
        # http://www.sqlite.org/lockingv3.html
        if sys.platform == "win32":  # pragma: no cover
            drive = os.path.splitdrive(path)[0]
            import ctypes
            if ctypes.windll.kernel32.GetDriveTypeW(u"%s\\" % drive) == 4:
                self.main_widget().show_error(_\
("Putting a database on a network drive is forbidden under Windows to avoid data corruption. Mnemosyne will now close."))
                sys.exit(-1)
        self.connection = sqlite3.connect(path)
        # http://www.mail-archive.com/[email protected]/msg34453.html
        self.connection.execute("pragma journal_mode = persist;")
        # Should only be used to speed up the test suite.
        if self.config()["asynchronous_database"] == True:
            self.connection.execute("pragma synchronous = off;")
Example #32
0
 def __init__(self, component_manager, current_card_type, return_values,
              parent=None):
     Component.__init__(self, component_manager)
     if parent is None:
         parent = self.main_widget()
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags() \
         | QtCore.Qt.WindowMinMaxButtonsHint)
     self.setWindowFlags(self.windowFlags() \
         & ~ QtCore.Qt.WindowContextHelpButtonHint)
     self.card_type_by_name = {}
     self.return_values = return_values
     for card_type in self.database().sorted_card_types():
         if card_type == current_card_type:
             continue
         self.card_type_by_name[_(card_type.name)] = card_type
         self.card_types_widget.addItem(_(card_type.name))
Example #33
0
    def __init__(self, component_manager, path):
        Component.__init__(self, component_manager)
        self._cursor = None
        # Make sure we don't put a database on a network drive under Windows:
        # http://www.sqlite.org/lockingv3.html
        if sys.platform == "win32":  # pragma: no cover
            drive = os.path.splitdrive(path)[0]
            import ctypes
            if ctypes.windll.kernel32.GetDriveTypeW(u"%s\\" % drive) == 4:
                self.main_widget().show_error(_\
("Putting a database on a network drive is forbidden under Windows to avoid data corruption. Mnemosyne will now close."))
                sys.exit(-1)
        self.connection = sqlite3.connect(path)
        # http://www.mail-archive.com/[email protected]/msg34453.html
        self.connection.execute("pragma journal_mode = persist;")
        # Should only be used to speed up the test suite.
        if self.config()["asynchronous_database"] == True:
            self.connection.execute("pragma synchronous = off;")
Example #34
0
 def __init__(self, component_manager, parent, acquire_database=None):
     Component.__init__(self, component_manager)
     QtGui.QWidget.__init__(self, parent)
     self.layout = QtGui.QVBoxLayout(self)
     self.tree_wdgt = QtGui.QTreeWidget(self)
     self.tree_wdgt.setColumnCount(2)
     self.tree_wdgt.setColumnHidden(1, True)
     self.tree_wdgt.setColumnHidden(NODE, True)
     self.tree_wdgt.setHeaderHidden(True)
     self.tree_wdgt.setSelectionMode(\
         QtGui.QAbstractItemView.ExtendedSelection)
     self.delegate = TagDelegate(component_manager, self)
     self.tree_wdgt.setItemDelegate(self.delegate)
     self.delegate.rename_node.connect(self.rename_node)
     self.delegate.redraw_node.connect(self.redraw_node)
     self.layout.addWidget(self.tree_wdgt)
     self.tree_wdgt.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self.tree_wdgt.customContextMenuRequested.connect(\
         self.context_menu)
     self.acquire_database = acquire_database
Example #35
0
 def __init__(self, component_manager, parent, acquire_database=None):
     Component.__init__(self, component_manager)
     QtGui.QWidget.__init__(self, parent)
     self.layout = QtGui.QVBoxLayout(self)
     self.tree_wdgt = QtGui.QTreeWidget(self)
     self.tree_wdgt.setColumnCount(2)
     self.tree_wdgt.setColumnHidden(1, True)
     self.tree_wdgt.setColumnHidden(NODE, True)
     self.tree_wdgt.setHeaderHidden(True)
     self.tree_wdgt.setSelectionMode(\
         QtGui.QAbstractItemView.ExtendedSelection)
     self.delegate = TagDelegate(component_manager, self)
     self.tree_wdgt.setItemDelegate(self.delegate)
     self.delegate.rename_node.connect(self.rename_node)
     self.delegate.redraw_node.connect(self.redraw_node)
     self.layout.addWidget(self.tree_wdgt)
     self.tree_wdgt.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self.tree_wdgt.customContextMenuRequested.connect(\
         self.context_menu)
     self.acquire_database = acquire_database
Example #36
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, self.main_widget())
     self.setupUi(self)
     self.dynamic_widgets = []
     self.affected_card_types = []
     self.key_names = []       
     # We calculate card_type_by_name here because these names can change
     # if the user chooses another translation.
     self.card_types_widget.addItem(_("<all card types>"))
     self.card_type_by_name = {}
     for card_type in self.card_types():
         self.card_type_by_name[card_type.name] = card_type
         self.card_types_widget.addItem(card_type.name)          
     # Store backups in order to be able to revert our changes.
     self.old_font = deepcopy(self.config()["font"])
     self.old_background_colour = \
         deepcopy(self.config()["background_colour"])
     self.old_font_colour = deepcopy(self.config()["font_colour"])
     self.old_alignment = deepcopy(self.config()["alignment"])
     self.changed = False
Example #37
0
 def __init__(self,
              component_manager,
              port,
              data_dir,
              config_dir,
              filename,
              is_server_local=False):
     Component.__init__(self, component_manager)
     self.port = port
     self.data_dir = data_dir
     self.config_dir = config_dir
     self.filename = filename
     self.is_server_local = is_server_local
     # When restarting the server, make sure we discard info from the
     # browser resending the form from the previous session.
     self.is_just_started = True
     self.is_mnemosyne_loaded = False
     self.is_shutting_down = False
     self.wsgi_server = wsgiserver.CherryPyWSGIServer(\
         ("0.0.0.0", port), self.wsgi_app, server_name="localhost",
         numthreads=1, timeout=5)
 def __init__(self,
              component_manager,
              current_card_type,
              return_values,
              parent=None):
     Component.__init__(self, component_manager)
     if parent is None:
         parent = self.main_widget()
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags() \
         | QtCore.Qt.WindowMinMaxButtonsHint)
     self.setWindowFlags(self.windowFlags() \
         & ~ QtCore.Qt.WindowContextHelpButtonHint)
     self.card_type_by_name = {}
     self.return_values = return_values
     for card_type in self.database().sorted_card_types():
         if card_type == current_card_type:
             continue
         self.card_type_by_name[_(card_type.name)] = card_type
         self.card_types_widget.addItem(_(card_type.name))
Example #39
0
 def __init__(self, component_manager, parent, statistics_page, page_index):
     Component.__init__(self, component_manager)
     QtGui.QWidget.__init__(self, parent)
     self.statistics_page = statistics_page
     self.page_index = page_index
     self.vbox_layout = QtGui.QVBoxLayout(self)
     self.combobox = QtGui.QComboBox(self)
     self.variant_ids = []
     self.variant_widgets = []
     self.current_variant_widget = None
     variants = statistics_page.variants
     if not variants:
         variants = [(0, _("Default"))]
     for variant_id, variant_name in variants:
         self.variant_ids.append(variant_id)
         self.variant_widgets.append(None)
         self.combobox.addItem(unicode(_(variant_name)))
     if len(self.variant_ids) <= 1 or \
        self.statistics_page.show_variants_in_combobox == False:
         self.combobox.hide()
     self.vbox_layout.addWidget(self.combobox)
     self.combobox.currentIndexChanged.connect(self.display_variant)
Example #40
0
    def __init__(self, component_manager, path):
        Component.__init__(self, component_manager)
        # Make sure we don't put a database on a network drive under Windows:
        # http://www.sqlite.org/lockingv3.html
        if sys.platform == "win32":  # pragma: no cover
            drive = os.path.splitdrive(path)[0]
            import ctypes
            if ctypes.windll.kernel32.GetDriveTypeW("%s\\" % drive) == 4:
                self.main_widget().show_error(_\
("Putting a database on a network drive is forbidden under Windows to avoid data corruption. Mnemosyne will now close."))
                sys.exit(-1)
        self.connection = apsw.Connection(path)
        self.connection.setbusytimeout(250)
        cursor = self.connection.cursor()
        # http://www.mail-archive.com/[email protected]/msg34453.html
        cursor.execute("pragma journal_mode = persist;")
        # Should only be used to speed up the test suite.
        if self.config()["asynchronous_database"] == True:
            cursor.execute("pragma synchronous = off;")
        # Always start a transaction and only commit when 'commit' is called
        # explicitly.
        cursor.execute("begin;")
Example #41
0
 def __init__(self, component_manager, parent, statistics_page, page_index):
     Component.__init__(self, component_manager)
     QtGui.QWidget.__init__(self, parent)
     self.statistics_page = statistics_page
     self.page_index = page_index
     self.vbox_layout = QtGui.QVBoxLayout(self)
     self.combobox = QtGui.QComboBox(self)
     self.variant_ids = []
     self.variant_widgets = []
     self.current_variant_widget = None
     variants = statistics_page.variants
     if not variants:
         variants = [(0, _("Default"))]
     for variant_id, variant_name in variants:
         self.variant_ids.append(variant_id)
         self.variant_widgets.append(None)
         self.combobox.addItem(unicode(_(variant_name)))
     if len(self.variant_ids) <= 1 or \
        self.statistics_page.show_variants_in_combobox == False:
         self.combobox.hide()
     self.vbox_layout.addWidget(self.combobox)
     self.combobox.currentIndexChanged.connect(self.display_variant)
Example #42
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
Example #43
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     global _
     _ = self
Example #44
0
 def activate(self):
     Component.activate(self)
     self.fill_dirs()
     self.load()
     self.load_user_config()
     self.set_defaults()
Example #45
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     basedir = None
     resource_limited = False
Example #46
0
 def __init__(self, parent, component_manager):
     Component.__init__(self, component_manager)
     QtGui.QDialog.__init__(self, parent)
     self.setupUi(self)
     for card_type in self.card_types():
         self.parent_type.addItem(card_type.name)
 def __init__(self, component_manager, Q_or_A, parent=None):
     Component.__init__(self, component_manager)
     QtGui.QStyledItemDelegate.__init__(self, parent)
     self.doc = QWebView2()
     self.Q_or_A = Q_or_A
Example #48
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.start_time = 0
     self.start_time_of_leg = 0
     self.running_time = 0
Example #49
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.card = None
Example #50
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.data_dir = None
     self.config_dir = None
     self.keys_to_sync = []
     self.determine_dirs()
Example #51
0
    def __init__(self, component_manager):

        Component.__init__(self, component_manager)

        self.w_tree = self.main_widget().w_tree
        self.get_widget = get_widget = self.w_tree.get_widget
        self.conf = self.config()
        self.connections = []
        self.connect_signals([\
            ("input_mode_toolbar_button_back_w", "clicked", \
                self.input_to_main_menu_cb),
            ("front_to_back_mode_selector_w", "released", \
                self.change_card_type_cb),
            ("both_way_mode_selector_w", "released", self.change_card_type_cb),
            ("three_side_mode_selector_w", "released", \
                self.change_card_type_cb),
            ("cloze_mode_selector_w", "released", self.change_card_type_cb),
            ("picture_content_button", "clicked", self.add_picture_cb),
            ("image_selection_dialog_button_select", "clicked", \
                self.select_item_cb),
            ("image_selection_dialog_button_close", "clicked",
                self.close_media_selection_dialog_cb),
            ("input_mode_prev_category_w", "clicked", self.change_category_cb),
            ("input_mode_next_category_w", "clicked", self.change_category_cb),
            ("input_mode_add_new_category_w", "clicked", \
                self.create_new_category_cb),
            ("sound_content_button", "clicked", self.add_sound_cb),
            ("category_name_container", "clicked", \
                self.show_add_category_block_cb),
            ("input_mode_close_add_category_block_w", "clicked",
                self.hide_add_category_block_cb),
            ("input_mode_snd_button", "released", \
                self.preview_sound_in_input_cb)])

        self.fact = None
        self.sounddir = None
        self.imagedir = None
        self.card_type = None
        self.categories_list = []
        self.added_new_cards = False
        #liststore = [text, type, filename, dirname, pixbuf]
        self.liststore = ListStore(str, str, str, str, gtk.gdk.Pixbuf)
        iconview_widget = get_widget("iconview_widget")
        iconview_widget.set_model(self.liststore)
        iconview_widget.set_pixbuf_column(4)
        iconview_widget.set_text_column(0)

        get_widget = self.get_widget
        # Widgets as attributes
        self.areas = {# Text areas
            "cloze": get_widget("cloze_text_w"),
            "answer":  get_widget("answer_text_w"),
            "foreign": get_widget("foreign_text_w"),
            "question": get_widget("question_text_w"),
            "translation": get_widget("translation_text_w"),
            "pronunciation": get_widget("pronun_text_w")
        }
        # Mandatory color setup fot GtkTextView
        for area in self.areas.values():
            area.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFFFF"))
            area.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000"))

        # Change default font
        font = pango.FontDescription("Nokia Sans %s" % \
            (self.conf['font_size'] - FONT_DISTINCTION))
        for area in self.areas.values():
            area.modify_font(font)

        self.widgets = {# Other widgets
            "CurrentCategory": get_widget("category_name_w"),
            "SoundButton": get_widget("sound_content_button"),
            "PictureButton": get_widget("picture_content_button"),
            "SoundIndicator": get_widget("input_mode_snd_button"),
            "CardTypeSwithcer": get_widget("card_type_switcher_w"),
            "MediaDialog": get_widget("media_selection_dialog"),
            "SoundContainer": get_widget("input_mode_snd_container"),
            "QuestionContainer": get_widget("input_mode_question_container"),
            "NewCategory": get_widget("input_mode_new_category_entry"),
            "ChangeCategoryBlock": get_widget(\
                "input_mode_change_category_block"),
            "AddCategoryBlock": get_widget("input_mode_add_category_block")
        }
        # Mandatory color setup fot GtkEntry
        self.widgets["NewCategory"].modify_base(gtk.STATE_NORMAL, \
            gtk.gdk.color_parse("#FFFFFF"))
        self.widgets["NewCategory"].modify_text(gtk.STATE_NORMAL, \
            gtk.gdk.color_parse("#000000"))

        # card_id: {"page": page_id, "selector": selector_widget, 
        # "widgets": [(field_name:text_area_widget)...]}
        self.selectors = {
            FrontToBack.id: {
            "page": 0, 
            "selector": get_widget("front_to_back_mode_selector_w"),
            "widgets": [('q', self.areas["question"]), 
                        ('a', self.areas["answer"])]
            },
            BothWays.id: {
            "page": 0,
            "selector": get_widget("both_way_mode_selector_w"),
            "widgets": [('q', self.areas["question"]), 
                        ('a', self.areas["answer"])]
            },
            ThreeSided.id: {
            "page": 1,
            "selector": get_widget("three_side_mode_selector_w"),
            "widgets": [('f', self.areas["foreign"]),
                        ('t', self.areas["translation"]),
                        ('p', self.areas["pronunciation"])]
            },
            Cloze.id: {
            "page": 2,
            "selector": get_widget("cloze_mode_selector_w"),
            "widgets": [('text', self.areas["cloze"])]
            }
        }
        # add card_type to selectors subdict
        for card_type in self.card_types():
            self.selectors[card_type.id]["card_type"] = card_type

        # create {selector_widget:card_type.id} dict
        self.widget_card_id = dict((self.selectors[id]["selector"], id) \
            for id in self.selectors.keys())

        self.set_card_type(get_widget("front_to_back_mode_selector_w"))
        self.compose_widgets()

        # Turn off hildon autocapitalization
        try:
            for widget in self.areas.values():
                widget.set_property("hildon-input-mode", 'full')
        # stock gtk doesn't have hildon properties
        except (TypeError, AttributeError): 
            pass # so, skip silently
Example #52
0
 def __init__(self, component_manager):
     self.active = False
     Component.__init__(self, component_manager)
Example #53
0
 def __init__(self, component_manager):
     Thread.__init__(self)
     Component.__init__(self, component_manager)
Example #54
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self._tags_with_name = {}
Example #55
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.card = None
     self.widget = None
     self.learning_ahead = False
     self.render_chain = "default"
Example #56
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.warned_about_missing_media = False