mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
save window size, few fixes
This commit is contained in:
parent
35bce5521f
commit
c8825887aa
6 changed files with 57 additions and 13 deletions
|
@ -38,7 +38,6 @@ class Application(Gtk.Application):
|
|||
win = None
|
||||
alive = True
|
||||
locked = False
|
||||
|
||||
settings_action = None
|
||||
|
||||
def __init__(self):
|
||||
|
@ -101,7 +100,7 @@ class Application(Gtk.Application):
|
|||
help_section = Gio.MenuItem.new_section(None, help_content)
|
||||
self.menu.append_item(help_section)
|
||||
|
||||
self.dark_mode_action = Gio.SimpleAction.new_stateful("night_mode", GLib.VariantType.new("b"), GLib.Variant.new_boolean(False))
|
||||
self.dark_mode_action = Gio.SimpleAction.new("night_mode", None)
|
||||
self.dark_mode_action.connect("activate", self.enable_dark_mode)
|
||||
self.add_action(self.dark_mode_action)
|
||||
|
||||
|
@ -123,7 +122,7 @@ class Application(Gtk.Application):
|
|||
action.connect("activate", self.on_quit)
|
||||
self.add_action(action)
|
||||
self.refresh_menu_night_mode()
|
||||
if is_gnome():
|
||||
if not show_app_menu():
|
||||
self.set_app_menu(self.menu)
|
||||
logging.debug("Adding gnome shell menu")
|
||||
|
||||
|
@ -136,7 +135,11 @@ class Application(Gtk.Application):
|
|||
is_dark_mode = self.cfg.read("night-mode", "preferences")
|
||||
settings = Gtk.Settings.get_default()
|
||||
settings.set_property("gtk-application-prefer-dark-theme", is_dark_mode)
|
||||
self.dark_mode_action.set_state(GLib.Variant.new_boolean(is_dark_mode))
|
||||
if is_dark_mode:
|
||||
self.is_dark_mode_menu.set_icon(Gio.ThemedIcon.new("emblem-ok-symbolic"))
|
||||
else:
|
||||
self.is_dark_mode_menu.set_icon(Gio.ThemedIcon.new(""))
|
||||
#self.dark_mode_action.set_state(GLib.Variant.new_boolean(is_dark_mode))
|
||||
|
||||
def do_activate(self, *args):
|
||||
if not self.win:
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
along with Gnome-TwoFactorAuth. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from os import path, mknod, makedirs, environ as env
|
||||
from gi.repository import GdkPixbuf, Gtk
|
||||
from gi.repository import GdkPixbuf, Gtk, Gio
|
||||
import logging
|
||||
from subprocess import PIPE, Popen, call
|
||||
from time import strftime
|
||||
|
@ -32,6 +32,22 @@ def is_gnome():
|
|||
return env.get("XDG_CURRENT_DESKTOP").lower() == "gnome"
|
||||
|
||||
|
||||
def show_app_menu():
|
||||
try:
|
||||
source = Gio.SettingsSchemaSource.get_default()
|
||||
path = "org.gnome.desktop.wm.preferences"
|
||||
key = "button-layout"
|
||||
source.lookup(path, True)
|
||||
gsettings = Gio.Settings.new(path)
|
||||
value = gsettings.get_value(key)
|
||||
value = str(value).strip("'")
|
||||
# "appmenu" in value or
|
||||
return not is_gnome()
|
||||
except Exception as e:
|
||||
logging.critical("Couldn't load gsettings source %s " % str(e))
|
||||
|
||||
|
||||
|
||||
def get_home_path():
|
||||
"""
|
||||
Get the home path, used to create db file
|
||||
|
|
|
@ -80,6 +80,8 @@ class AccountsWindow(Gtk.Box, Observer):
|
|||
if removed_id:
|
||||
self.accounts_list.remove_by_id(removed_id)
|
||||
self.accounts_grid.remove_by_id(removed_id)
|
||||
if self.app.db.count() == 0:
|
||||
self.window.refresh_window()
|
||||
|
||||
def get_accounts_list(self):
|
||||
return self.accounts_list
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
from gi import require_version
|
||||
require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, Gio
|
||||
from TwoFactorAuth.utils import is_gnome
|
||||
from TwoFactorAuth.utils import show_app_menu
|
||||
import logging
|
||||
from gettext import gettext as _
|
||||
|
||||
|
@ -50,7 +50,7 @@ class HeaderBar(Gtk.HeaderBar):
|
|||
right_box = self.generate_right_box()
|
||||
left_box = self.generate_left_box()
|
||||
|
||||
if not is_gnome():
|
||||
if show_app_menu():
|
||||
# add settings menu
|
||||
self.generate_popover(right_box)
|
||||
|
||||
|
@ -185,7 +185,7 @@ class HeaderBar(Gtk.HeaderBar):
|
|||
self.select_button.set_no_show_all(not visible)
|
||||
|
||||
def toggle_settings_button(self, visible):
|
||||
if not is_gnome():
|
||||
if show_app_menu():
|
||||
self.settings_button.set_visible(visible)
|
||||
self.settings_button.set_no_show_all(not visible)
|
||||
|
||||
|
|
|
@ -55,8 +55,7 @@ class Window(Gtk.ApplicationWindow):
|
|||
self.move_latest_position()
|
||||
self.set_wmclass("Gnome-TwoFactorAuth", "Gnome TwoFactorAuth")
|
||||
self.set_icon_name("Gnome-TwoFactorAuth")
|
||||
self.resize(500, 650)
|
||||
self.set_size_request(500, 650)
|
||||
self.use_latest_size()
|
||||
self.set_resizable(True)
|
||||
self.connect("key_press_event", self.on_key_press)
|
||||
self.connect("delete-event", lambda x, y: self.app.on_quit())
|
||||
|
@ -180,9 +179,12 @@ class Window(Gtk.ApplicationWindow):
|
|||
"""
|
||||
Save window position
|
||||
"""
|
||||
x, y = self.get_position()
|
||||
self.app.cfg.update("position-x", x, "preferences")
|
||||
self.app.cfg.update("position-y", y, "preferences")
|
||||
pos_x, pos_y = self.get_position()
|
||||
size_x, size_y = self.get_size()
|
||||
self.app.cfg.update("position-x", pos_x, "preferences")
|
||||
self.app.cfg.update("position-y", pos_y, "preferences")
|
||||
self.app.cfg.update("size-x", size_x, "preferences")
|
||||
self.app.cfg.update("size-y", size_y, "preferences")
|
||||
|
||||
def move_latest_position(self):
|
||||
"""
|
||||
|
@ -194,3 +196,9 @@ class Window(Gtk.ApplicationWindow):
|
|||
self.move(x, y)
|
||||
else:
|
||||
self.set_position(Gtk.WindowPosition.CENTER)
|
||||
|
||||
def use_latest_size(self):
|
||||
x = self.app.cfg.read("size-x", "preferences")
|
||||
y = self.app.cfg.read("size-y", "preferences")
|
||||
self.resize(x, y)
|
||||
self.props.width_request = 500
|
||||
|
|
|
@ -36,6 +36,21 @@
|
|||
Default window postiton on y axes
|
||||
</description>
|
||||
</key>
|
||||
|
||||
<key name="size-x" type="i">
|
||||
<default>500</default>
|
||||
<summary>Default window postiton on x axes</summary>
|
||||
<description>
|
||||
Default window postiton on x axes
|
||||
</description>
|
||||
</key>
|
||||
<key name="size-y" type="i">
|
||||
<default>650</default>
|
||||
<summary>Default window postiton on y axes</summary>
|
||||
<description>
|
||||
Default window postiton on y axes
|
||||
</description>
|
||||
</key>
|
||||
<key name="view-mode" type="s">
|
||||
<default>"list"</default>
|
||||
<summary>Default view mode grid/list</summary>
|
||||
|
|
Loading…
Add table
Reference in a new issue