~gary-lasker/software-center/list-view-stars-gtk3

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/widgets/symbolic_icons.py

  • Committer: Michael Vogt
  • Date: 2011-08-02 08:30:26 UTC
  • mfrom: (1917.9.26 the-aesthetics)
  • Revision ID: michael.vogt@ubuntu.com-20110802083026-rvx4cxg7o2j232l8
merged from lp:~mmcg069/software-center/the-aesthetics with some minor tweaks (disable JS and plugins in webkit, set datadir globally in symbolic_icons tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
 
22
22
from math import pi as PI
23
 
from gi.repository import Gtk, Gdk, GObject
 
23
from gi.repository import Gtk, Gdk, GObject, PangoCairo
24
24
 
25
25
import softwarecenter.paths
 
26
from softwarecenter.ui.gtk3.em import em
26
27
from softwarecenter.ui.gtk3.drawing import rounded_rect
27
28
 
28
29
# pi constants
45
46
        # get base dir
46
47
        SYMBOLIC_DIR = os.path.join(
47
48
            softwarecenter.paths.datadir, "ui/gtk3/art/icons/")
 
49
 
48
50
        drop_shadow_path = SYMBOLIC_DIR + self.DROPSHADOW % name
49
51
        self.drop_shadow = cairo.ImageSurface.create_from_png(drop_shadow_path)
50
52
        icon_path = SYMBOLIC_DIR + self.ICON % name
124
126
 
125
127
class PendingSymbolicIcon(SymbolicIcon, RotationAboutCenterAnimation):
126
128
 
127
 
    BUBBLE_BORDER_RADIUS = 4
 
129
    BUBBLE_MAX_BORDER_RADIUS = em()
128
130
    BUBBLE_XPADDING = 5
129
131
    BUBBLE_YPADDING = 2
130
132
    BUBBLE_FONT_DESC = "Bold 8.5"
154
156
        cr.restore()
155
157
 
156
158
        if not self.is_animating() or not self.transaction_count: return
 
159
 
157
160
        # paint transactions bubble
 
161
 
158
162
        # get the layout extents and calc the bubble size
159
163
        ex = self.layout.get_pixel_extents()[1]
160
164
        x = (a.width - self.icon.get_width()) / 2 + self.icon.get_width() - ex.width + 2
161
165
        y = (a.height - self.icon.get_height()) / 2 + self.icon.get_height() - ex.height + 2
162
166
        w = ex.width + 2*self.BUBBLE_XPADDING
163
167
        h = ex.height + 2*self.BUBBLE_YPADDING
 
168
 
 
169
        border_radius = w/3
 
170
        if border_radius > self.BUBBLE_MAX_BORDER_RADIUS:
 
171
            border_radius = self.BUBBLE_MAX_BORDER_RADIUS
 
172
 
164
173
        # paint background
165
 
        rounded_rect(cr, x+1, y+1, w-2, h-2, self.BUBBLE_BORDER_RADIUS)
166
 
        cr.set_source_rgba(0,0,0,0.75)
 
174
        context = widget.get_style_context()
 
175
        context.save()
 
176
        color = context.get_background_color(Gtk.StateFlags.SELECTED)
 
177
        rounded_rect(cr, x+1, y+1, w-2, h-2, border_radius)
 
178
        Gdk.cairo_set_source_rgba(cr, color)
167
179
        cr.fill()
 
180
        context.restore()
 
181
 
168
182
        # paint outline
169
 
        #~ rounded_rect(cr, x+0.5, y+0.5, w-1, h-1, self.BUBBLE_BORDER_RADIUS)
170
 
        #~ cr.set_source_rgba(1,1,1, 0.85)
171
 
        #~ cr.set_line_width(1)
172
 
        #~ cr.stroke()
 
183
        rounded_rect(cr, x+1.5, y+1.5, w-3, h-3, border_radius-1)
 
184
        cr.set_source_rgb(1,1,1)
 
185
        cr.set_line_width(1)
 
186
        cr.stroke()
 
187
 
173
188
        # paint layout
174
 
        Gtk.render_layout(widget.get_style_context(), cr,
175
 
                          x + self.BUBBLE_XPADDING,
176
 
                          y + self.BUBBLE_YPADDING,
177
 
                          self.layout)
 
189
        cr.save()
 
190
        cr.translate(x+(w-ex.width)*0.5, y+(h-ex.height)*0.5)
 
191
        cr.move_to(0, 1)
 
192
        PangoCairo.layout_path(cr, self.layout)
 
193
        cr.set_source_rgba(0,0,0,0.6)
 
194
        cr.fill()
 
195
        Gtk.render_layout(context, cr, 0, 0, self.layout)
 
196
        cr.restore()
178
197
        return
179
198
 
180
199
    def set_transaction_count(self, count):
181
200
        if count == self.transaction_count: return
182
201
        self.transaction_count = count
183
 
        m = '<span font_desc="%s">%i</span>' % (self.BUBBLE_FONT_DESC,
184
 
                                                count)
 
202
        m = '<span font_desc="%s" color="%s">%i</span>' % (self.BUBBLE_FONT_DESC,
 
203
                                                           "white", 
 
204
                                                           count)
185
205
        self.layout.set_markup(m, -1)
186
206
        self.queue_draw()
187
207
        return
188
208
 
189
209
 
190
210
if __name__ == "__main__":
 
211
    softwarecenter.paths.datadir = os.path.join(os.getcwd(), 'data')
 
212
 
191
213
    win = Gtk.Window()
 
214
    win.set_border_width(20)
192
215
    hb = Gtk.HBox(spacing=12)
193
216
    win.add(hb)
194
217
    ico = SymbolicIcon("available")
197
220
    ico.start()
198
221
    ico.set_transaction_count(33)
199
222
    hb.add(ico)
 
223
    ico = PendingSymbolicIcon("pending")
 
224
    ico.start()
 
225
    ico.set_transaction_count(1)
 
226
    hb.add(ico)
200
227
    win.show_all()
201
228
    win.connect("destroy", Gtk.main_quit)
202
229
    Gtk.main()