Thanks. Pushed and published a new activity.<div><br></div><div>Gonzalo<br><br><div class="gmail_quote">On Wed, Jul 25, 2012 at 1:12 PM, Manuel Kaufmann <span dir="ltr"><<a href="mailto:humitos@gmail.com" target="_blank">humitos@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Convert all the gtk2 and sugar-toolkit code to launch this Activity<br>
using Gtk3.<br>
<br>
* Searching on the log file is not working due to this bug:<br>
<a href="https://bugzilla.gnome.org/show_bug.cgi?id=680597" target="_blank">https://bugzilla.gnome.org/show_bug.cgi?id=680597</a><br>
<br>
All these steps are documented here:<br>
<br>
* <a href="http://wiki.sugarlabs.org/go/Features/GTK3/Porting/Log" target="_blank">http://wiki.sugarlabs.org/go/Features/GTK3/Porting/Log</a><br>
<br>
Signed-off-by: Manuel Kaufmann <<a href="mailto:humitos@gmail.com">humitos@gmail.com</a>><br>
---<br>
logviewer.py | 163 ++++++++++++++++++++++++++++++++--------------------------<br>
setup.py | 2 +-<br>
2 files changed, 92 insertions(+), 73 deletions(-)<br>
<br>
diff --git a/logviewer.py b/logviewer.py<br>
index 71ab5c1..02cf25b 100644<br>
--- a/logviewer.py<br>
+++ b/logviewer.py<br>
@@ -22,23 +22,24 @@ from gettext import gettext as _<br>
<br>
import re<br>
<br>
-import gtk<br>
-import pango<br>
-import gobject<br>
-import gio<br>
-<br>
-from sugar.activity import activity<br>
-from sugar.activity.widgets import ActivityToolbarButton<br>
-from sugar import env<br>
-from sugar.graphics import iconentry<br>
-from sugar.graphics.toolbutton import ToolButton<br>
-from sugar.graphics.toggletoolbutton import ToggleToolButton<br>
-from sugar.graphics.palette import Palette<br>
-from sugar.graphics.alert import NotifyAlert<br>
+from gi.repository import Gtk<br>
+from gi.repository import Gdk<br>
+from gi.repository import Pango<br>
+from gi.repository import GObject<br>
+from gi.repository import Gio<br>
+<br>
+from sugar3.activity import activity<br>
+from sugar3.activity.widgets import ActivityToolbarButton<br>
+from sugar3 import env<br>
+from sugar3.graphics import iconentry<br>
+from sugar3.graphics.toolbutton import ToolButton<br>
+from sugar3.graphics.toggletoolbutton import ToggleToolButton<br>
+from sugar3.graphics.palette import Palette<br>
+from sugar3.graphics.alert import NotifyAlert<br>
from logcollect import LogCollect<br>
-from sugar.graphics.toolbarbox import ToolbarBox<br>
-from sugar.activity.widgets import CopyButton, StopButton<br>
-from sugar.datastore import datastore<br>
+from sugar3.graphics.toolbarbox import ToolbarBox<br>
+from sugar3.activity.widgets import CopyButton, StopButton<br>
+from sugar3.datastore import datastore<br>
<br>
<br>
_AUTOSEARCH_TIMEOUT = 1000<br>
@@ -49,10 +50,10 @@ def _notify_response_cb(notify, response, activity):<br>
activity.remove_alert(notify)<br>
<br>
<br>
-class MultiLogView(gtk.HPaned):<br>
+class MultiLogView(Gtk.HPaned):<br>
<br>
def __init__(self, paths, extra_files):<br>
- gtk.HPaned.__init__(self)<br>
+ GObject.GObject.__init__(self)<br>
<br>
self.paths = paths<br>
self.extra_files = extra_files<br>
@@ -73,20 +74,21 @@ class MultiLogView(gtk.HPaned):<br>
self._find_logs()<br>
<br>
def _build_treeview(self):<br>
- self._treeview = gtk.TreeView()<br>
+ self._treeview = Gtk.TreeView()<br>
<br>
self._treeview.set_rules_hint(True)<br>
self._treeview.connect('cursor-changed', self._cursor_changed_cb)<br>
<br>
- self._treemodel = gtk.TreeStore(gobject.TYPE_STRING)<br>
+ self._treemodel = Gtk.TreeStore(GObject.TYPE_STRING)<br>
<br>
- sorted = gtk.TreeModelSort(self._treemodel)<br>
- sorted.set_sort_column_id(0, gtk.SORT_ASCENDING)<br>
+ # README: <a href="https://bugzilla.gnome.org/show_bug.cgi?id=680009" target="_blank">https://bugzilla.gnome.org/show_bug.cgi?id=680009</a><br>
+ sorted = self._treemodel.sort_new_with_model()<br>
+ sorted.set_sort_column_id(0, Gtk.SortType.ASCENDING)<br>
sorted.set_sort_func(0, self._sort_logfile)<br>
self._treeview.set_model(sorted)<br>
<br>
- renderer = gtk.CellRendererText()<br>
- col = gtk.TreeViewColumn(_('Log Files'), renderer, text=0)<br>
+ renderer = Gtk.CellRendererText()<br>
+ col = Gtk.TreeViewColumn(_('Log Files'), renderer, text=0)<br>
self._treeview.append_column(col)<br>
<br>
self.path_iter = {}<br>
@@ -96,40 +98,40 @@ class MultiLogView(gtk.HPaned):<br>
if len(self.extra_files):<br>
self.extra_iter = self._treemodel.append(None, [_('Other')])<br>
<br>
- scroll = gtk.ScrolledWindow()<br>
- scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)<br>
+ scroll = Gtk.ScrolledWindow()<br>
+ scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)<br>
scroll.add(self._treeview)<br>
- scroll.set_size_request(gtk.gdk.screen_width() * 30 / 100, -1)<br>
+ scroll.set_size_request(Gdk.Screen.width() * 30 / 100, -1)<br>
<br>
self.add1(scroll)<br>
<br>
def _build_textview(self):<br>
- self._textview = gtk.TextView()<br>
- self._textview.set_wrap_mode(gtk.WRAP_NONE)<br>
+ self._textview = Gtk.TextView()<br>
+ self._textview.set_wrap_mode(Gtk.WrapMode.NONE)<br>
<br>
- pangoFont = pango.FontDescription('Mono')<br>
+ pangoFont = Pango.FontDescription('Mono')<br>
self._textview.modify_font(pangoFont)<br>
<br>
- bgcolor = gtk.gdk.color_parse('#FFFFFF')<br>
- self._textview.modify_base(gtk.STATE_NORMAL, bgcolor)<br>
+ bgcolor = Gdk.color_parse('#FFFFFF')<br>
+ self._textview.modify_base(Gtk.StateType.NORMAL, bgcolor)<br>
<br>
self._textview.set_editable(False)<br>
<br>
- self._tagtable = gtk.TextTagTable()<br>
- hilite_tag = gtk.TextTag('search-hilite')<br>
+ self._tagtable = Gtk.TextTagTable()<br>
+ hilite_tag = Gtk.TextTag.new('search-hilite')<br>
hilite_tag.props.background = '#FFFFB0'<br>
self._tagtable.add(hilite_tag)<br>
- select_tag = gtk.TextTag('search-select')<br>
+ select_tag = Gtk.TextTag.new('search-select')<br>
select_tag.props.background = '#B0B0FF'<br>
self._tagtable.add(select_tag)<br>
<br>
- scroll = gtk.ScrolledWindow()<br>
- scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)<br>
+ scroll = Gtk.ScrolledWindow()<br>
+ scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)<br>
scroll.add(self._textview)<br>
<br>
self.add2(scroll)<br>
<br>
- def _sort_logfile(self, treemodel, itera, iterb):<br>
+ def _sort_logfile(self, treemodel, itera, iterb, user_data=None):<br>
a = treemodel.get_value(itera, 0)<br>
b = treemodel.get_value(iterb, 0)<br>
if a == None or b == None:<br>
@@ -162,36 +164,41 @@ class MultiLogView(gtk.HPaned):<br>
def _configure_watcher(self):<br>
# Setting where GIO will be watching<br>
for p in self.paths:<br>
- monitor = gio.File(p).monitor_directory()<br>
+ monitor = Gio.File.new_for_path(p)\<br>
+ .monitor_directory(Gio.FileMonitorFlags.NONE, None)<br>
monitor.connect('changed', self._log_file_changed_cb)<br>
self._gio_monitors.append(monitor)<br>
<br>
for f in self.extra_files:<br>
- monitor = gio.File(f).monitor_file()<br>
+ monitor = Gio.File.new_for_path(f)\<br>
+ .monitor_file(Gio.FileMonitorFlags.NONE, None)<br>
monitor.connect('changed', self._log_file_changed_cb)<br>
self._gio_monitors.append(monitor)<br>
<br>
def _log_file_changed_cb(self, monitor, log_file, other_file, event):<br>
logfile = log_file.get_basename()<br>
<br>
- if event == gio.FILE_MONITOR_EVENT_CHANGED:<br>
+ if event == Gio.FileMonitorEvent.CHANGED:<br>
if logfile in self.logs:<br>
self.logs[logfile].update()<br>
- elif event == gio.FILE_MONITOR_EVENT_DELETED:<br>
+ elif event == Gio.FileMonitorEvent.DELETED:<br>
if logfile in self.logs:<br>
self._remove_log_file(logfile)<br>
- elif event == gio.FILE_MONITOR_EVENT_CREATED:<br>
+ elif event == Gio.FileMonitorEvent.CREATED:<br>
self._add_log_file(log_file.get_path())<br>
<br>
def _cursor_changed_cb(self, treeview):<br>
treestore, text_iter = self._treeview.get_selection().get_selected()<br>
- self._show_log(treestore.get_value(text_iter, 0))<br>
+ # FIXME: None is not a possible value<br>
+ if text_iter:<br>
+ self._show_log(treestore.get_value(text_iter, 0))<br>
<br>
def _show_log(self, logfile):<br>
if logfile in self.logs:<br>
log = self.logs[logfile]<br>
self._textview.set_buffer(log)<br>
- self._textview.scroll_to_mark(log.get_insert(), 0)<br>
+ self._textview.scroll_to_mark(<br>
+ log.get_insert(), 0, use_align=False, xalign=0.5, yalign=0.5)<br>
self.active_log = log<br>
<br>
def _find_logs(self):<br>
@@ -241,15 +248,18 @@ class MultiLogView(gtk.HPaned):<br>
written = log._written<br>
<br>
if self.active_log == None:<br>
+ # import epdb;epdb.set_trace()<br>
self.active_log = log<br>
self._show_log(logfile)<br>
- log_iter = \<br>
- self._treeview.get_model().convert_child_iter_to_iter(None,<br>
- log.iter)<br>
+ # README: I don't understand how it works, sometimes it fails<br>
+ # <a href="http://developer.gnome.org/gtk3/3.5/GtkTreeModelSort.html#gtk-tree-model-sort-convert-child-iter-to-iter" target="_blank">http://developer.gnome.org/gtk3/3.5/GtkTreeModelSort.html#gtk-tree-model-sort-convert-child-iter-to-iter</a><br>
+ success, log_iter = \<br>
+ self._treeview.get_model().convert_child_iter_to_iter(log.iter)<br>
self._treeview.get_selection().select_iter(log_iter)<br>
<br>
if written > 0 and self.active_log == log:<br>
- self._textview.scroll_to_mark(log.get_insert(), 0)<br>
+ self._textview.scroll_to_mark(<br>
+ log.get_insert(), 0, use_align=False, xalign=0.5, yalign=0.5)<br>
<br>
def _remove_log_file(self, logfile):<br>
log = self.logs[logfile]<br>
@@ -268,13 +278,16 @@ class MultiLogView(gtk.HPaned):<br>
_buffer.remove_tag_by_name('search-select', start, end)<br>
<br>
text_iter = _buffer.get_start_iter()<br>
- while True:<br>
- next_found = text_iter.forward_search(text, 0)<br>
- if next_found is None:<br>
- break<br>
- start, end = next_found<br>
- _buffer.apply_tag_by_name('search-hilite', start, end)<br>
- text_iter = end<br>
+<br>
+ # FIXME: this search is not working due to this bug<br>
+ # <a href="https://bugzilla.gnome.org/show_bug.cgi?id=680597" target="_blank">https://bugzilla.gnome.org/show_bug.cgi?id=680597</a><br>
+ # while True:<br>
+ # next_found = text_iter.forward_search(text, 0)<br>
+ # if next_found is None:<br>
+ # break<br>
+ # start, end = next_found<br>
+ # _buffer.apply_tag_by_name('search-hilite', start, end)<br>
+ # text_iter = end<br>
<br>
if self.get_next_result('current'):<br>
self.search_next('current')<br>
@@ -312,10 +325,14 @@ class MultiLogView(gtk.HPaned):<br>
self._textview.scroll_to_iter(end, 0.1)<br>
<br>
<br>
-class LogBuffer(gtk.TextBuffer):<br>
+class LogBuffer(Gtk.TextBuffer):<br>
<br>
def __init__(self, tagtable, logfile, iterator):<br>
- gtk.TextBuffer.__init__(self, tagtable)<br>
+ # GObject.GObject.__init__(self, tagtable)<br>
+ GObject.GObject.__init__(self)<br>
+<br>
+ # FIXME: it's not possible to set this value<br>
+ # self.props.tag_table = tagtable<br>
<br>
self.logfile = logfile<br>
self._pos = 0<br>
@@ -367,6 +384,8 @@ class LogActivity(activity.Activity):<br>
<br>
self._build_toolbox()<br>
<br>
+ # Get Sugar's clipboard<br>
+ self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)<br>
self.show()<br>
<br>
def _build_toolbox(self):<br>
@@ -389,13 +408,13 @@ class LogActivity(activity.Activity):<br>
toolbar_box.toolbar.insert(wrap_btn, -1)<br>
<br>
self.search_entry = iconentry.IconEntry()<br>
- self.search_entry.set_size_request(gtk.gdk.screen_width() / 3, -1)<br>
+ self.search_entry.set_size_request(Gdk.Screen.width() / 3, -1)<br>
self.search_entry.set_icon_from_name(<br>
iconentry.ICON_ENTRY_PRIMARY, 'system-search')<br>
self.search_entry.add_clear_button()<br>
self.search_entry.connect('activate', self._search_entry_activate_cb)<br>
self.search_entry.connect('changed', self._search_entry_changed_cb)<br>
- search_item = gtk.ToolItem()<br>
+ search_item = Gtk.ToolItem()<br>
search_item.add(self.search_entry)<br>
toolbar_box.toolbar.insert(search_item, -1)<br>
<br>
@@ -423,7 +442,7 @@ class LogActivity(activity.Activity):<br>
delete_btn.connect('clicked', self._delete_log_cb)<br>
toolbar_box.toolbar.insert(delete_btn, -1)<br>
<br>
- separator = gtk.SeparatorToolItem()<br>
+ separator = Gtk.SeparatorToolItem()<br>
separator.set_expand(True)<br>
separator.set_draw(False)<br>
toolbar_box.toolbar.insert(separator, -1)<br>
@@ -435,24 +454,24 @@ class LogActivity(activity.Activity):<br>
<br>
def __copy_clicked_cb(self, button):<br>
if self.viewer.active_log:<br>
- self.viewer.active_log.copy_clipboard(gtk.clipboard_get())<br>
+ self.viewer.active_log.copy_clipboard(self.clipboard)<br>
<br>
def _wrap_cb(self, button):<br>
if button.get_active():<br>
- self.viewer._textview.set_wrap_mode(gtk.WRAP_WORD_CHAR)<br>
+ self.viewer._textview.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)<br>
else:<br>
- self.viewer._textview.set_wrap_mode(gtk.WRAP_NONE)<br>
+ self.viewer._textview.set_wrap_mode(Gtk.WrapMode.NONE)<br>
<br>
def _search_entry_activate_cb(self, entry):<br>
if self._autosearch_timer:<br>
- gobject.source_remove(self._autosearch_timer)<br>
+ GObject.source_remove(self._autosearch_timer)<br>
self.viewer.set_search_text(entry.props.text)<br>
self._update_search_buttons()<br>
<br>
def _search_entry_changed_cb(self, entry):<br>
if self._autosearch_timer:<br>
- gobject.source_remove(self._autosearch_timer)<br>
- self._autosearch_timer = gobject.timeout_add(_AUTOSEARCH_TIMEOUT,<br>
+ GObject.source_remove(self._autosearch_timer)<br>
+ self._autosearch_timer = GObject.timeout_add(_AUTOSEARCH_TIMEOUT,<br>
self.__autosearch_timer_cb)<br>
<br>
def __autosearch_timer_cb(self):<br>
@@ -503,17 +522,17 @@ class CollectorPalette(Palette):<br>
<br>
self._collector = LogCollect()<br>
<br>
- label = gtk.Label(<br>
+ label = Gtk.Label(label=<br>
_('This captures information about the system\n'\<br>
'and running processes to a journal entry.\n'\<br>
'Use this to improve a problem report.'))<br>
<br>
- send_button = gtk.Button(_('Capture information'))<br>
+ send_button = Gtk.Button(_('Capture information'))<br>
send_button.connect('clicked', self._on_send_button_clicked_cb)<br>
<br>
- vbox = gtk.VBox(False, 5)<br>
- vbox.pack_start(label)<br>
- vbox.pack_start(send_button)<br>
+ vbox = Gtk.VBox(False, 5)<br>
+ vbox.pack_start(label, True, True, 0)<br>
+ vbox.pack_start(send_button, True, True, 0)<br>
vbox.show_all()<br>
<br>
self.set_content(vbox)<br>
diff --git a/setup.py b/setup.py<br>
index 876cd3f..95390a3 100755<br>
--- a/setup.py<br>
+++ b/setup.py<br>
@@ -16,7 +16,7 @@<br>
# along with this program; if not, write to the Free Software<br>
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA<br>
<br>
-from sugar.activity import bundlebuilder<br>
+from sugar3.activity import bundlebuilder<br>
<br>
bundlebuilder.start()<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.7.10.4<br>
<br>
</font></span></blockquote></div><br></div>