This file is indexed.

/usr/share/screenlets-manager/WebframeScreenlet.py is in screenlets 0.1.6-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/usr/bin/env python

# WebframeScreenlet
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# @license  GNU General Public License Version 3
# @author   Akira Ohgaki <akiraohgaki@gmail.com>
# @link     https://launchpad.net/webframe

import sys
import os
import gettext

import gobject
import gtk
import screenlets

_ = screenlets.utils.get_translator(__file__)

def tdoc(obj):
    obj.__doc__ = _(obj.__doc__)
    return obj

@tdoc

class WebframeScreenlet(screenlets.Screenlet):
    """A Screenlet to browse the web"""

    __name__ = 'WebframeScreenlet'
    __version__ = '0.4.0'
    __author__ = 'Akira Ohgaki'
    __requires__ = ['python-webkit']
    __desc__ = __doc__

    browser = None
    webkit_browser = None
    gecko_browser = None
    autoreload = None

    default_theme = 'Black'
    gecko_browser_profile = 'mozilla'
    browser_engines = ['webkit', 'gecko']
    browser_width = 480
    browser_min_width = 200
    browser_max_width = 2000
    browser_height = 320
    browser_min_height = 200
    browser_max_height = 2000
    browser_border_width = 15
    browser_border_min_width = 10
    browser_border_max_width = 20
    autoreload_interval = 0 # minutes
    autoreload_max_interval = 120 # minutes
    home_uri = ''
    search_uri = 'http://www.google.com/m'
    last_uri = ''

    def __init__(self, **keyword_args):
        screenlets.Screenlet.__init__(
            self,
            width=self.browser_width + self.browser_border_width * 2,
            height=self.browser_height + self.browser_border_width * 2,
            uses_theme=True,
            is_widget=False,
            is_sticky=True,
            resize_on_scroll=False,
            **keyword_args
        )
        self.theme_name = self.default_theme
        self.add_options_group(
            _('Webframe'),
            _('Preferences for this Webframe instance')
        )
        self.add_option(screenlets.options.StringOption(
            _('Webframe'),
            'home_uri',
            str(self.home_uri),
            _('Home page'),
            _('Set your favorite pages')
        ))
        self.add_option(screenlets.options.IntOption(
            _('Webframe'),
            'autoreload_interval',
            self.autoreload_interval,
            _('Auto reload (minutes)'),
            _('0 is disable an auto reload event'),
            min=0,
            max=self.autoreload_max_interval
        ))
        self.add_option(screenlets.options.IntOption(
            _('Webframe'),
            'browser_width',
            self.browser_width,
            _('Width'),
            _('Width of the browser viewport'),
            min=self.browser_min_width,
            max=self.browser_max_width
        ))
        self.add_option(screenlets.options.IntOption(
            _('Webframe'),
            'browser_height',
            self.browser_height,
            _('Height'),
            _('Height of the browser viewport'),
            min=self.browser_min_height,
            max=self.browser_max_height
        ))
        self.add_option(screenlets.options.IntOption(
            _('Webframe'),
            'browser_border_width',
            self.browser_border_width,
            _('Border width'),
            _('Thickness of border in pixels'),
            min=self.browser_border_min_width,
            max=self.browser_border_max_width
        ))
        self.add_option(screenlets.options.ListOption(
            _('Webframe'),
            'browser_engines',
            self.browser_engines,
            _('Web browser engine'),
            _('Set default engine to the first item of list')
        ))

    def on_after_set_atribute(self, name, value):
        if self.browser:
            if name == 'autoreload_interval':
                self.set_autoreload(self.autoreload_interval)
            elif name in ('browser_width', 'browser_height', 'browser_border_width'):
                self.width = self.browser_width + self.browser_border_width * 2
                self.height = self.browser_height + self.browser_border_width * 2
                self.browser.set_border_width(self.browser_border_width)
                self.redraw_canvas()

    def on_init(self):
        if not self.theme:
            #screenlets.show_message(self, _('Theme could not be loaded.'))
            print(_('Theme could not be loaded.'))
        self.init_browser()
        self.browser.set_border_width(self.browser_border_width)
        self.window.add(self.browser)
        self.window.show_all()
        if self.home_uri:
            self.browser_action('load_uri', self.home_uri)
        else:
            self.browser_action('load_uri', self.search_uri)
        self.set_autoreload(self.autoreload_interval)
        self.add_menuitem('go_back', _('Back'))
        self.add_menuitem('go_forward', _('Forward'))
        self.add_menuitem('reload', _('Reload'))
        self.add_menuitem('load_home_uri', _('Home'))
        self.add_menuitem('load_search_uri', _('Search'))
        self.add_menuitem('open_uri', _('View in Browser'))
        self.add_default_menuitems()

    def on_menuitem_select(self, id):
        if id == 'go_back':
            self.browser_action('go_back')
        elif id == 'go_forward':
            self.browser_action('go_forward')
        elif id == 'reload':
            self.browser_action('reload')
        elif id == 'load_home_uri':
            self.browser_action('load_uri', self.home_uri)
        elif id == 'load_search_uri':
            self.browser_action('load_uri', self.search_uri)
        elif id == 'open_uri':
            os.system("gnome-open '" + self.browser_action('get_uri') + "'")

    def on_mouse_enter(self, event):
        self.set_autoreload(0)

    def on_unfocus(self, event):
        self.set_autoreload(self.autoreload_interval)

    def on_draw(self, context):
        context.scale(self.scale, self.scale)
        theme_dir = self.get_screenlet_dir() + '/themes/' + self.theme_name
        bg_file = theme_dir + '/bg.png'
        left_file = theme_dir + '/left.png'
        right_file = theme_dir + '/right.png'
        top_file = theme_dir + '/top.png'
        bottom_file = theme_dir + '/bottom.png'
        left_top_file = theme_dir + '/left-top.png'
        left_bottom_file = theme_dir + '/left-bottom.png'
        right_top_file = theme_dir + '/right-top.png'
        right_bottom_file = theme_dir + '/right-bottom.png'
        left_center_file = theme_dir + '/left-center.png'
        right_center_file = theme_dir + '/right-center.png'
        top_center_file = theme_dir + '/top-center.png'
        bottom_center_file = theme_dir + '/bottom-center.png'
        image_files = (
            bg_file,
            left_file, right_file, top_file, bottom_file,
            left_top_file, left_bottom_file, right_top_file, right_bottom_file,
            left_center_file, right_center_file, top_center_file, bottom_center_file
        )
        is_collect = True
        for image_file in image_files:
            if not os.path.isfile(image_file):
                is_collect = False
                break
        if self.theme and is_collect:
            bg_size = self.theme.get_image_size(bg_file)
            left_size = self.theme.get_image_size(left_file)
            right_size = self.theme.get_image_size(right_file)
            top_size = self.theme.get_image_size(top_file)
            bottom_size = self.theme.get_image_size(bottom_file)
            left_top_size = self.theme.get_image_size(left_top_file)
            left_bottom_size = self.theme.get_image_size(left_bottom_file)
            right_top_size = self.theme.get_image_size(right_top_file)
            right_bottom_size = self.theme.get_image_size(right_bottom_file)
            left_center_size = self.theme.get_image_size(left_center_file)
            right_center_size = self.theme.get_image_size(right_center_file)
            top_center_size = self.theme.get_image_size(top_center_file)
            bottom_center_size = self.theme.get_image_size(bottom_center_file)
            left_scaled_height = (self.height - left_top_size[1] - left_center_size[1] - left_bottom_size[1]) / 2
            right_scaled_height = (self.height - right_top_size[1] - right_center_size[1] - right_bottom_size[1]) / 2
            top_scaled_width = (self.width - left_top_size[0] - top_center_size[0] - right_top_size[0]) / 2
            bottom_scaled_width = (self.width - left_bottom_size[0] - bottom_center_size[0] - right_bottom_size[0]) / 2
            self.theme.draw_scaled_image(
                context,
                self.browser_border_width,
                self.browser_border_width,
                bg_file,
                self.browser_width,
                self.browser_height
            )
            self.theme.draw_scaled_image(
                context,
                0,
                left_top_size[1],
                left_file,
                left_size[0],
                left_scaled_height
            )
            self.theme.draw_scaled_image(
                context,
                0,
                left_top_size[1] + left_scaled_height + left_center_size[1],
                left_file,
                left_size[0],
                self.height - left_top_size[1] - left_scaled_height - left_center_size[1] - left_bottom_size[1]
            )
            self.theme.draw_scaled_image(
                context,
                self.width - right_size[0],
                right_top_size[1],
                right_file,
                right_size[0],
                right_scaled_height
            )
            self.theme.draw_scaled_image(
                context,
                self.width - right_size[0],
                right_top_size[1] + right_scaled_height + right_center_size[1],
                right_file,
                right_size[0],
                self.height - right_top_size[1] - right_scaled_height - right_center_size[1] - right_bottom_size[1]
            )
            self.theme.draw_scaled_image(
                context,
                left_top_size[0],
                0,
                top_file,
                top_scaled_width,
                top_size[1]
            )
            self.theme.draw_scaled_image(
                context,
                left_top_size[0] + top_scaled_width + top_center_size[0],
                0,
                top_file,
                self.width - left_top_size[0] - top_scaled_width - top_center_size[0] - right_top_size[0],
                top_size[1]
            )
            self.theme.draw_scaled_image(
                context,
                left_bottom_size[0],
                self.height - bottom_size[1],
                bottom_file,
                bottom_scaled_width,
                bottom_size[1]
            )
            self.theme.draw_scaled_image(
                context,
                left_bottom_size[0] + bottom_scaled_width + bottom_center_size[0],
                self.height - bottom_size[1],
                bottom_file,
                self.width - left_bottom_size[0] - bottom_scaled_width - bottom_center_size[0] - right_bottom_size[0],
                bottom_size[1]
            )
            self.theme.draw_image(
                context,
                0,
                0,
                left_top_file
            )
            self.theme.draw_image(
                context,
                0,
                self.height - left_bottom_size[1],
                left_bottom_file
            )
            self.theme.draw_image(
                context,
                self.width - right_top_size[0],
                0,
                right_top_file
            )
            self.theme.draw_image(
                context,
                self.width - right_bottom_size[0],
                self.height - right_bottom_size[1],
                right_bottom_file
            )
            self.theme.draw_image(
                context,
                0,
                left_top_size[1] + left_scaled_height,
                left_center_file
            )
            self.theme.draw_image(
                context,
                self.width - right_center_size[0],
                right_top_size[1] + right_scaled_height,
                right_center_file
            )
            self.theme.draw_image(
                context,
                left_top_size[0] + top_scaled_width,
                0,
                top_center_file
            )
            self.theme.draw_image(
                context,
                left_bottom_size[0] + bottom_scaled_width,
                self.height - bottom_center_size[1],
                bottom_center_file
            )
        else:
            context.set_source_rgba(0, 0, 0, 0.7)
            context.rectangle(0, 0, self.width, self.height)
            context.fill()

    def on_draw_shape(self, context):
        self.on_draw(context)

    def init_browser(self):
        """ Initialize a web browser
        """
        self.browser = gtk.VBox()
        if self.browser_engines[0] == 'webkit':
            try:
                self.init_webkit_browser()
                scrolled_window = gtk.ScrolledWindow()
                scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
                scrolled_window.add(self.webkit_browser)
                self.browser.pack_start(scrolled_window, True, True, 0)
            except:
                #screenlets.show_error(self, _('WebKit engine could not be initialized.'))
                print(_('WebKit engine could not be initialized.'))
        elif self.browser_engines[0] == 'gecko':
            try:
                self.init_gecko_browser()
                self.browser.pack_start(self.gecko_browser, True, True, 0)
            except:
                #screenlets.show_error(self, _('Gecko engine could not be initialized.'))
                print(_('Gecko engine could not be initialized.'))

    def init_webkit_browser(self):
        """ Initialize a WebKit web browser
            WebKitGTK+ Reference Manual:
            http://webkitgtk.org/reference/index.html
        """
        import webkit
        self.webkit_browser = webkit.WebView()
        settings = self.webkit_browser.get_settings()
        settings.set_property('enable-default-context-menu', False)
        self.webkit_browser.set_settings(settings)

    def init_gecko_browser(self):
        """ Initialize a Gecko web browser
            Python GtkMozembed Reference Manual:
            http://www.pygtk.org/pygtkmozembed/index.html
        """
        import gtkmozembed
        if hasattr(gtkmozembed, 'set_profile_path'):
            gtkmozembed.set_profile_path(self.get_screenlet_dir(), self.gecko_browser_profile)
        else:
            gtkmozembed.gtk_moz_embed_set_profile_path(self.get_screenlet_dir(), self.gecko_browser_profile)
        self.gecko_browser = gtkmozembed.MozEmbed()

    def browser_action(self, action, uri=''):
        """ Web browser action
        """
        if self.webkit_browser:
            if action == 'go_back':
                self.webkit_browser.go_back()
            elif action == 'go_forward':
                self.webkit_browser.go_forward()
            elif action == 'reload':
                self.webkit_browser.reload()
            elif action == 'load_uri':
                self.webkit_browser.load_uri(uri)
            elif action == 'get_uri':
                return self.webkit_browser.get_property('uri')
        elif self.gecko_browser:
            if action == 'go_back':
                self.gecko_browser.go_back()
            elif action == 'go_forward':
                self.gecko_browser.go_forward()
            elif action == 'reload':
                self.gecko_browser.reload(True)
            elif action == 'load_uri':
                self.gecko_browser.load_url(uri)
            elif action == 'get_uri':
                return self.gecko_browser.get_location()

    def set_autoreload(self, interval):
        """ Set an auto reload event
        """
        if self.autoreload:
            gobject.source_remove(self.autoreload)
        if (interval > 0) and (self.webkit_browser or self.gecko_browser):
            self.last_uri = self.browser_action('get_uri')
            self.autoreload = gobject.timeout_add(60000 * interval, self.autoreload_handler)

    def autoreload_handler(self):
        """ Auto reload event handler
        """
        if self.last_uri == self.browser_action('get_uri'):
            self.browser_action('reload')
            return True
        else:
            return False

if __name__ == '__main__':
    screenlets.session.create_session(WebframeScreenlet)