def create_linkrow(self, link_this): hbox = gtk.HBox() def ff(btn, page): if id(page) in editor_of(self).m_page_mapping: editor_of(self).show_page_id(id(page)) else: if not page[0]: page[0].append(pd.LinkList(link_this.m_name)) p = Page(page, parent_page(self)) p.show() editor_of(self).add_page(p) if isinstance(link_this, pd.Page): linkbutton = gu.ClickableLabel(link_this.m_name) linkbutton.connect('clicked', ff, link_this) else: try: linkbutton = gu.ClickableLabel(lessonfile.infocache.get(link_this, 'title')) linkbutton.set_tooltip_text(link_this) except lessonfile.InfoCache.FileNotFound: linkbutton = gu.ClickableLabel(_(u"«%s» was not found") % link_this) linkbutton.make_warning() hbox.pack_start(linkbutton) linkbutton.connect('button-press-event', self.on_right_click_row, link_this) hbox.show_all() return hbox
def _display_data(self, page, display_only_tests=False, is_search_result=False, show_topics=False): """ display_only_tests should be True when we are browsing available tests. This will validate statistics for each lesson and display the test result. """ COLW = 4 if not is_search_result: self.m_page = page try: self.g_grid.destroy() except AttributeError: pass self.g_grid = Gtk.Grid() self.g_box.pack_start(self.g_grid, False, False, 0) label = None for col_idx, column in enumerate(page): assert isinstance(column, frontpage.Column) first = True y = 0 for sect_id, linklist in enumerate(column): if isinstance(linklist, frontpage.Paragraph): label = Gtk.Label(label=linklist.m_text) label.set_use_markup(True) label.set_line_wrap(True) label.set_alignment(0.0, 0.5) self.g_grid.attach(label, col_idx * COLW, y, 1, 1) y += 1 continue assert isinstance(linklist, frontpage.LinkList) if (display_only_tests and not frontpage._TreeCommon.tests_in_sub(linklist)): continue heading = Gtk.Label(label="<b>%s</b>" % _no_xgettext(linklist.m_name)) heading.set_alignment(0.0, 0.5) heading.set_use_markup(True) self.g_grid.attach(heading, col_idx * COLW, y, 2, 1) y += 1 for idx, link in enumerate(linklist): if isinstance( self, TestsView ) and not frontpage._TreeCommon.tests_in_sub(link): continue if isinstance(link, frontpage.Page): label = gu.ClickableLabel(_no_xgettext(link.m_name)) label.connect('clicked', self.on_page_link_clicked, link) self.g_grid.attach(label, col_idx * COLW + 1, y, 1, 1) else: assert isinstance(link, unicode), type(link) if display_only_tests: solfege.db.validate_stored_statistics(link) try: for fieldname in self.m_fields: if fieldname in ( u'link', u'link-with-filename-tooltip'): labeltxt = lessonfile.infocache.get( link, 'title') label = gu.ClickableLabel( _no_xgettext(labeltxt)) if solfege.app.m_options.debug: label.set_tooltip_text( u"%s\n%s module" % (link, lessonfile.infocache.get( link, 'module'))) elif fieldname == u'link-with-filename-tooltip': label.set_tooltip_text(link) if show_topics: topic = solfege.app.m_frontpage_data.get_topic_of_lesson_file( link) if topic and topic not in labeltxt: label.add_heading(topic) label.connect('clicked', self.on_link_clicked, link) else: if fieldname == 'filename': label = Gtk.Label(label=link) else: label = Gtk.Label( lessonfile.infocache.get( link, fieldname)) label.set_alignment(0.0, 0.5) self.g_grid.attach(label, col_idx * COLW + 1, y, 1, 1) except lessonfile.InfoCache.FileNotFound: label = gu.ClickableLabel( _(u"«%s» was not found") % link) label.make_warning() except lessonfile.InfoCache.FileNotLessonfile: label = gu.ClickableLabel( _(u"Failed to parse «%s»") % link) label.make_warning() if first: label.m_first = True first = False self.m_linkbuttons.append(label) label.connect('focus-in-event', self.on_focus_in) if display_only_tests: if isinstance(link, unicode): passed, result = solfege.db.get_test_status(link) if passed == True: self.g_grid.attach( Gtk.Label( _("passed, %.1f%%") % (result * 100)), col_idx * COLW + 2, y, 1, 1) if passed == False: self.g_grid.attach( Gtk.Label( _("failed, %.1f%%") % (result * 100)), col_idx * COLW + 2, y, 1, 1) y += 1 if label: label.m_last = True self.g_grid.show_all() self.adjust_scrolledwin_size() self.get_vadjustment().set_value(0.0)
def _display_data(self, page, display_only_tests=False, is_search_result=False, show_topics=False): """ display_only_tests should be True when we are browsing available tests. This will validate statistics for each lesson and display the test result. """ if not is_search_result: self.m_page = page try: self.g_hbox.destroy() except AttributeError: pass self.g_hbox = gu.bHBox(self.g_box) self.g_hbox.set_spacing(gu.hig.SPACE_MEDIUM) label = None do_sg = True if len(page[0]) > 0 and isinstance(page[0][0], frontpage.LinkList): count = 0 for column in page: assert isinstance(column, frontpage.Column) for linklist in column: assert isinstance(linklist, (frontpage.LinkList, frontpage.Paragraph)) if isinstance(linklist, frontpage.LinkList): count += len(linklist) if count > 80: do_sg = False for column in page: sizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) assert isinstance(column, frontpage.Column) first = True vbox = gtk.VBox() vbox.set_spacing(gu.hig.SPACE_MEDIUM) self.g_hbox.pack_start(vbox, False) for sect_id, linklist in enumerate(column): if isinstance(linklist, frontpage.Paragraph): label = gtk.Label(linklist.m_text) label.set_use_markup(True) label.set_line_wrap(True) label.set_alignment(0.0, 0.5) vbox.pack_start(label, False) continue assert isinstance(linklist, frontpage.LinkList) if (display_only_tests and not frontpage._TreeCommon.tests_in_sub(linklist)): continue linkbox = gtk.VBox() vbox.pack_start(linkbox, False) heading = gtk.Label("<b>%s</b>" % _no_xgettext(linklist.m_name)) heading.set_alignment(0.0, 0.5) heading.set_use_markup(True) linkbox.pack_start(heading, False) sizegroups = dict((k, gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)) for k in self.m_fields) for idx, link in enumerate(linklist): if isinstance(self, TestsView) and not frontpage._TreeCommon.tests_in_sub(link): continue if isinstance(link, frontpage.Page): label = gu.ClickableLabel(_no_xgettext(link.m_name)) label.connect('clicked', self.on_page_link_clicked, link) else: assert isinstance(link, unicode), type(link) label = gtk.HBox() label.set_spacing(gu.hig.SPACE_SMALL) if display_only_tests: solfege.db.validate_stored_statistics(link) try: for fieldname in self.m_fields: if fieldname in (u'link', u'link-with-filename-tooltip'): labeltxt = lessonfile.infocache.get(link, 'title') lbl = gu.ClickableLabel(_no_xgettext(labeltxt)) if solfege.app.m_options.debug: lbl.set_tooltip_text(u"%s\n%s module" % (link, lessonfile.infocache.get(link, 'module'))) elif fieldname == u'link-with-filename-tooltip': lbl.set_tooltip_text(link) if do_sg: sizegroups[fieldname].add_widget(lbl) if show_topics: topic = solfege.app.m_frontpage_data.get_topic_of_lesson_file(link) if topic and topic not in labeltxt: lbl.add_heading(topic) lbl.connect('clicked', self.on_link_clicked, link) else: if fieldname == 'filename': lbl = gtk.Label(link) else: lbl = gtk.Label(lessonfile.infocache.get(link, fieldname)) lbl.set_alignment(0.0, 0.5) if do_sg: sizegroups[fieldname].add_widget(lbl) label.pack_start(lbl, False) except lessonfile.InfoCache.FileNotFound: label = gu.ClickableLabel(_(u"«%s» was not found") % link) label.make_warning() except lessonfile.InfoCache.FileNotLessonfile: label = gu.ClickableLabel(_(u"Failed to parse «%s»") % link) label.make_warning() if first: label.set_data('first', True) first = False w = label.size_request()[0] if w > self.max_exercise_label_width: w = self.max_exercise_label_width if isinstance(link, unicode): txt = _(lessonfile.infocache.get(link, "title")) else: txt = link.m_name label.set_tooltip_text(txt) label.set_size_request(w / len(page), -1) self.m_linkbuttons.append(label) label.connect('focus-in-event', self.on_focus_in) if display_only_tests: box = gtk.HBox() box.pack_start(label) if isinstance(link, unicode): passed, result = solfege.db.get_test_status(link) if passed == True: box.pack_start(gtk.Label(_("passed, %.1f%%") % (result * 100))) if passed == False: box.pack_start(gtk.Label(_("failed, %.1f%%") % (result * 100))) # do nothing if passed == None since linkbox.pack_start(box, True) else: linkbox.pack_start(label, True) if do_sg: sizegroup.add_widget(label) if label: label.set_data('last', True) self.g_hbox.show_all() self.adjust_scrolledwin_size() self.get_vadjustment().set_value(0.0)
def _display_data(self, page, display_only_tests=False, is_search_result=False, show_topics=False): """ display_only_tests should be True when we are browsing available tests. This will validate statistics for each lesson and display the test result. """ COLW = 4 if not is_search_result: self.m_page = page try: self.g_grid.destroy() except AttributeError: pass self.g_grid = Gtk.Grid() self.g_grid.set_column_spacing(12) self.g_box.pack_start(self.g_grid, False, False, 0) label = None for col_idx, column in enumerate(page): assert isinstance(column, frontpage.Column) first = True y = 1 for sect_id, linklist in enumerate(column): if isinstance(linklist, frontpage.Paragraph): label = Gtk.Label(label=linklist.m_text) label.set_use_markup(True) label.set_line_wrap(True) label.set_alignment(0.0, 0.5) self.g_grid.attach(label, col_idx * COLW, y, 1, 1) y += 1 continue assert isinstance(linklist, frontpage.LinkList) if (display_only_tests and not frontpage._TreeCommon.tests_in_sub(linklist)): continue heading = Gtk.Label(label="<b>%s</b>" % linklist.m_name) heading.set_alignment(0.0, 0.5) heading.set_use_markup(True) self.g_grid.attach(heading, col_idx * COLW, y, 2, 1) y += 1 for idx, link in enumerate(linklist): if isinstance( self, TestsView ) and not frontpage._TreeCommon.tests_in_sub(link): continue if isinstance(link, frontpage.Page): label = gu.ClickableLabel(link.m_name) label.connect('clicked', self.on_page_link_clicked, link) self.g_grid.attach(label, col_idx * COLW, y, 1, 1) else: assert isinstance(link, str), type(link) if display_only_tests: solfege.db.validate_stored_statistics(link) try: for field_idx, fieldname in enumerate( self.m_fields): if fieldname in ('link', 'link-with-filename-tooltip'): labeltxt = lessonfile.infocache.get( link, 'title') if linklist.C_locale: labeltxt = labeltxt.cval label = gu.ClickableLabel(labeltxt) else: label = gu.ClickableLabel(labeltxt) if solfege.app.m_options.debug: label.set_tooltip_text( "%s\n%s module" % (link, lessonfile.infocache.get( link, 'module'))) elif fieldname == 'link-with-filename-tooltip': label.set_tooltip_text(link) if show_topics: topic = solfege.app.m_frontpage_data.get_topic_of_lesson_file( link) if topic and topic not in labeltxt: label.add_heading(topic) label.connect('clicked', self.on_link_clicked, link) else: if fieldname == 'filename': label = Gtk.Label(label=link) else: label = Gtk.Label( lessonfile.infocache.get( link, fieldname)) label.set_alignment(0.0, 0.5) self.g_grid.attach(label, col_idx * COLW + field_idx, y, 1, 1) if lessonfile.infocache.get( link, 'module') == 'toneincontext': from solfege.exercises import toneincontext try: p = toneincontext.ToneInKeyStatistics.get_percentage_of_file( link) * 100 except solfege.statistics.DB.FileNotInDB: pass else: label = Gtk.Label("{:.0f}%".format(p)) if p < 0.5: label.set_name("wlabelred") elif p < 0.9: label.set_name("wlabelyellow") else: label.set_name("wlabelgreen") g = Gtk.Grid() g.props.valign = Gtk.Align.CENTER g.attach(label, 0, 0, 1, 1) label.set_width_chars(6) self.g_grid.attach( g, col_idx * COLW + field_idx + 1, y, 1, 1) except lessonfile.InfoCache.FileNotFound: label = gu.ClickableLabel( _("«%s» was not found") % link) label.make_warning() self.g_grid.attach(label, col_idx * COLW + field_idx, y, 1, 1) except lessonfile.InfoCache.FileNotLessonfile: label = gu.ClickableLabel( _("Failed to parse «%s»") % link) label.make_warning() self.g_grid.attach(label, col_idx * COLW + 1 + field_idx, y, 1, 1) if first: label.m_first = True first = False self.m_linkbuttons.append(label) label.connect('focus-in-event', self.on_focus_in) if display_only_tests: if isinstance(link, str): passed, result = solfege.db.get_test_status(link) if passed == True: self.g_grid.attach( Gtk.Label( _("passed, %.1f%%") % (result * 100)), col_idx * COLW + 2, y, 1, 1) if passed == False: self.g_grid.attach( Gtk.Label( _("failed, %.1f%%") % (result * 100)), col_idx * COLW + 2, y, 1, 1) y += 1 if label: label.m_last = True self.g_grid.show_all() self.adjust_scrolledwin_size() self.get_vadjustment().set_value(0.0)