~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to UpdateManager/ReleaseNotesViewer.py

  • Committer: Michael Vogt
  • Date: 2011-07-08 07:46:54 UTC
  • mfrom: (2146.2.16 pygi)
  • Revision ID: michael.vogt@ubuntu.com-20110708074654-nbcspqmsrlbxc6p0
merged from the pygi branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#  
5
5
#  Author: Sebastian Heinlein <sebastian.heinlein@web.de>
6
6
#
7
 
#  This modul provides an inheritance of the gtk.TextView that is 
 
7
#  This modul provides an inheritance of the Gtk.TextView that is 
8
8
#  aware of http URLs and allows to open them in a browser.
9
9
#  It is based on the pygtk-demo "hypertext".
10
10
24
24
#  USA
25
25
 
26
26
import logging
27
 
import pango
28
 
import gtk
 
27
from gi.repository import Pango
 
28
from gi.repository import Gtk
29
29
import pygtk
30
30
import os
31
31
import subprocess
47
47
    subprocess.Popen(command)
48
48
 
49
49
 
50
 
class ReleaseNotesViewer(gtk.TextView):
 
50
class ReleaseNotesViewer(Gtk.TextView):
51
51
    def __init__(self, notes):
52
 
        """Init the ReleaseNotesViewer as an Inheritance of the gtk.TextView.
 
52
        """Init the ReleaseNotesViewer as an Inheritance of the Gtk.TextView.
53
53
           Load the notes into the buffer and make links clickable"""
54
54
        # init the parent
55
 
        gtk.TextView.__init__(self)
 
55
        GObject.GObject.__init__(self)
56
56
        # global hovering over link state
57
57
        self.hovering = False
58
58
        self.first = True
59
59
        # setup the buffer and signals
60
60
        self.set_property("editable", False)
61
61
        self.set_cursor_visible(False)
62
 
        self.modify_font(pango.FontDescription("monospace"))
63
 
        self.buffer = gtk.TextBuffer()
 
62
        self.modify_font(Pango.FontDescription("monospace"))
 
63
        self.buffer = Gtk.TextBuffer()
64
64
        self.set_buffer(self.buffer)
65
65
        self.buffer.set_text(notes)
66
66
        self.connect("event-after", self.event_after)
72
72
    def tag_link(self, start, end, url):
73
73
        """Apply the tag that marks links to the specified buffer selection"""
74
74
        tag = self.buffer.create_tag(None, foreground="blue",
75
 
                                     underline=pango.UNDERLINE_SINGLE)
 
75
                                     underline=Pango.Underline.SINGLE)
76
76
        tag.set_data("url", url)
77
77
        self.buffer.apply_tag(tag , start, end)
78
78
 
83
83
        iter = self.buffer.get_iter_at_offset(0)
84
84
        while 1:
85
85
            # search for the next URL in the buffer
86
 
            ret = iter.forward_search("http://", gtk.TEXT_SEARCH_VISIBLE_ONLY,
 
86
            ret = iter.forward_search("http://", Gtk.TextSearchFlags.VISIBLE_ONLY,
87
87
                                      None)
88
88
            # if we reach the end break the loop
89
89
            if not ret:
109
109
    def event_after(self, text_view, event):
110
110
        """callback for mouse click events"""
111
111
        # we only react on left mouse clicks
112
 
        if event.type != gtk.gdk.BUTTON_RELEASE:
 
112
        if event.type != Gdk.BUTTON_RELEASE:
113
113
            return False
114
114
        if event.button != 1:
115
115
            return False
124
124
                return False
125
125
 
126
126
        # get the iter at the mouse position
127
 
        (x, y) = self.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
 
127
        (x, y) = self.window_to_buffer_coords(Gtk.TextWindowType.WIDGET,
128
128
                                              int(event.x), int(event.y))
129
129
        iter = self.get_iter_at_location(x, y)
130
130
        
139
139
    def motion_notify_event(self, text_view, event):
140
140
        """callback for the mouse movement event, that calls the
141
141
           check_hovering method with the mouse postition coordiantes"""
142
 
        x, y = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
 
142
        x, y = text_view.window_to_buffer_coords(Gtk.TextWindowType.WIDGET,
143
143
                                                 int(event.x), int(event.y))
144
144
        self.check_hovering(x, y)
145
145
        self.window.get_pointer()
150
150
           that calls the check_hovering method with the mouse position
151
151
           coordinates"""
152
152
        (wx, wy, mod) = text_view.window.get_pointer()
153
 
        (bx, by) = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET, wx,
 
153
        (bx, by) = text_view.window_to_buffer_coords(Gtk.TextWindowType.WIDGET, wx,
154
154
                                                     wy)
155
155
        self.check_hovering(bx, by)
156
156
        return False
176
176
            self.hovering = _hovering
177
177
            # Set the appropriate cursur icon
178
178
            if self.hovering:
179
 
                self.get_window(gtk.TEXT_WINDOW_TEXT).\
180
 
                        set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
 
179
                self.get_window(Gtk.TextWindowType.TEXT).\
 
180
                        set_cursor(Gdk.Cursor.new(Gdk.HAND2))
181
181
            else:
182
 
                self.get_window(gtk.TEXT_WINDOW_TEXT).\
183
 
                        set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
 
182
                self.get_window(Gtk.TextWindowType.TEXT).\
 
183
                        set_cursor(Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR))
184
184
 
185
185
if __name__ == "__main__":
186
186
    # some simple test code
187
 
    win = gtk.Window()
 
187
    win = Gtk.Window()
188
188
    rv = ReleaseNotesViewer(open("../DistUpgrade/ReleaseAnnouncement").read())
189
189
    win.add(rv)
190
190
    win.show_all()
191
 
    gtk.main()
 
191
    Gtk.main()