Add logo to status bar.

This commit is contained in:
luxick
2018-03-07 18:38:29 +01:00
parent e5d0d92de2
commit ce7bb3a244
8 changed files with 53 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
import os
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gtk, GdkPixbuf
from dsst_gtk3.handlers import handlers
from dsst_gtk3 import util, reload, client
@@ -17,6 +17,10 @@ class GtkUi:
]
for path in glade_resources:
self.ui.add_from_string(util.load_ui_resource_string(path))
# Set the status bar logo
dd_logo = ['dsst_gtk3', 'resources', 'images', 'dd.png']
logo_pixbuf = util.load_image_resource(dd_logo, 60, 13)
logo = self.ui.get_object('status_bar_logo').set_from_pixbuf(logo_pixbuf)
# Connect signal handlers to UI
self.handlers = handlers.Handlers(self)
self.ui.connect_signals(self.handlers)

View File

@@ -2505,7 +2505,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<child>
@@ -2519,7 +2519,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">2</property>
</packing>
</child>
<child>
@@ -2531,7 +2531,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">3</property>
</packing>
</child>
<child>
@@ -2542,6 +2542,18 @@
<attribute name="weight" value="semibold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkImage" id="status_bar_logo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -4,7 +4,7 @@ This modules contains general utilities for the GTK application to use.
import json
import os
from contextlib import contextmanager
from gi.repository import Gtk
from gi.repository import Gtk, GdkPixbuf
from typing import Callable
from dsst_gtk3 import gtk_ui
from zipfile import ZipFile
@@ -75,7 +75,7 @@ def get_index_of_combo_model(widget, column: int, value: int):
def load_ui_resource_from_file(resource_path: list) -> str:
project_base_dir = os.path.dirname(os.path.dirname(__file__))
full_path = os.path.join(project_base_dir, *resource_path)
with open(full_path, 'r') as file:
with open(full_path, 'r', encoding='utf8') as file:
return file.read()
@@ -93,10 +93,35 @@ def load_ui_resource_string(resource_path: list) -> str:
if os.path.isdir(os.path.dirname(__file__)):
return load_ui_resource_from_file(resource_path)
else:
return load_ui_resource_from_archive(resource_path)
def load_image_resource_file(resource_path: list, width: int, height: int) -> GdkPixbuf:
project_base_dir = os.path.dirname(os.path.dirname(__file__))
full_path = os.path.join(project_base_dir, *resource_path)
return GdkPixbuf.Pixbuf.new_from_file_at_scale(full_path, width=width, height=height, preserve_aspect_ratio=False)
def load_image_resource_archive(resource_path: list, width: int, height: int) -> GdkPixbuf:
resource_path = os.path.join(*resource_path)
zip_path = os.path.dirname(os.path.dirname(__file__))
with ZipFile(zip_path, 'r') as archive:
with archive.open(resource_path) as data:
loader = GdkPixbuf.PixbufLoader()
loader.write(data.read())
pixbuf = loader.get_pixbuf() # type: GdkPixbuf.Pixbuf
pixbuf = pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.BILINEAR)
loader.close()
return pixbuf
def load_image_resource(resource_path: list, width: int, height: int) -> GdkPixbuf:
if os.path.isdir(os.path.dirname(__file__)):
return load_image_resource_file(resource_path, width, height)
else:
return load_image_resource_archive(resource_path, width, height)
def load_config(config_path: str) -> dict:
with open(config_path) as config_file:
return json.load(config_file)