~umang/indicator-stickynotes/trunk

« back to all changes in this revision

Viewing changes to stickynotes/gui.py

  • Committer: Umang Varma
  • Date: 2012-07-25 03:26:43 UTC
  • Revision ID: git-v1:492b83b785d2f4be607a7f2795d3ad05db3dcff7
Added text color editing support

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        with open(os.path.join(self.path, "style.css")) as css_file:
60
60
            self.css_template = Template(css_file.read())
61
61
        self.css = Gtk.CssProvider()
 
62
        self.style_contexts = [self.winMain.get_style_context(),
 
63
                self.txtNote.get_style_context()]
62
64
        # Update window-specific style. Global styles are loaded initially!
63
65
        self.update_style()
64
66
        # Ensure buttons are displayed with images
121
123
        css_string = self.css_template.substitute(**self.css_data())\
122
124
                .encode("ascii", "replace")
123
125
        self.css.load_from_data(css_string)
124
 
        Gtk.StyleContext.add_provider(self.winMain.get_style_context(),
125
 
                self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
 
126
        for context in self.style_contexts:
 
127
            context.add_provider(self.css,
 
128
                    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
126
129
 
127
130
    def css_data(self):
128
131
        """Returns data to substitute into the CSS template"""
129
132
        data = {}
130
 
        # Converts from HSV to RGB hex. All values are scaled to a max of 1
131
 
        hsv_to_hex = lambda x: "#" + "".join(["{:02x}".format(int(255*a))
132
 
            for a in colorsys.hsv_to_rgb(*x)])
 
133
        # Converts to RGB hex. All RGB/HSV values are scaled to a max of 1
 
134
        rgb_to_hex = lambda x: "#" + "".join(["{:02x}".format(int(255*a))
 
135
            for a in x])
 
136
        hsv_to_hex = lambda x: rgb_to_hex(colorsys.hsv_to_rgb(*x))
133
137
        bg_end_hsv = self.noteset.properties.get("d_bgcolor_hsv", [56./360, 1, 1])
134
138
        # bg_start_hsv is computed by "lightening" bg_end_hsv. 
135
139
        bg_start_hsv = [bg_end_hsv[0], bg_end_hsv[1], bg_end_hsv[2] + .60]
140
144
            bg_start_hsv[1] = 0
141
145
        data.update({"bg_start": hsv_to_hex(bg_start_hsv), "bg_end":
142
146
                hsv_to_hex(bg_end_hsv)})
 
147
        data["text_color"] = rgb_to_hex(self.noteset.properties.\
 
148
                get("d_textcolor", [0, 0, 0]))
143
149
        return data
144
150
 
145
151
    def save(self, *args):
199
205
        self.builder = Gtk.Builder()
200
206
        self.builder.add_from_file(glade_file)
201
207
        self.builder.connect_signals(self)
202
 
        widgets = ["wSettings", "bgcolor"]
 
208
        widgets = ["wSettings", "bgcolor", "textcolor"]
203
209
        for w in widgets:
204
210
            setattr(self, w, self.builder.get_object(w))
205
211
        self.bgcolor.set_rgba(Gdk.RGBA(*colorsys.hsv_to_rgb(
206
212
            *self.noteset.properties.get("d_bgcolor_hsv", [56./360, 1, 1])), alpha=1))
207
 
        self.textcolor.set_rgba(Gdk.RGBA(*colorsys.hsv_to_rgb(
208
 
            *self.noteset.properties.get("d_textcolor", [0, 0, 0])), alpha=1))
 
213
        self.textcolor.set_rgba(Gdk.RGBA(*self.noteset.properties.\
 
214
                get("d_textcolor", [0, 0, 0]), alpha=1))
209
215
        ret =  self.wSettings.run()
210
216
        self.wSettings.destroy()
211
217
 
218
224
        # Remind GtkSourceView's that they are transparent, etc.
219
225
        load_global_css()
220
226
 
 
227
    def update_textcolor(self, *args):
 
228
        rgba = self.textcolor.get_rgba()
 
229
        self.noteset.properties["d_textcolor"] = [rgba.red, rgba.green, rgba.blue]
 
230
        for note in self.noteset.notes:
 
231
            note.gui.update_style()