Exemplo n.º 1
0
 def update(self, dlg):
     fn = dlg.get_preview_filename()
     if fn:
         fn = gu.decode_filename(fn)
         for child in self.g_topic_box.get_children():
             child.destroy()
         fn = lessonfile.mk_uri(fn)
         try:
             self.set_sensitive(True)
             self.g_title.set_text(lessonfile.infocache.get(fn, 'title'))
             self.g_module.set_text(lessonfile.infocache.get(fn, 'module'))
             self.g_ok_button.set_sensitive(True)
             for x in self.m_model.iterate_topics_for_file(fn):
                 l = gtk.Label(x)
                 l.set_alignment(0.0, 0.5)
                 self.g_topic_box.pack_start(l, False)
             if not self.g_topic_box.get_children():
                 l = gtk.Label(u"-")
                 l.set_alignment(0.0, 0.5)
                 self.g_topic_box.pack_start(l, False)
         except (lessonfile.InfoCache.FileNotFound,
                 lessonfile.InfoCache.FileNotLessonfile), e:
             self.g_title.set_text(u'')
             self.g_module.set_text(u'')
             self.g_ok_button.set_sensitive(False)
             self.set_sensitive(False)
Exemplo n.º 2
0
 def update(self, dlg):
     fn = dlg.get_preview_filename()
     if fn:
         fn = gu.decode_filename(fn)
         for child in self.g_topic_box.get_children():
             child.destroy()
         fn = lessonfile.mk_uri(fn)
         try:
             self.set_sensitive(True)
             self.g_title.set_text(lessonfile.infocache.get(fn, 'title'))
             self.g_module.set_text(lessonfile.infocache.get(fn, 'module'))
             self.g_ok_button.set_sensitive(True)
             for x in self.m_model.iterate_topics_for_file(fn):
                 l = gtk.Label(x)
                 l.set_alignment(0.0, 0.5)
                 self.g_topic_box.pack_start(l, False)
             if not self.g_topic_box.get_children():
                 l = gtk.Label(u"-")
                 l.set_alignment(0.0, 0.5)
                 self.g_topic_box.pack_start(l, False)
         except (lessonfile.InfoCache.FileNotFound,
                 lessonfile.InfoCache.FileNotLessonfile), e:
             self.g_title.set_text(u'')
             self.g_module.set_text(u'')
             self.g_ok_button.set_sensitive(False)
             self.set_sensitive(False)
Exemplo n.º 3
0
 def _add_filenames(self, filenames):
     for fn in filenames:
         assert os.path.isabs(fn)
         # If the file name is a file in a subdirectory below
         # lessonfile.exercises_dir in the current working directory,
         # then the file is a standard lesson file, and it will be
         # converted to a uri scheme with:
         fn = lessonfile.mk_uri(fn)
         # Small test to check that the file actually is a lesson file.
         try:
             lessonfile.infocache.get(fn, 'title')
         except lessonfile.infocache.FileNotLessonfile:
             continue
         self.m_model.append(fn)
         self.g_link_box.pack_start(self.create_linkrow(fn), True, True, 0)
Exemplo n.º 4
0
 def _add_filenames(self, filenames):
     for filename in filenames:
         fn = gu.decode_filename(filename)
         assert os.path.isabs(fn)
         # If the file name is a file in a subdirectory below
         # lessonfile.exercises_dir in the current working directory,
         # then the file is a standard lesson file, and it will be
         # converted to a uri scheme with:
         fn = lessonfile.mk_uri(fn)
         # Small test to check that the file actually is a lesson file.
         try:
             lessonfile.infocache.get(fn, 'title')
         except lessonfile.infocache.FileNotLessonfile:
             continue
         self.m_model.append(fn)
         self.g_link_box.pack_start(self.create_linkrow(fn), False)
Exemplo n.º 5
0
 def get_uuid_to_filename_mapping(self, callback=None):
     """
     Parse all lesson files we can find and return a dict mapping
     the lesson_id to file names.
     Current lessonfile manager code cause us to parse the user contributed
     files in ~/lessonfiles too.
     """
     count = 0
     mapping = {}
     lessonfile.require_mgr()
     for uuid, data in lessonfile.mgr.parse(False):
         mapping[uuid] = lessonfile.mk_uri(data['filename'])
         count += 1
         callback(_("Files read: %i") % count)
     logging.info("get_uuid_to_filename_mapping: scanned %i files." % count)
     return count, mapping
