5
from contacts_sync.ui.data import getdatapath
6
from contacts_sync.contact_data import Url, URL_DESCRIPTIONS, HOME_PAGE_URL, BLOG_URL
7
from contacts_sync.ui.icons import get_url_icon
8
from contacts_sync.ui.presenters.webpage import WebpagePresenter
10
logger = logging.getLogger("macaco.ui.webpage")
12
class WebpageDialog(gtk.Dialog):
14
__gtype_name__ = "WebpageDialog"
17
"""__init__ - This function is typically not called directly.
18
Creation of a WebpageDialog requires redeading the associated ui
19
file and parsing the ui definition extrenally,
20
and then calling WebpageDialog.finish_initializing().
22
Use the convenience function NewWebpageDialog to create
23
a WebpageDialog object.
28
def finish_initializing(self, builder):
29
"""finish_initalizing should be called after parsing the ui definition
30
and creating a WebpageDialog object with it in order to finish
31
initializing the start of the new WebpageDialog instance.
34
#get a reference to the builder and set up the signals
35
self.builder = builder
36
self.builder.connect_signals(self)
37
self._presentor = WebpagePresenter(self)
38
self.__type_box = self.builder.get_object("type_box")
39
self.__type_store = self.builder.get_object("type_store")
40
# we add the values for the list box.
41
text_cell = gtk.CellRendererText()
42
self.__type_box.pack_start(text_cell, True)
43
self.__type_box.add_attribute(text_cell, 'text',0)
44
logo_cell = gtk.CellRendererPixbuf()
45
self.__type_box.pack_start(logo_cell, False)
46
self.__type_box.add_attribute(logo_cell, 'pixbuf', 1)
47
# we add the different columns to the combobox
48
self.__type_store.append(["Home Page", get_url_icon(HOME_PAGE_URL), 0])
49
self.__type_store.append(["Blog", get_url_icon(BLOG_URL), 1])
50
# set the default type
51
self.__type_box.set_active_iter(self.__type_store.get_iter_first())
53
def ok(self, widget, data=None):
54
"""ok - The user has elected to save the changes.
55
Called before the dialog returns gtk.RESONSE_OK from run().
58
self._presentor.read_web()
61
def cancel(self, widget, data=None):
62
"""cancel - The user has elected cancel changes.
63
Called before the dialog returns gtk.RESPONSE_CANCEL for run()
68
###########################################################################
69
#################### implementation of WebpageView ########################
70
###########################################################################
72
def _get_object(self):
75
@return: The web that is displayed
77
return self._presentor.web
79
def _set_object(self, value):
82
@param value: the Url to display in the UI.
84
self._presentor.web = value
85
self._presentor.write_web()
87
object = property(_get_object, _set_object)
92
@return: The url that is displayed in the UI.
94
return self.builder.get_object("url_entry").get_text()
96
def _set_url(self, value):
99
@param value: The new url to show in the UI.
101
self.builder.get_object("url_entry").set_text(value)
103
url = property(_get_url, _set_url)
105
def _get_description(self):
108
@return: The description currently displyed in the UI.
110
item = self.__type_box.get_active_iter()
111
index = self.__type_store.get_value(item, 2)
112
return URL_DESCRIPTIONS[index]
114
def _set_description(self, value):
117
@param value: The new description to show in the ui.
120
self.__type_box.set_active_iter(self.__type_store.get_iter_first())
122
if value == HOME_PAGE_URL:
126
self.__type_box.set_active_iter(self.__type_store.get_iter(index))
128
description = property(_get_description, _set_description)
130
def NewWebpageDialog(url=None):
131
"""NewWebpageDialog - returns a fully instantiated
132
dialog-camel_case_nameDialog object. Use this function rather than
133
creating WebpageDialog instance directly.
137
#look for the ui file that describes the ui
138
ui_filename = os.path.join(getdatapath(), 'WebpageDialog.ui')
139
if not os.path.exists(ui_filename):
142
builder = gtk.Builder()
143
builder.add_from_file(ui_filename)
144
dialog = builder.get_object("webpage_dialog")
145
dialog.finish_initializing(builder)
150
if __name__ == "__main__":
151
dialog = NewWebpageDialog(Url("http://www.google.com"))