~umang/indicator-stickynotes/trunk

« back to all changes in this revision

Viewing changes to stickynotes/gui.py

  • Committer: Umang Varma
  • Date: 2015-07-01 16:45:35 UTC
  • Revision ID: git-v1:9bff8a94ec55fbd75cd12f242146ddc2c2e5ca50
Switch to -dark icons if using dark background

-dark icons are generated using "convert icon.png -negate icon-dark.png"

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        # Get necessary objects
64
64
        self.winMain.set_name("main-window")
65
65
        widgets = ["txtNote", "bAdd", "imgAdd", "imgResizeR", "eResizeR",
66
 
                "bLock", "imgLock", "imgUnlock", "bClose",
67
 
                "confirmDelete", "movebox1", "movebox2"]
 
66
                "bLock", "imgLock", "imgUnlock", "imgClose", "imgDropdown",
 
67
                "bClose", "confirmDelete", "movebox1", "movebox2"]
68
68
        for w in widgets:
69
69
            setattr(self, w, self.builder.get_object(w))
70
70
        self.style_contexts = [self.winMain.get_style_context(),
170
170
 
171
171
    def update_style(self):
172
172
        """Updates the style using CSS template"""
 
173
        self.update_button_color()
173
174
        css_string = self.css_template.substitute(**self.css_data())\
174
175
                .encode("ascii", "replace")
175
176
        self.css.load_from_data(css_string)
177
178
            context.add_provider(self.css,
178
179
                    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
179
180
 
 
181
    def update_button_color(self):
 
182
        """Switches between regular and dark icons appropriately"""
 
183
        lightness = sum(colorsys.hsv_to_rgb(*self.note.cat_prop("bgcolor_hsv")))
 
184
        suffix = "-dark" if lightness <= 1 else ""
 
185
        iconfiles = {"imgAdd":"add", "imgClose":"close", "imgDropdown":"menu",
 
186
                "imgLock":"lock", "imgUnlock":"unlock", "imgResizeR":"resizer"}
 
187
        for img, filename in iconfiles.items():
 
188
            getattr(self, img).set_from_file("Icons/" + filename + suffix +
 
189
                    ".png")
 
190
 
180
191
    def css_data(self):
181
192
        """Returns data to substitute into the CSS template"""
182
193
        data = {}