Skip to content

Commit

Permalink
Merge pull request #3 from zevlee/gtk4
Browse files Browse the repository at this point in the history
Update to GTK4
  • Loading branch information
zevlee authored Jun 1, 2022
2 parents e0c2011 + d257547 commit f350130
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.4.0
20 changes: 16 additions & 4 deletions lib/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from lib.utils import Utils
from os.path import join
from platform import system
from gi import require_versions
require_versions({"Gtk": "3.0"})
require_versions({"Gtk": "4.0", "Adw": "1"})
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf


class About(Gtk.AboutDialog):
Expand All @@ -22,9 +22,21 @@ def __init__(self, parent):
website_label="Homepage"
)

# Set up header
header = Gtk.HeaderBar()

# Set decoration layout
if system() == "Darwin":
header.set_decoration_layout("close,minimize,maximize:")
else:
header.set_decoration_layout(":minimize,maximize,close")

# Add header
self.set_titlebar(header)

# Set up logo
filename = join(Utils.APP_DIR, f"{Utils.ID}.svg")
logo = Pixbuf.new_from_file(filename)
logo = Gtk.Image.new_from_file(filename)

# Add logo
self.set_logo(logo)
self.set_logo(logo.get_paintable())
15 changes: 10 additions & 5 deletions lib/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from platform import system
from json import dumps
from gi import require_versions
require_versions({"Gtk": "3.0"})
from gi.repository import Gtk, Gio, GLib
require_versions({"Gtk": "4.0", "Adw": "1"})
from gi.repository import Gtk, Gdk, Gio, GLib, Adw


class Application(Gtk.Application):
class Application(Adw.Application):

def __init__(self):
super().__init__(
Expand All @@ -26,6 +26,9 @@ def __init__(self):
# Set program name
GLib.set_prgname(Utils.ID)

# Set color scheme
self.get_style_manager().set_color_scheme(Adw.ColorScheme.PREFER_DARK)

def do_startup(self):
Gtk.Application.do_startup(self)

Expand All @@ -49,8 +52,10 @@ def do_startup(self):

# Set up icons for linux
if system() == "Linux":
icon_theme = Gtk.IconTheme.get_default()
icon_theme.append_search_path(
icon_theme = Gtk.IconTheme.get_for_display(
Gdk.Display.get_default()
)
icon_theme.add_search_path(
join(Utils.APP_DIR, "usr", "share", "icons")
)

Expand Down
12 changes: 5 additions & 7 deletions lib/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from platform import system
from json import dumps
from gi import require_versions
require_versions({"Gtk": "3.0"})
require_versions({"Gtk": "4.0", "Adw": "1"})
from gi.repository import Gtk


Expand All @@ -16,11 +16,12 @@ def __init__(self, parent):
super().__init__(
modal=True,
transient_for=parent,
resizable=False
resizable=False,
title="Preferences"
)

# Set up header
header = Gtk.HeaderBar(title="Preferences", show_close_button=True)
header = Gtk.HeaderBar()

# Set decoration layout
if system() == "Darwin":
Expand Down Expand Up @@ -169,10 +170,7 @@ def __init__(self, parent):
grid.attach(widgets[i][j], j * width, i, width, 1)

# Add grid
self.add(grid)

# Show all added widgets
self.show_all()
self.set_child(grid)

# Flattened list of symbol check buttons
self.symbols = [symbol for row in symbols for symbol in row]
Expand Down
21 changes: 8 additions & 13 deletions lib/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from platform import system
from json import dumps
from gi import require_versions
require_versions({"Gtk": "3.0"})
require_versions({"Gtk": "4.0", "Adw": "1"})
from gi.repository import Gtk, Gio


Expand All @@ -25,20 +25,15 @@ def __init__(self, app):
self.set_icon_name(Utils.ID)

# Set up header
header = Gtk.HeaderBar(title=Utils.NAME, show_close_button=True)
header = Gtk.HeaderBar()

# Build menu
builder = Gtk.Builder.new_from_file(
join(Utils.APP_DIR, "gui", "menu.xml")
)
menu = builder.get_object("app-menu")
menu_button = Gtk.MenuButton()
menu_button.set_image(
Gtk.Image.new_from_icon_name(
"open-menu-symbolic",
Gtk.IconSize.SMALL_TOOLBAR
)
)
menu_button.set_icon_name("open-menu-symbolic")
menu_button.set_menu_model(menu)

# Add menu actions
Expand Down Expand Up @@ -157,10 +152,7 @@ def __init__(self, app):
grid.attach(widgets[i][j], j * width, i, width, 1)

# Add grid
self.add(grid)

# Show all added widgets
self.show_all()
self.set_child(grid)

def on_prefs_clicked(self, action, param):
"""
Expand Down Expand Up @@ -212,7 +204,9 @@ def on_file_clicked(self, widget):
"_Cancel", Gtk.ResponseType.CANCEL,
"_Open", Gtk.ResponseType.OK,
)
dialog.set_current_folder(join(Utils.CONFIG_DIR, "wordlists"))
dialog.set_current_folder(
Gio.File.new_for_path(join(Utils.CONFIG_DIR, "wordlists"))
)
dialog.connect("response", self._select_file)
dialog.show()

Expand Down Expand Up @@ -267,6 +261,7 @@ def on_generate_clicked(self, button):
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK
)
dialog.set_titlebar(Gtk.HeaderBar(show_title_buttons=False))
dialog.connect("response", self._confirm)
try:
self._generate_password()
Expand Down
4 changes: 3 additions & 1 deletion linux/passphraser.spec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ a = Analysis(
],
hooksconfig={
'gi': {
'icons': ['Adwaita'],
'themes': ['Adwaita'],
'module-versions': {
'Gtk': '3.0'
'Gtk': '4.0'
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion macos/passphraser.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ a = Analysis(
],
hooksconfig={
'gi': {
'icons': ['Adwaita'],
'themes': ['Adwaita'],
'module-versions': {
'Gtk': '3.0'
'Gtk': '4.0'
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion passphraser
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sys import argv
from gi import require_versions
require_versions({"Gdk": "3.0"})
require_versions({"Gdk": "4.0"})
from gi.repository import Gdk
Gdk.set_allowed_backends("x11,*")
from lib.application import Application
Expand Down
4 changes: 3 additions & 1 deletion windows/passphraser.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ a = Analysis(
],
hooksconfig={
'gi': {
'icons': ['Adwaita'],
'themes': ['Adwaita'],
'module-versions': {
'Gtk': '3.0'
'Gtk': '4.0'
}
}
},
Expand Down

0 comments on commit f350130

Please sign in to comment.