~cmiller/+junk/notify-friends-contacts

« back to all changes in this revision

Viewing changes to ui/views/webpage.py

  • Committer: Chad MILLER
  • Date: 2010-07-03 23:18:35 UTC
  • mfrom: (2.1.2 contacts_sync)
  • Revision ID: cmiller@hypatia-20100703231835-jqd5pmqcrlfb3avg
Merge Mandel's ui code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
import os
 
3
import gtk
 
4
import logging
 
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
 
9
 
 
10
logger = logging.getLogger("macaco.ui.webpage")
 
11
 
 
12
class WebpageDialog(gtk.Dialog):
 
13
 
 
14
    __gtype_name__ = "WebpageDialog"
 
15
 
 
16
    def __init__(self):
 
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().
 
21
 
 
22
        Use the convenience function NewWebpageDialog to create
 
23
        a WebpageDialog object.
 
24
 
 
25
        """
 
26
        pass
 
27
 
 
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.
 
32
 
 
33
        """
 
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())
 
52
 
 
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().
 
56
 
 
57
        """
 
58
        self._presentor.read_web()
 
59
        self.destroy()
 
60
 
 
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()
 
64
 
 
65
        """
 
66
        self.destroy()
 
67
 
 
68
    ###########################################################################
 
69
    #################### implementation of WebpageView ########################
 
70
    ###########################################################################
 
71
 
 
72
    def _get_object(self):
 
73
        """
 
74
        @rtype: Url
 
75
        @return: The web that is displayed
 
76
        """
 
77
        return self._presentor.web
 
78
 
 
79
    def _set_object(self, value):
 
80
        """
 
81
        @type value: Url
 
82
        @param value: the Url to display in the UI.
 
83
        """
 
84
        self._presentor.web = value
 
85
        self._presentor.write_web()
 
86
 
 
87
    object = property(_get_object, _set_object)
 
88
 
 
89
    def _get_url(self):
 
90
        """
 
91
        @rtype: string
 
92
        @return: The url that is displayed in the UI.
 
93
        """
 
94
        return self.builder.get_object("url_entry").get_text()
 
95
 
 
96
    def _set_url(self, value):
 
97
        """
 
98
        @type value: string
 
99
        @param value: The new url to show in the UI.
 
100
        """
 
101
        self.builder.get_object("url_entry").set_text(value)
 
102
 
 
103
    url = property(_get_url, _set_url)
 
104
 
 
105
    def _get_description(self):
 
106
        """
 
107
        @rtype: string
 
108
        @return: The description currently displyed in the UI.
 
109
        """
 
110
        item = self.__type_box.get_active_iter()
 
111
        index = self.__type_store.get_value(item, 2)
 
112
        return URL_DESCRIPTIONS[index]
 
113
 
 
114
    def _set_description(self, value):
 
115
        """
 
116
        @type value: string
 
117
        @param value: The new description to show in the ui.
 
118
        """
 
119
        if value is None:
 
120
                self.__type_box.set_active_iter(self.__type_store.get_iter_first())
 
121
        else:
 
122
            if value == HOME_PAGE_URL:
 
123
                index = 0
 
124
            else:
 
125
                index = 1
 
126
            self.__type_box.set_active_iter(self.__type_store.get_iter(index))
 
127
 
 
128
    description = property(_get_description, _set_description)
 
129
 
 
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.
 
134
 
 
135
    """
 
136
 
 
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):
 
140
        ui_filename = None
 
141
 
 
142
    builder = gtk.Builder()
 
143
    builder.add_from_file(ui_filename)
 
144
    dialog = builder.get_object("webpage_dialog")
 
145
    dialog.finish_initializing(builder)
 
146
    if url is not None:
 
147
        dialog.object = url
 
148
    return dialog
 
149
 
 
150
if __name__ == "__main__":
 
151
    dialog = NewWebpageDialog(Url("http://www.google.com"))
 
152
    dialog.show()
 
153
    gtk.main()