Created
October 2, 2014 00:38
-
-
Save carlos-jenkins/8eb6083c6db148743d74 to your computer and use it in GitHub Desktop.
Example of using Font Awesome in a PyGObject application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright (C) 2014 Carlos Jenkins <[email protected]> | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, | |
# software distributed under the License is distributed on an | |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
# KIND, either express or implied. See the License for the | |
# specific language governing permissions and limitations | |
# under the License. | |
""" | |
Example of using Font Awesome in a PyGObject application. | |
""" | |
from gi.repository import Gtk | |
class MyApp(object): | |
def __init__(self): | |
""" | |
Build GUI | |
""" | |
# States | |
self.swap = False | |
# Build GUI from Glade file | |
self.builder = Gtk.Builder() | |
self.builder.add_from_file('ui.glade') | |
# Get objects | |
go = self.builder.get_object | |
self.window = go('window') | |
self.button = go('button') | |
self.label = go('label') | |
# Connect signals | |
self.builder.connect_signals(self) | |
# Configure interface | |
self.window.connect('delete-event', lambda x, y: Gtk.main_quit()) | |
# Everything is ready | |
self.window.show() | |
def _btn_cb(self, widget, data=None): | |
""" | |
Button callback | |
""" | |
if self.swap: | |
markup = ( | |
'<span font_desc="FontAwesome 30"></span>' | |
' ' | |
'<span font_desc="FontAwesome 30"></span>' | |
) | |
else: | |
markup = ( | |
'<span fgcolor="#7c8dde" font_desc="FontAwesome 30"></span>' | |
' ' | |
'<span fgcolor="#26638c" font_desc="FontAwesome 30"></span>' | |
) | |
self.label.set_markup(markup) | |
self.swap = not self.swap | |
if __name__ == '__main__': | |
gui = MyApp() | |
Gtk.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- Generated with glade 3.16.1 --> | |
<interface> | |
<requires lib="gtk+" version="3.10"/> | |
<object class="GtkWindow" id="window"> | |
<property name="can_focus">False</property> | |
<property name="window_position">center-always</property> | |
<property name="default_width">300</property> | |
<property name="default_height">300</property> | |
<child> | |
<object class="GtkBox" id="box"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="margin_left">5</property> | |
<property name="margin_right">5</property> | |
<property name="margin_top">5</property> | |
<property name="margin_bottom">5</property> | |
<property name="orientation">vertical</property> | |
<child> | |
<object class="GtkButton" id="button"> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="clicked" handler="_btn_cb" swapped="no"/> | |
<child> | |
<object class="GtkLabel" id="button_label"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label" translatable="yes"><span font_desc="FontAwesome 30">&#xf039;</span> <span font_desc="FontAwesome 30">&#xf17b;</span></property> | |
<property name="use_markup">True</property> | |
</object> | |
</child> | |
</object> | |
<packing> | |
<property name="expand">True</property> | |
<property name="fill">True</property> | |
<property name="position">0</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkLabel" id="label"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="label" translatable="yes"><span font_desc="FontAwesome 30">&#xf113;</span> <span font_desc="FontAwesome 30">&#xf0ac;</span></property> | |
<property name="use_markup">True</property> | |
</object> | |
<packing> | |
<property name="expand">True</property> | |
<property name="fill">True</property> | |
<property name="position">1</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</interface> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment