[Rigo] rewrite NoticeBoard TreeView behaviour

Previously, the Notice object was shown directly inside the
cell renderer, which made things a bit clumsy and buggy.
Now, notices are loaded through xdg-open in html format.
This commit is contained in:
Fabio Erculiani
2012-07-14 18:19:59 +02:00
parent 3912ca0471
commit afd2608153
5 changed files with 76 additions and 35 deletions

View File

@@ -108,11 +108,10 @@ class Notice(object):
Return ConfigurationUpdate markup text.
"""
msg = "<b>%s</b>\n<small><b>%s</b>, " + \
"<i>%s</i>\n<u>%s</u>\n\n%s</small>"
"<i>%s</i>\n<u>%s</u></small>"
msg = msg % (
escape_markup(self.title()),
escape_markup(self.repository()),
escape_markup(self.date()),
escape_markup(self.link()),
escape_markup(self.description()))
escape_markup(self.link()))
return prepare_markup(msg)

View File

@@ -21,6 +21,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
import os
import hashlib
import errno
import tempfile
from gi.repository import GObject, GLib
@@ -28,8 +29,12 @@ from rigo.paths import CONF_DIR
from rigo.ui.gtk3.widgets.notifications import \
NoticeBoardNotificationBox
from rigo.enums import RigoViewStates
from rigo.utils import open_url
from entropy.cache import EntropyCacher
from entropy.const import etpConst
import entropy.tools
class NoticeBoardViewController(GObject.Object):
@@ -100,6 +105,7 @@ class NoticeBoardViewController(GObject.Object):
Setup the ConfigUpdatesViewController resources.
"""
self._view.set_model(self._store)
self._view.connect("show-notice", self._on_show_notice)
self._view.show()
def set_notification_controller(self, nc):
@@ -194,3 +200,39 @@ class NoticeBoardViewController(GObject.Object):
box.connect("let-me-see", _nb_let_me_see)
box.connect("stop-annoying", _nb_stop_annoying)
self._nc.append(box)
def _on_show_notice(self, view, notice):
print notice
tmp_fd, tmp_path = None, None
try:
fname = notice.title().replace("/", "-")
tmp_fd, tmp_path = tempfile.mkstemp(prefix=fname, suffix=".html")
with entropy.tools.codecs_fdopen(
tmp_fd, "w", etpConst['conf_encoding']) as tmp_f:
tmp_f.write("<b>")
tmp_f.write(notice.title())
tmp_f.write("</b>")
tmp_f.write("\n<br/><i>")
tmp_f.write(notice.date())
tmp_f.write("</i>, ")
tmp_f.write(notice.repository())
tmp_f.write("\n\n<br/><br/><div style='max-width: 400px'>")
tmp_f.write(notice.description())
tmp_f.write("</div>\n\n<br/>")
tmp_f.write("<b>URL</b>: <a href=\"")
tmp_f.write(notice.link())
tmp_f.write("\">")
tmp_f.write(notice.link())
tmp_f.write("</a>")
tmp_f.write("\n<br/><br/>")
tmp_f.flush()
finally:
if tmp_fd is not None:
try:
os.close(tmp_fd)
except OSError:
pass
# leaks, but xdg-open is async
if tmp_path is not None:
open_url(tmp_path)

View File