Exemplo n.º 6
0
 def load_file(self, filename):
     p = Dataparser({'yes': True, 'no': False}, {})
     p.parse_file(filename)
     s = p.globals.setdefault('output_format', 'midi')
     s = s.lower()
     if s in self.g_output:
         self.g_output[s].set_active(True)
     else:
         # MIDI is the default format
         self.g_output['midi'].set_active(True)
     self.m_filename = filename
     if p.globals['fileformat_version'] == 1:
         lessonfile.require_mgr()
     self.g_named_tracks.set_active(p.globals.get('named_tracks', False))
     for lesson in p.blocklists.setdefault('lesson', []):
         # In this loop we will set the filename column of the liststore
         # to None if there is any problem, and set a title mentioning
         # the unknown lesson_id or filename.
         if p.globals['fileformat_version'] == 1:
             try:
                 filename = lessonfile.mgr.get(lesson['lesson_id'], 'filename')
                 filename = lessonfile.mk_uri(filename)
             except lessonfile.mgr.UnknownLessonID, e:
                 filename = None
         else:
             filename = lesson['filename']
         if filename:
             if os.path.exists(lessonfile.uri_expand(filename)):
                 fn = filename
                 title = self.get_lessonfile_title(filename)
             else:
                 fn = None
                 title = _(u"«<b>%s</b>» was not found") % filename
             self.g_liststore.append((fn,
                 title,
                 lesson['count'],
                 lesson['repeat'],
                 lesson['delay']))
         else:
             self.g_liststore.append((filename,
                 _("Unknown lesson_id: <b>%s</b>") % lesson['lesson_id'],
                 lesson['count'],
                 lesson['repeat'],
                 lesson['delay']))
Exemplo n.º 7
0
 def cnv_2_3(lesson_id):
     try:
         return lessonfile.mk_uri(lessonfile.mgr.get(lesson_id, 'filename'))
     except lessonfile.mgr.UnknownLessonID, e:
         return unicode(e)
Exemplo n.º 8
0
 def load_file(self, filename):
     """
     This function can load both format version 1.0 and 2.0
     """
     tree = et.ElementTree()
     tree.parse(filename)
     # section.find('text').text will be none if it was not set
     # when saved, and we need a string.
     if tree.find("title").text:
         self.g_title.set_text(tree.find("title").text)
     else:
         self.g_title.set_text("")
     sheet = tree.find("sheet")
     if tree.find('output_format').text == 'latex':
         self.g_latex_radio.set_active(True)
     else:
         self.g_latex_radio.set_active(False)
     self.g_liststore.clear()
     self.m_sections = []
     for section in tree.findall("section"):
         d = {}
         lessonfilename = section.find('filename')
         if lessonfilename == None:
             # fileformat 1.0
             lessonfile.require_mgr()
             lesson_id = section.find('lesson_id').text
             lessonfilename = lessonfile.mgr.get(lesson_id, 'filename')
             lessonfilename = lessonfile.mk_uri(lessonfilename)
         else:
             lessonfilename = lessonfilename.text
         # It seems that the elementtree parser will return str if
         # there are no non-ascii chars in the filename. So lets
         # make unicode of it if it is str
         if isinstance(lessonfilename, str):
             lessonfilename = unicode(lessonfilename)
         d['filename'] = lessonfilename
         # section.find('text').text will be none if it was not set
         # when saved, and d['title'] need to be a string
         if section.find('title').text:
             d['title'] = section.find('title').text
         else:
             d['title'] = ""
         if section.find('intervals') != None:
             d['intervals'] = eval(section.find('intervals').text, {}, {})
         else:
             if lessonfile.infocache.get(lessonfilename, 'module') == 'harmonicinterval':
                 d['intervals'] = []
                 gu.dialog_ok("FIXME: «%s» was saved with a buggy version of solfege, so you must set the intervals by selecting the file in the dialog and clicking the intervals to be asked. Sorry!" % lessonfilename)
         d['count'] = int(section.find('count').text)
         d['line_len'] = int(section.find('line_len').text)
         d['qtype'] = int(section.find('qtype').text)
         d['questions'] = []
         for question in section.findall("question"):
             q = {'question': {}, 'answer': {}}
             q['question']['music'] = question.find("students").find("music").text
             q['question']['name'] = question.find("students").find("name").text
             q['answer']['music'] = question.find("teachers").find("music").text
             q['answer']['name'] = question.find("teachers").find("name").text
             d['questions'].append(q)
         self.m_sections.append(d)
         try:
             # Check that the filename is valid
             lessonfile.infocache.get(lessonfilename, 'title')
             self.g_liststore.append((d['title'], lessonfilename))
         except lessonfile.infocache.InfoCacheException, e:
             self.g_liststore.append((_("«%s» not found") % str(e), None))
         self.g_treeview.set_cursor((0,))