aboutsummaryrefslogtreecommitdiffstats
path: root/lvc/widgets/gtk/window.py
blob: 18d91a21b618a8562b14f1d17f05ef73a671d904 (plain)
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# @Base: Miro - an RSS based video player application
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
# Jesus Eduardo (Heckyel) | 2017
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
#
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.

""".window -- GTK Window widget."""

import gobject
import gtk
import os

from lvc import resources
from lvc import signals

import keymap
import layout
import widgets
import wrappermap

# keeps the objects alive until destroy() is called
alive_windows = set()
running_dialogs = set()


class WrappedWindow(gtk.Window):
    def do_map(self):
        gtk.Window.do_map(self)
        wrappermap.wrapper(self).emit('show')

    def do_unmap(self):
        gtk.Window.do_unmap(self)
        wrappermap.wrapper(self).emit('hide')

    def do_focus_in_event(self, event):
        gtk.Window.do_focus_in_event(self, event)
        wrappermap.wrapper(self).emit('active-change')

    def do_focus_out_event(self, event):
        gtk.Window.do_focus_out_event(self, event)
        wrappermap.wrapper(self).emit('active-change')

    def do_key_press_event(self, event):
        if self.activate_key(event):  # event activated a menu item
            return

        if self.propagate_key_event(event):  # event handled by widget
            return

        ret = keymap.translate_gtk_event(event)
        if ret is not None:
            key, modifiers = ret
            rv = wrappermap.wrapper(self).emit('key-press', key, modifiers)
            if not rv:
                gtk.Window.do_key_press_event(self, event)

    def _get_focused_wrapper(self):
        """Get the wrapper of the widget with keyboard focus"""
        focused = self.get_focus()
        # some of our widgets created children for their use
        # (GtkSearchTextEntry).  If we don't find a wrapper for
        # focused, try it's parents
        while focused is not None:
            try:
                wrapper = wrappermap.wrapper(focused)
            except KeyError:
                focused = focused.get_parent()
            else:
                return wrapper
        return None

    def change_focus_using_wrapper(self, direction):
        my_wrapper = wrappermap.wrapper(self)
        focused_wrapper = self._get_focused_wrapper()
        if direction == gtk.DIR_TAB_FORWARD:
            to_focus = my_wrapper.get_next_tab_focus(focused_wrapper, True)
        elif direction == gtk.DIR_TAB_BACKWARD:
            to_focus = my_wrapper.get_next_tab_focus(focused_wrapper, False)
        else:
            return False
        if to_focus is not None:
            to_focus.focus()
            return True
        return False

    def do_focus(self, direction):
        if not self.change_focus_using_wrapper(direction):
            gtk.Window.do_focus(self, direction)

gobject.type_register(WrappedWindow)


class WindowBase(signals.SignalEmitter):
    def __init__(self):
        signals.SignalEmitter.__init__(self)
        self.create_signal('use-custom-style-changed')
        self.create_signal('key-press')
        self.create_signal('show')
        self.create_signal('hide')

    def set_window(self, window):
        self._window = window
        window.connect('style-set', self.on_style_set)
        wrappermap.add(window, self)
        self.calc_use_custom_style()

    def on_style_set(self, widget, old_style):
        old_use_custom_style = self.use_custom_style
        self.calc_use_custom_style()
        if old_use_custom_style != self.use_custom_style:
            self.emit('use-custom-style-changed')

    def calc_use_custom_style(self):
        if self._window is not None:
            base = self._window.style.base[gtk.STATE_NORMAL]
            # Decide if we should use a custom style.  Right now the
            # formula is the base color is a very light shade of
            # gray/white (lighter than #f0f0f0).
            self.use_custom_style = ((base.red == base.green == base.blue) and
                                     base.red >= 61680)


