~thomas-deruyter-3/qreator/qreator

« back to all changes in this revision

Viewing changes to qreator/QreatorWindow.py

  • Committer: David Planella
  • Date: 2012-05-17 10:08:19 UTC
  • Revision ID: david.planella@ubuntu.com-20120517100819-kwasz64e9efbs3np
Started adding more bling to the QR code drawing area with Cairo

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from gettext import gettext as _
19
19
gettext.textdomain('qreator')
20
20
 
 
21
import cairo
 
22
import math
21
23
from gi.repository import Gtk, Gdk  # pylint: disable=E0611
22
24
from gi.repository import GtkChamplain, Clutter, Champlain
23
25
import logging
290
292
        if text == '':
291
293
            return
292
294
 
 
295
        x = 0.0
 
296
        y = 0.0        
 
297
        width = widget.get_allocated_width()
 
298
        height = widget.get_allocated_height()
 
299
        aspect = 1.0
 
300
        corner_radius = height / 50.0
 
301
 
 
302
        radius = corner_radius / aspect
 
303
        degrees = math.pi / 180.0
 
304
 
 
305
        lg = cairo.LinearGradient(0.0, 0.0, 500.0, 500.0)
 
306
        lg.add_color_stop_rgba(0, 1, 1, 1, 1)
 
307
        lg.add_color_stop_rgba(1, 0.678, 0.678, 0.678, 1)
 
308
        
 
309
        #rg = cairo.RadialGradient(w/2.0, 0.0, 100.6,
 
310
        #                          w/2.0, 0.0, 500.0)
 
311
        #rg.add_color_stop_rgba(0, 1, 1, 1, 1)
 
312
        #rg.add_color_stop_rgba(1, 0.678, 0.678, 0.678, 1)
 
313
        
 
314
        ctx.set_source(lg)
 
315
        #ctx.rectangle(0, 0, width, height)
 
316
        
 
317
        ctx.new_sub_path()
 
318
        ctx.arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees)
 
319
        ctx.arc(x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees)
 
320
        ctx.arc(x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees)
 
321
        ctx.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees)
 
322
        ctx.close_path()
 
323
 
 
324
        ctx.fill()
 
325
        
 
326
        # Fill the background
 
327
        #ctx.set_source_rgb(0.678, 0.678, 0.678)
 
328
        #ctx.rectangle(0, 0, w, h)
 
329
        #ctx.fill()
 
330
        ##ctx.set_line_width(14)
 
331
        #cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
 
332
        #ctx.set_source_rgb(1, 0, 1)
 
333
        #ctx.stroke_preserve()
 
334
        #ctx.paint()
 
335
 
293
336
        # Create the QR code
294
337
        qr_code = QRCode()
295
338
        self.surface = qr_code.encode(text, QRCodeOutput.CAIRO_SURFACE)
307
350
 
308
351
 
309
352
def get_current_location():
310
 
    '''Gets the current location from geolocation via IP (only method)
311
 
       currently supported'''
 
353
    '''Gets the current location from geolocation via IP (only method
 
354
       currently supported)'''
312
355
 
313
356
    location = Geoclue.DiscoverLocation()
314
357
    location.init()