~thomas-deruyter-3/qreator/qreator

« back to all changes in this revision

Viewing changes to qreator/QreatorWindow.py

  • Committer: David Planella
  • Date: 2012-02-10 19:18:24 UTC
  • Revision ID: david.planella@ubuntu.com-20120210191824-2l8s07g9ysrdg93y
Added some documentation, cleaned up the QRCode's object methods a bit

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import Geoclue
20
20
from QRCode import QRCode as QRCode
 
21
from QRCode import QRCodeOutput as QRCodeOutput
21
22
 
22
23
COL_TEXT = 0
23
24
COL_PIXBUF = 1
51
52
        self.PreferencesDialog = PreferencesQreatorDialog
52
53
 
53
54
        # Code for other initialization actions should be added here.
 
55
 
 
56
        # Initialize the clipboard
54
57
        self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
 
58
 
 
59
        # Initialize the style for the main toolbar
55
60
        context = self.ui.toolbar1.get_style_context()
56
61
        context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
 
62
 
 
63
        # Initialize the Cairo surface that will contain the QR code
57
64
        self.surface = None
 
65
 
 
66
        # Initialize the icon view widget
58
67
        self.ui.iconview1.set_text_column(COL_TEXT)
59
68
        self.ui.iconview1.set_pixbuf_column(COL_PIXBUF)
60
69
 
 
70
        # Hide the notebook tabs
61
71
        self.ui.notebook1.set_show_tabs(False)
62
72
 
63
73
        self.qr_code_placeholder = 'aa'
69
79
        return True
70
80
 
71
81
    def on_toolbuttonHome_clicked(self, widget, data=None):
 
82
        '''Shows the home page'''
72
83
        self.ui.notebook1.set_current_page(PAGE_HOME)
73
84
 
74
85
    def on_toolbuttonHistory_clicked(self, widget, data=None):
 
86
        '''Shows the history page'''
75
87
        self.ui.notebook1.set_current_page(PAGE_HISTORY)
76
88
 
77
89
    def on_toolbuttonSettings_clicked(self, widget, data=None):
 
90
        '''Shows the settings page'''
78
91
        self.ui.notebook1.set_current_page(PAGE_SETTINGS)
79
92
 
80
93
    def on_toolbuttonAbout_clicked(self, widget, data=None):
 
94
        '''Shows the about page'''
81
95
        self.ui.notebook1.set_current_page(PAGE_ABOUT)
82
96
 
83
97
    def on_iconview1_item_activated(self, widget, item):
 
98
        '''Loads the UI for the appropriate QR type'''
84
99
 
85
100
        model = widget.get_model()
86
101
        qr_type = model[item][COL_ID]
87
102
 
 
103
        # We're loading each UI type inside this grid
88
104
        grid = self.ui.grid1
89
105
 
 
106
        # FIXME: the way of choosing the page is a bit of a hack for now
90
107
        if qr_type + PAGE_URL == PAGE_URL:
 
108
            # We're now loading the UI for the URL QR type
91
109
            entry1 = Gtk.Entry()
92
110
            entry1.connect('changed', self.on_entry1_changed)
93
111
            entry1.set_hexpand(True)
 
112
 
 
113
            # Remove the current widgets from the top half of the UI,
 
114
            # replace them with the current QR type's UI
94
115
            children = grid.get_children()
95
116
            grid.remove(children[0])
96
117
            grid.attach(entry1, 0, 0, 1, 1)
97
118
 
98
119
        elif qr_type + PAGE_URL == PAGE_GEO:
99
 
            # Map loading
 
120
            # We're now loading the UI for the map QR type
100
121
            map_widget = GtkChamplain.Embed()
101
122
            map_widget.set_hexpand(True)
102
123
            map_widget.set_vexpand(True)
103
 
            
 
124
 
104
125
            map_grid = Gtk.Grid()
105
126
            map_grid.attach(map_widget, 0, 0, 2, 1)
106
 
            
107
 
            #map_location_grid = Gtk.Grid()
 
127
 
108
128
            lat_entry = Gtk.Entry()
109
129
            lat_entry.set_hexpand(True)
110
130
            lat_label = Gtk.Label(_('Latitude:'))
111
131
            lat_label.set_alignment(xalign=0, yalign=0.5)
112
 
            #lat_label.set_hexpand(True)
113
132
            lon_entry = Gtk.Entry()
114
133
            lon_label = Gtk.Label(_('Longitude:'))
115
134
            lon_label.set_alignment(xalign=0, yalign=0.5)
123
142
                                    Gtk.PositionType.RIGHT, 1, 1)
124
143
            map_grid.attach_next_to(lon_entry, lon_label,
125
144
                                    Gtk.PositionType.RIGHT, 1, 1)
126
 
            
127
 
          
 
145
 
 
146
            # Remove the current widgets from the top half of the UI,
 
147
            # replace them with the current QR type's UI
128
148
            children = grid.get_children()
129
149
            grid.remove(children[0])
130
150
            self.ui.grid1.attach(map_grid, 0, 0, 1, 1)
134
154
            map_widget.connect('button-release-event',
135
155
                               self.on_map_widget_button_press_event,
136
156
                               self.map_view)
 
157
 
 
158
            # Get the current location, center the map on it, and initialize
 
159
            # other map features
137
160
            latitude, longitude = get_current_location()
138
161
            self.map_view.center_on(latitude, longitude)
139
162
            self.map_view.set_zoom_level(15)
217
240
 
218
241
        # Create the QR code
219
242
        qr_code = QRCode()
220
 
        self.surface = qr_code.encode_to_cairo(text)
 
243
        self.surface = qr_code.encode(text, QRCodeOutput.CAIRO_SURFACE)
221
244
 
222
245
        # Center the image in the drawing area
223
246
        centered_width, centered_height = \
232
255
 
233
256
 
234
257
def get_current_location():
 
258
    '''Gets the current location from geolocation via IP (only method)
 
259
       currently supported'''
 
260
 
235
261
    location = Geoclue.DiscoverLocation()
236
262
    location.init()
237
263
    location.set_position_provider(POS_PROVIDER)
238
264
    position = location.get_location_info()
 
265
 
239
266
    return position['latitude'], position['longitude']