class Window(WindowBase):
    """The main Libre window.  """

    def __init__(self, title, rect=None):
        """Create the Libre Main Window.  Title is the name to give the
        window, rect specifies the position it should have on screen.
        """
        WindowBase.__init__(self)
        self.set_window(self._make_gtk_window())
        self._window.set_title(title)
        self.setup_icon()
        if rect:
            self._window.set_default_size(rect.width, rect.height)
            self._window.set_default_size(rect.width, rect.height)
            self._window.set_gravity(gtk.gdk.GRAVITY_CENTER)
            self._window.move(rect.x, rect.y)

        self.create_signal('active-change')
        self.create_signal('will-close')
        self.create_signal('did-move')
        self.create_signal('file-drag-motion')
        self.create_signal('file-drag-received')
        self.create_signal('file-drag-leave')
        self.create_signal('on-shown')
        self.drag_signals = []
        alive_windows.add(self)

        self._window.connect('delete-event', self.on_delete_window)
        self._window.connect('map-event', lambda w, a: self.emit('on-shown'))
        # XXX: Define MVCWindow/MiroWindow style not hard code this
        self._window.set_resizable(False)

    def setup_icon(self):
        icon_pixbuf = gtk.gdk.pixbuf_new_from_file(
            resources.image_path("lvc-logo.png"))
        self._window.set_icon(icon_pixbuf)

    def accept_file_drag(self, val):
        if not val:
            self._window.drag_dest_set(0, [], 0)
            for handle in self.drag_signals:
                self.disconnect(handle)
            self.drag_signals = []
        else:
            self._window.drag_dest_set(
                gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
                [('text/uri-list', 0, 0)],
                gtk.gdk.ACTION_COPY)
            for signal, callback in (
                    ('drag-motion', self.on_drag_motion),
                    ('drag-data-received', self.on_drag_data_received),
                    ('drag-leave', self.on_drag_leave)):
                self.drag_signals.append(
                    self._window.connect(signal, callback))

    def on_drag_motion(self, widget, context, x, y, time):
        self.emit('file-drag-motion')

    def on_drag_data_received(self, widget, context, x, y, selection_data,
                              info, time):
        self.emit('file-drag-received', selection_data.get_uris())

    def on_drag_leave(self, widget, context, time):
        self.emit('file-drag-leave')

    def on_delete_window(self, widget, event):
        # when the user clicks on the X in the corner of the window we
        # want that to close the window, but also trigger our
        # will-close signal and all that machinery unless the window
        # is currently hidden--then we don't do anything.
        if not self._window.window.is_visible():
            return
        self.close()
        return True

    def _make_gtk_window(self):
        return WrappedWindow()

    def set_title(self, title):
        self._window.set_title(title)

    def get_title(self):
        self._window.get_title()

    def center(self):
        self._window.set_position(gtk.WIN_POS_CENTER)

    def show(self):
        if self not in alive_windows:
            raise ValueError("Window destroyed")
        self._window.show()

    def close(self):
        if hasattr(self, "_closing"):
            return
        self._closing = True
        # Keep a reference to the widget in case will-close signal handler
        # calls destroy()
        old_window = self._window
        self.emit('will-close')
        old_window.hide()
        del self._closing

    def destroy(self):
        self.close()
        self._window = None
        alive_windows.discard(self)

    def is_active(self):
        return self._window.is_active()

    def is_visible(self):
        return self._window.props.visible

    def get_next_tab_focus(self, current, is_forward):
        return None

    def set_content_widget(self, widget):
        """Set the widget that will be drawn in the content area for this
        window.

        It will be allocated the entire area of the widget, except the
        space needed for the titlebar, frame and other decorations.
        When the window is resized, content should also be resized.
        """
        self._add_content_widget(widget)
        widget._widget.show()
        self.content_widget = widget

    def _add_content_widget(self, widget):
        self._window.add(widget._widget)

    def get_content_widget(self, widget):
        """Get the current content widget."""
        return self.content_widget

    def get_frame(self):
        pos = self._window.get_position()
        size = self._window.get_size()
        return widgets.Rect(pos[0], pos[1], size[0], size[1])

    def set_frame(self, x=None, y=None, width=None, height=None):
        if x is not None or y is not None:
            pos = self._window.get_position()
            x = x if x is not None else pos[0]
            y = y if y is not None else pos[1]
            self._window.move(x, y)

        if width is not None or height is not None:
            size = self._window.get_size()
            width = width if width is not None else size[0]
            height = height if height is not None else size[1]
            self._window.resize(width, height)

    def get_monitor_geometry(self):
        """Returns a Rect of the geometry of the monitor that this
        window is currently on.

        :returns: Rect
        """
        gtkwindow = self._window
        gdkwindow = gtkwindow.window
        screen = gtkwindow.get_screen()

        monitor = screen.get_monitor_at_window(gdkwindow)
        return screen.get_monitor_geometry(monitor)

    def check_position_and_fix(self):
        """This pulls the geometry of the monitor of the screen this
        window is on as well as the position of the window.

        It then makes sure that the position y is greater than the
        monitor geometry y.  This makes sure that the titlebar of
        the window is showing.
        """
        gtkwindow = self._window
        gdkwindow = gtkwindow.window
        monitor_geom = self.get_monitor_geometry()

        frame_extents = gdkwindow.get_frame_extents()
        position = gtkwindow.get_position()

        # if the frame is not visible, then we move the window so that
        # it is
        if frame_extents.y < monitor_geom.y:
            gtkwindow.move(position[0],
                           monitor_geom.y + (position[1] - frame_extents.y))


