OSG_Mugshot_fork/mugshot_lib/Window.py

101 lines
3.9 KiB
Python
Raw Normal View History

2014-01-25 23:13:56 +00:00
#!/usr/bin/python3
2013-07-12 17:56:24 +00:00
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2014-01-25 23:13:56 +00:00
# Mugshot - Lightweight user configuration utility
2020-12-29 03:55:14 +00:00
# Copyright (C) 2013-2020 Sean Davis <sean@bluesabre.org>
2014-01-25 22:21:53 +00:00
#
2014-01-25 23:13:56 +00:00
# This program is free software: you can redistribute it and/or modify it
2014-07-28 00:07:47 +00:00
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
2014-07-28 00:07:47 +00:00
# (at your option) any later version.
2014-01-25 22:21:53 +00:00
#
2014-01-25 23:13:56 +00:00
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
2013-07-12 17:56:24 +00:00
2016-10-18 10:34:57 +00:00
import os
2013-07-12 17:56:24 +00:00
import logging
2016-10-18 10:34:57 +00:00
from gi.repository import Gio, Gtk # pylint: disable=E0611
2014-01-25 23:31:53 +00:00
from . helpers import get_builder, show_uri
2013-07-12 17:56:24 +00:00
2016-10-18 10:34:57 +00:00
logger = logging.getLogger('mugshot_lib')
2014-01-25 22:21:53 +00:00
2013-07-12 17:56:24 +00:00
class Window(Gtk.Window):
2015-09-01 02:31:02 +00:00
2014-01-25 22:21:53 +00:00
"""This class is meant to be subclassed by MugshotWindow. It provides
common functions and some boilerplate."""
2013-07-12 17:56:24 +00:00
__gtype_name__ = "Window"
2014-01-25 22:21:53 +00:00
# To construct a new instance of this method, the following notable
2013-07-12 17:56:24 +00:00
# methods are called in this order:
# __new__(cls)
# __init__(self)
# finish_initializing(self, builder)
# __init__(self)
#
# For this reason, it's recommended you leave __init__ empty and put
# your initialization code in finish_initializing
2014-01-25 22:21:53 +00:00
2013-07-12 17:56:24 +00:00
def __new__(cls):
2014-01-25 22:21:53 +00:00
"""Special static method that's automatically called by Python when
2013-07-12 17:56:24 +00:00
constructing a new instance of this class.
2014-01-25 22:21:53 +00:00
2013-07-12 17:56:24 +00:00
Returns a fully instantiated BaseMugshotWindow object.
"""
builder = get_builder('MugshotWindow')
new_object = builder.get_object("mugshot_window")
new_object.finish_initializing(builder)
return new_object
def finish_initializing(self, builder):
"""Called while initializing this instance in __new__
finish_initializing should be called after parsing the UI definition
and creating a MugshotWindow object with it in order to finish
initializing the start of the new MugshotWindow instance.
"""
# Get a reference to the builder and set up the signals.
self.builder = builder
self.ui = builder.get_ui(self, True)
2014-01-25 22:21:53 +00:00
self.CameraDialog = None # class
self.camera_dialog = None # instance
2013-07-12 17:56:24 +00:00
self.settings = Gio.Settings.new("org.bluesabre.mugshot")
2013-07-12 17:56:24 +00:00
self.settings.connect('changed', self.on_preferences_changed)
2018-08-06 09:47:21 +00:00
self.tmpfile = None
def on_help_activate(self, widget, data=None):
2014-01-25 22:21:53 +00:00
"""Show the Help documentation when Help is clicked."""
2019-06-02 09:17:04 +00:00
show_uri(self, "https://github.com/bluesabre/mugshot/wiki")
2014-01-25 22:21:53 +00:00
def on_menu_camera_activate(self, widget, data=None):
"""Display the camera window for mugshot."""
if self.camera_dialog is not None:
logger.debug('show existing camera_dialog')
self.camera_dialog.show()
elif self.CameraDialog is not None:
logger.debug('create new camera_dialog')
2014-01-25 22:21:53 +00:00
self.camera_dialog = self.CameraDialog() # pylint: disable=E1102
2018-08-07 10:14:29 +00:00
self.camera_dialog.connect(
'apply', self.on_camera_dialog_apply) # pylint: disable=E1101
self.camera_dialog.show()
2013-07-12 17:56:24 +00:00
def on_destroy(self, widget, data=None):
"""Called when the MugshotWindow is closed."""
# Clean up code for saving application state should be added here.
if self.tmpfile and os.path.isfile(self.tmpfile.name):
os.remove(self.tmpfile.name)
2013-07-12 17:56:24 +00:00
Gtk.main_quit()
def on_preferences_changed(self, settings, key, data=None):
2014-01-25 22:21:53 +00:00
"""Log preference updates."""
logger.debug('preference changed: %s = %s' %
2014-04-02 01:52:45 +00:00
(key, str(settings.get_value(key))))