@@ -69,7 +69,6 @@ class CellRendererAppView(Gtk.CellRendererText):
self.pixbuf_width = 0
self.apptitle_width = 0
self.apptitle_height = 0
self.markup_height = 0
self.normal_height = 0
self.selected_height = 0
self.show_ratings = show_ratings
@@ -431,7 +430,6 @@ class CellRendererConfigUpdateView(Gtk.CellRendererText):
self.pixbuf_width = 0
self.title_width = 0
self.title_height = 0
self.markup_height = 0
self.normal_height = 0
self.selected_height = 0
@@ -614,6 +612,9 @@ class CellRendererConfigUpdateView(Gtk.CellRendererText):
context.restore()
class NoticeCellButtonIDs:
SHOW = 0
class CellRendererNoticeView(Gtk.CellRendererText):
@@ -640,7 +641,6 @@ class CellRendererNoticeView(Gtk.CellRendererText):
self.pixbuf_width = 0
self.title_width = 0
self.title_height = 0
self.markup_height = 0
self.normal_height = 0
self.selected_height = 0
@@ -687,18 +687,11 @@ class CellRendererNoticeView(Gtk.CellRendererText):
Gdk.cairo_set_source_pixbuf(cr, icon, x, y)
cr.paint()
def _calculate_height(self, markup):
l = Gtk.Label()
l.set_markup(markup)
w, h = l.get_layout().get_size()
return h / Pango.SCALE
def _render_summary(self, context, cr, cu,
cell_area, layout, xpad, ypad,
is_rtl):
markup = cu.get_markup()
self.markup_height = self._calculate_height(markup)
layout.set_markup(markup, -1)
@@ -866,7 +859,6 @@ class CellRendererRepositoryView(Gtk.CellRendererText):
self.pixbuf_width = 0
self.title_width = 0
self.title_height = 0
self.markup_height = 0
self.normal_height = 0
self.selected_height = 0
@@ -913,18 +905,11 @@ class CellRendererRepositoryView(Gtk.CellRendererText):
Gdk.cairo_set_source_pixbuf(cr, icon, x, y)
cr.paint()
def _calculate_height(self, markup):
l = Gtk.Label()
l.set_markup(markup)
w, h = l.get_layout().get_size()
return h / Pango.SCALE
def _render_summary(self, context, cr, repo,
cell_area, layout, xpad, ypad,
is_rtl):
markup = repo.get_markup()
self.markup_height = self._calculate_height(markup)
layout.set_markup(markup, -1)
@@ -1088,7 +1073,6 @@ class CellRendererPreferenceView(Gtk.CellRendererText):
self.pixbuf_width = 0
self.title_width = 0
self.title_height = 0
self.markup_height = 0
self.normal_height = 0
self.selected_height = 0
@@ -1133,12 +1117,6 @@ class CellRendererPreferenceView(Gtk.CellRendererText):
Gdk.cairo_set_source_pixbuf(cr, icon, x, y)
cr.paint()
def _calculate_height(self, markup):
l = Gtk.Label()
l.set_markup(markup)
w, h = l.get_layout().get_size()
return h / Pango.SCALE
def _render_summary(self, context, cr, cu,
cell_area, layout, xpad, ypad,
is_rtl):

View File

@@ -116,10 +116,7 @@ class GenericTreeView(Gtk.TreeView):
btn_h = btn.height
normal_height = max(32 + 4*ypad, em(2.5) + 4*ypad)
markup_height = tr.markup_height
if markup_height > 0:
normal_height -= max(0, markup_height)
tr.normal_height = normal_height + markup_height
tr.normal_height = normal_height
tr.selected_height = tr.normal_height + btn_h + StockEms.MEDIUM
def _on_style_updated(self, widget, tr):

View File

@@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""
from gi.repository import Gtk
from gi.repository import Gtk, GObject
from cellrenderers import CellButtonRenderer, CellRendererNoticeView
from cellrenderers import CellButtonRenderer, CellRendererNoticeView, \
NoticeCellButtonIDs
from rigo.utils import open_url
from rigo.ui.gtk3.models.noticeboardliststore import NoticeBoardListStore
@@ -30,6 +31,16 @@ from rigo.ui.gtk3.widgets.generictreeview import GenericTreeView
class NoticeBoardTreeView(GenericTreeView):
VARIANT_SHOW = 0
__gsignals__ = {
# Show Notice
"show-notice" : (GObject.SignalFlags.RUN_LAST,
None,
(GObject.TYPE_PYOBJECT,),
),
}
def __init__(self, icons, icon_size):
Gtk.TreeView.__init__(self)
@@ -39,11 +50,18 @@ class NoticeBoardTreeView(GenericTreeView):
tr.set_pixbuf_width(icon_size)
GenericTreeView.__init__(
self, self._row_activated_callback, None, tr)
self, self._row_activated_callback,
self._button_activated_callback, tr)
column = Gtk.TreeViewColumn("Notices", tr,
notice=self.COL_ROW_DATA)
show_notice = CellButtonRenderer(
self, name=NoticeCellButtonIDs.SHOW)
show_notice.set_markup_variants(
{self.VARIANT_SHOW: _("Show"),})
tr.button_pack_end(show_notice)
column.set_cell_data_func(tr, self._cell_data_func_cb)
column.set_fixed_width(350)
column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
@@ -51,3 +69,10 @@ class NoticeBoardTreeView(GenericTreeView):
def _row_activated_callback(self, path, rowref):
open_url(rowref.link())
def _button_activated_callback(self, btn, btn_id, notice, store, path):
if isinstance(store, Gtk.TreeModelFilter):
store = store.get_model()
if btn_id == NoticeCellButtonIDs.SHOW:
self.emit("show-notice", notice)
return False