class DialogWindow(Window):
    def __init__(self, title, rect=None):
        Window.__init__(self, title, rect)
        self._window.set_resizable(False)


class MainWindow(Window):
    def __init__(self, title, rect):
        Window.__init__(self, title, rect)
        self.vbox = gtk.VBox()
        self._window.add(self.vbox)
        self.vbox.show()
        self._add_app_menubar()
        self.create_signal('save-dimensions')
        self.create_signal('save-maximized')
        self._window.connect('key-release-event', self.on_key_release)
        self._window.connect('window-state-event', self.on_window_state_event)
        self._window.connect('configure-event', self.on_configure_event)

    def _make_gtk_window(self):
        return WrappedWindow()

    def on_delete_window(self, widget, event):
        return True

    def on_configure_event(self, widget, event):
        (x, y) = self._window.get_position()
        (width, height) = self._window.get_size()
        self.emit('save-dimensions', x, y, width, height)

    def on_window_state_event(self, widget, event):
        maximized = bool(
            event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED)
        self.emit('save-maximized', maximized)

    def on_key_release(self, widget, event):
        if app.playback_manager.is_playing:
            if gtk.gdk.keyval_name(event.keyval) in ('Right', 'Left',
                                                     'Up', 'Down'):
                return True

    def _add_app_menubar(self):
        self.menubar = app.widgetapp.menubar
        self.vbox.pack_start(self.menubar._widget, expand=False)
        self.connect_menu_keyboard_shortcuts()

    def _add_content_widget(self, widget):
        self.vbox.pack_start(widget._widget, expand=True)


class DialogBase(WindowBase):
    def set_transient_for(self, window):
        self._window.set_transient_for(window._window)

    def run(self):
        running_dialogs.add(self)
        try:
            return self._run()
        finally:
            running_dialogs.remove(self)
            self._window = None

    def _run(self):
        """Run the dialog.  Must be implemented by subclasses."""
        raise NotImplementedError()

    def destroy(self):
        if self._window is not None:
            self._window.response(gtk.RESPONSE_NONE)
            # don't set self._window to None yet.  We will unset it when we
            # return from the _run() method


class Dialog(DialogBase):
    def __init__(self, title, description=None):
        """Create a dialog."""
        DialogBase.__init__(self)
        self.create_signal('open')
        self.create_signal('close')
        self.set_window(gtk.Dialog(title))
        self._window.set_default_size(425, -1)
        self.extra_widget = None
        self.buttons_to_add = []
        wrappermap.add(self._window, self)
        self.description = description

    def build_content(self):
        packing_vbox = layout.VBox(spacing=20)
        packing_vbox._widget.set_border_width(6)
        if self.description is not None:
            label = gtk.Label(self.description)
            label.set_line_wrap(True)
            label.set_size_request(390, -1)
            label.set_selectable(True)
            packing_vbox._widget.pack_start(label)
        if self.extra_widget:
            packing_vbox._widget.pack_start(self.extra_widget._widget)
        return packing_vbox

    def add_button(self, text):
        from lvc.widgets import dialogs
        _stock = {
            dialogs.BUTTON_OK.text: gtk.STOCK_OK,
            dialogs.BUTTON_CANCEL.text: gtk.STOCK_CANCEL,
            dialogs.BUTTON_YES.text: gtk.STOCK_YES,
            dialogs.BUTTON_NO.text: gtk.STOCK_NO,
            dialogs.BUTTON_QUIT.text: gtk.STOCK_QUIT,
            dialogs.BUTTON_REMOVE.text: gtk.STOCK_REMOVE,
            dialogs.BUTTON_DELETE.text: gtk.STOCK_DELETE,
            }
        if text in _stock:
            # store both the text and the stock ID
            text = _stock[text], text
        self.buttons_to_add.append(text)

    def pack_buttons(self):
        # There's a couple tricky things here:
        # 1) We need to add them in the reversed order we got them, since GTK
        # lays them out left-to-right
        #
        # 2) We can't use 0 as a response-id.  GTK only reserves positive
        # response_ids for the user.
        response_id = len(self.buttons_to_add)
        for text in reversed(self.buttons_to_add):
            label = None
            if isinstance(text, tuple):  # stock ID, text
                text, label = text
            button = self._window.add_button(text, response_id)
            if label is not None:
                button.set_label(label)
            response_id -= 1
        self.buttons_to_add = []
        self._window.set_default_response(1)

    def _run(self):
        self.pack_buttons()
        packing_vbox = self.build_content()
        self._window.vbox.pack_start(packing_vbox._widget, True, True)
        self._window.show_all()
        response = self._window.run()
        self._window.hide()
        if response == gtk.RESPONSE_DELETE_EVENT:
            return -1
        else:
            return response - 1  # response IDs started at 1

    def set_extra_widget(self, widget):
        self.extra_widget = widget

    def get_extra_widget(self):
        return self.extra_widget


