bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
1 |
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
try: |
|
18 |
import pygtk |
|
19 |
pygtk.require("2.0") |
|
20 |
except: |
|
21 |
pass
|
|
0.13.10
by Jelmer Vernooij
Don't pass around gladefile all the time. |
22 |
|
23 |
import gtk |
|
24 |
import gtk.glade |
|
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
25 |
|
93.1.6
by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile) |
26 |
from olive import OlivePreferences |
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
27 |
from dialog import error_dialog |
93.1.12
by Alexander Belchenko
Names XML files with GUI resources obtained via olive/guifiles.py |
28 |
from guifiles import GLADEFILENAME |
93.1.6
by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile) |
29 |
|
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
30 |
|
31 |
class OliveBookmark: |
|
32 |
""" Display the Edit bookmark dialog and perform the needed actions. """ |
|
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
33 |
def __init__(self, selected): |
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
34 |
""" Initialize the Edit bookmark dialog. """ |
93.1.6
by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile) |
35 |
self.glade = gtk.glade.XML(GLADEFILENAME, 'window_bookmark', 'olive-gtk') |
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
36 |
|
37 |
self.window = self.glade.get_widget('window_bookmark') |
|
38 |
||
121
by Szilveszter Farkas (Phanatic)
Use OliveBookmarkDialog instead of OliveBookmark. |
39 |
self.pref = OlivePreferences() |
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
40 |
|
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
41 |
# Dictionary for signal_autoconnect
|
42 |
dic = { "on_button_bookmark_save_clicked": self.bookmark, |
|
43 |
"on_button_bookmark_cancel_clicked": self.close } |
|
44 |
||
45 |
# Connect the signals to the handlers
|
|
46 |
self.glade.signal_autoconnect(dic) |
|
47 |
||
48 |
# Get some important widgets
|
|
49 |
self.entry_location = self.glade.get_widget('entry_bookmark_location') |
|
50 |
self.entry_title = self.glade.get_widget('entry_bookmark_title') |
|
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
51 |
|
52 |
self.selected = selected |
|
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
53 |
|
54 |
def display(self): |
|
55 |
""" Display the Edit bookmark dialog. """ |
|
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
56 |
path = self.selected |
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
57 |
self.entry_location.set_text(path) |
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
58 |
self.entry_title.set_text(self.pref.get_bookmark_title(path)) |
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
59 |
self.window.show_all() |
60 |
||
61 |
def bookmark(self, widget): |
|
62 |
if self.entry_title.get_text() == '': |
|
0.13.6
by Jelmer Vernooij
Don't pass along dialog context everywhere. |
63 |
error_dialog(_('No title given'), |
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
64 |
_('Please specify a title to continue.')) |
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
65 |
return
|
66 |
||
0.8.93
by Szilveszter Farkas (Phanatic)
Some further cleanups. More to come. |
67 |
self.pref.set_bookmark_title(self.entry_location.get_text(), |
68 |
self.entry_title.get_text()) |
|
69 |
self.pref.write() |
|
0.8.57
by Szilveszter Farkas (Phanatic)
Bookmarks have titles; you can also edit them. |
70 |
|
71 |
self.close() |
|
72 |
||
73 |
def close(self, widget=None): |
|
74 |
self.window.destroy() |
|
121
by Szilveszter Farkas (Phanatic)
Use OliveBookmarkDialog instead of OliveBookmark. |
75 |
|
76 |
class OliveBookmarkDialog(gtk.Dialog): |
|
77 |
""" This class wraps the old Bookmark window into a gtk.Dialog. """ |
|
78 |
||
79 |
def __init__(self, selected, parent=None): |
|
80 |
""" Initialize the Bookmark dialog. """ |
|
81 |
gtk.Dialog.__init__(self, title="Bookmarks - Olive", |
|
82 |
parent=parent, |
|
83 |
flags=0, |
|
84 |
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) |
|
85 |
||
86 |
self.pref = OlivePreferences() |
|
87 |
||
88 |
# Get arguments
|
|
89 |
self.selected = selected |
|
90 |
||
91 |
# Create widgets
|
|
92 |
self._label_location = gtk.Label(_("Location:")) |
|
93 |
self._label_title = gtk.Label(_("Title:")) |
|
94 |
self._entry_location = gtk.Entry() |
|
95 |
self._entry_title = gtk.Entry() |
|
96 |
self._button_save = gtk.Button(stock=gtk.STOCK_SAVE) |
|
97 |
||
98 |
self._button_save.connect('clicked', self._on_save_clicked) |
|
99 |
||
100 |
# Set default values
|
|
101 |
self._entry_location.set_text(self.selected) |
|
102 |
self._entry_location.set_sensitive(False) |
|
103 |
self._entry_title.set_text(self.pref.get_bookmark_title(self.selected)) |
|
104 |
self._entry_title.set_flags(gtk.CAN_FOCUS | gtk.HAS_FOCUS) |
|
105 |
||
106 |
# Create a table and put widgets into it
|
|
107 |
self._table = gtk.Table(rows=2, columns=2) |
|
108 |
self._table.attach(self._label_location, 0, 1, 0, 1) |
|
109 |
self._table.attach(self._label_title, 0, 1, 1, 2) |
|
110 |
self._table.attach(self._entry_location, 1, 2, 0, 1) |
|
111 |
self._table.attach(self._entry_title, 1, 2, 1, 2) |
|
112 |
||
113 |
self._label_location.set_alignment(0, 0.5) |
|
114 |
self._label_title.set_alignment(0, 0.5) |
|
115 |
self._table.set_row_spacings(3) |
|
116 |
self._table.set_col_spacings(3) |
|
117 |
self.vbox.set_spacing(3) |
|
118 |
||
119 |
self.vbox.add(self._table) |
|
120 |
||
121 |
self.action_area.pack_end(self._button_save) |
|
122 |
||
123 |
self.vbox.show_all() |
|
124 |
||
125 |
def _on_save_clicked(self, button): |
|
126 |
""" Save button clicked handler. """ |
|
127 |
if self._entry_title.get_text() == '': |
|
128 |
error_dialog(_('No title given'), |
|
129 |
_('Please specify a title to continue.')) |
|
130 |
return
|
|
131 |
||
132 |
self.pref.set_bookmark_title(self._entry_location.get_text(), |
|
133 |
self._entry_title.get_text()) |
|
134 |
self.pref.write() |
|
135 |
||
136 |
self.response(gtk.RESPONSE_OK) |