class FileDialogBase(DialogBase):
    def _run(self):
        ret = self._window.run()
        self._window.hide()
        if ret == gtk.RESPONSE_OK:
            self._files = self._window.get_filenames()
            return 0


class FileOpenDialog(FileDialogBase):
    def __init__(self, title):
        FileDialogBase.__init__(self)
        self._files = None
        fcd = gtk.FileChooserDialog(title,
                                    action=gtk.FILE_CHOOSER_ACTION_OPEN,
                                    buttons=(gtk.STOCK_CANCEL,
                                             gtk.RESPONSE_CANCEL,
                                             gtk.STOCK_OPEN,
                                             gtk.RESPONSE_OK))

        self.set_window(fcd)

    def set_filename(self, text):
        self._window.set_filename(text)

    def set_select_multiple(self, value):
        self._window.set_select_multiple(value)

    def add_filters(self, filters):
        for name, ext_list in filters:
            f = gtk.FileFilter()
            f.set_name(name)
            for mem in ext_list:
                f.add_pattern('*.%s' % mem)
            self._window.add_filter(f)

        f = gtk.FileFilter()
        f.set_name(_('All files'))
        f.add_pattern('*')
        self._window.add_filter(f)

    def get_filenames(self):
        return [unicode(f) for f in self._files]

    def get_filename(self):
        if self._files is None:
            # clicked Cancel
            return None
        else:
            return unicode(self._files[0])

    # provide a common interface for file chooser dialogs
    get_path = get_filename

    def set_path(self, path):
        # set_filename puts the whole path in the filename field
        self._window.set_current_folder(os.path.dirname(path))
        self._window.set_current_name(os.path.basename(path))


class FileSaveDialog(FileDialogBase):
    def __init__(self, title):
        FileDialogBase.__init__(self)
        self._files = None
        fcd = gtk.FileChooserDialog(title,
                                    action=gtk.FILE_CHOOSER_ACTION_SAVE,
                                    buttons=(gtk.STOCK_CANCEL,
                                             gtk.RESPONSE_CANCEL,
                                             gtk.STOCK_SAVE,
                                             gtk.RESPONSE_OK))
        self.set_window(fcd)

    def set_filename(self, text):
        self._window.set_current_name(text)

    def get_filename(self):
        if self._files is None:
            # clicked Cancel
            return None
        else:
            return unicode(self._files[0])

    # provide a common interface for file chooser dialogs
    get_path = get_filename

    def set_path(self, path):
        # set_filename puts the whole path in the filename field
        self._window.set_current_folder(os.path.dirname(path))
        self._window.set_current_name(os.path.basename(path))


class DirectorySelectDialog(FileDialogBase):
    def __init__(self, title):
        FileDialogBase.__init__(self)
        self._files = None
        choose_str = 'Choose'
        fcd = gtk.FileChooserDialog(
            title,
            action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            buttons=(gtk.STOCK_CANCEL,
                     gtk.RESPONSE_CANCEL,
                     choose_str, gtk.RESPONSE_OK))
        self.set_window(fcd)

    def set_directory(self, text):
        self._window.set_filename(text)

    def get_directory(self):
        if self._files is None:
            # clicked Cancel
            return None
        else:
            return unicode(self._files[0])

    # provide a common interface for file chooser dialogs
    get_path = get_directory
    set_path = set_directory


class AboutDialog(Dialog):
    def __init__(self):
        Dialog.__init__(self, "Libre Video Converter")
#            _("About %(appname)s",
#              {'appname': app.config.get(prefs.SHORT_APP_NAME)}))
#        self.add_button(_("Close"))
        self.add_button("Close")
        self._window.set_has_separator(False)

    def build_content(self):
        packing_vbox = layout.VBox(spacing=20)
        # icon_pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
        #         resources.share_path('icons/hicolor/128x128/apps/miro.png'),
        #         48, 48)
        # packing_vbox._widget.pack_start(gtk.image_new_from_pixbuf(icon_pixbuf))
        # if app.config.get(prefs.APP_REVISION_NUM):
        #     version = "%s (%s)" % (
        #         app.config.get(prefs.APP_VERSION),
        #         app.config.get(prefs.APP_REVISION_NUM))
        # else:
        #     version = "%s" % app.config.get(prefs.APP_VERSION)
        version = '1.0.1'
        # name_label = gtk.Label(
        #     '<span size="xx-large" weight="bold">%s %s</span>' % (
        #         app.config.get(prefs.SHORT_APP_NAME), version))
        name_label = gtk.Label(
            '<span size="xx-large" weight="bold">%s %s</span>' % (
                'Libre Video Converter', version))
        name_label.set_use_markup(True)
        packing_vbox._widget.pack_start(name_label)
        copyright_text = 'Copyright (c) Jesus Eduardo (Heckyel) | 2017'
        copyright_label = gtk.Label('<small>%s</small>' % copyright_text)
        copyright_label.set_use_markup(True)
        copyright_label.set_justify(gtk.JUSTIFY_CENTER)
        packing_vbox._widget.pack_start(copyright_label)

        # FIXME - make the project url clickable
        # packing_vbox._widget.pack_start(
        #     gtk.Label(app.config.get(prefs.PROJECT_URL)))

        # contributor_label = gtk.Label(
        #     _("Thank you to all the people who contributed to %(appname)s "
        #       "%(version)s:",
        #       {"appname": app.config.get(prefs.SHORT_APP_NAME),
        #        "version": app.config.get(prefs.APP_VERSION)}))
        # contributor_label.set_justify(gtk.JUSTIFY_CENTER)
        # packing_vbox._widget.pack_start(contributor_label)

        # get contributors, remove newlines and wrap it
        # contributors = open(resources.path('CREDITS'), 'r').readlines()
        # contributors = [c[2:].strip()
        #                 for c in contributors if c.startswith("* ")]
        # contributors = ", ".join(contributors)

        # show contributors
        # contrib_buffer = gtk.TextBuffer()
        # contrib_buffer.set_text(contributors)

        # contrib_view = gtk.TextView(contrib_buffer)
        # contrib_view.set_editable(False)
        # contrib_view.set_cursor_visible(False)
        # contrib_view.set_wrap_mode(gtk.WRAP_WORD)
        # contrib_window = gtk.ScrolledWindow()
        # contrib_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        # contrib_window.add(contrib_view)
        # contrib_window.set_size_request(-1, 100)
        # packing_vbox._widget.pack_start(contrib_window)

        # FIXME - make the project url clickable
        # donate_label = gtk.Label(
        #     _("To help fund continued %(appname)s development, visit the "
        #       "donation page at:",
        #       {"appname": app.config.get(prefs.SHORT_APP_NAME)}))
        # donate_label.set_justify(gtk.JUSTIFY_CENTER)
        # packing_vbox._widget.pack_start(donate_label)

        # packing_vbox._widget.pack_start(
        #     gtk.Label(app.config.get(prefs.DONATE_URL)))
        return packing_vbox

    def on_contrib_link_event(self, texttag, widget, event, iter_):
        if event.type == gtk.gdk.BUTTON_PRESS:
            resources.open_url(
                'https://notabug.org/heckyel/librevideoconverter')

type_map = {
    0: gtk.MESSAGE_WARNING,
    1: gtk.MESSAGE_INFO,
    2: gtk.MESSAGE_ERROR
}


class AlertDialog(DialogBase):
    def __init__(self, title, description, alert_type):
        DialogBase.__init__(self)
        message_type = type_map.get(alert_type, gtk.MESSAGE_INFO)
        self.set_window(gtk.MessageDialog(type=message_type,
                                          message_format=description))
        self._window.set_title(title)
        self.description = description

    def add_button(self, text):
        self._window.add_button(_stock.get(text, text), 1)
        self._window.set_default_response(1)

    def _run(self):
        self._window.set_modal(False)
        self._window.show_all()
        response = self._window.run()
        self._window.hide()
        if response == gtk.RESPONSE_DELETE_EVENT:
            return -1
        else:
            # response IDs start at 1
            return response - 1