Skip to content

Commit

Permalink
Merge pull request #121 from tfuxu/meson-refactor
Browse files Browse the repository at this point in the history
Refactoring meson architecture
  • Loading branch information
0xMRTT committed Aug 13, 2022
2 parents 0985f28 + e67ab2b commit fd010a8
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 53 deletions.
37 changes: 33 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,43 @@ project('adwcustomizer',
],
)

# Import modules
gnome = import('gnome')
i18n = import('i18n')
python = import('python')

# Constants
PROJECT_RDNN_NAME = 'com.github.AdwCustomizerTeam.AdwCustomizer'
APPLICATION_ID = PROJECT_RDNN_NAME

dependency('glib-2.0')
dependency('pygobject-3.0')
dependency('libadwaita-1')
dependency('gtk4', version: '>= 4.5.0')
dependency('libadwaita-1', version: '>= 1.2.alpha')
dependency('pygobject-3.0', version: '>= 3.42.0')

i18n = import('i18n')
# Python installation directory
PY_INSTALLDIR = python.find_installation('python3')

gnome = import('gnome')
# Check if python3 is installed
if not PY_INSTALLDIR.found()
error('No valid python3 binary found')
endif

PKGDATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
MODULE_DIR = join_paths(PKGDATA_DIR, 'adwcustomizer')
PLUGINS_DIR = join_paths(PKGDATA_DIR, 'adwcustomizer', 'plugins')

# Install configuration data
conf = configuration_data()
conf.set('APP_ID', PROJECT_RDNN_NAME)
conf.set('PKGDATA_DIR', PKGDATA_DIR)
conf.set('DATA_DIR', join_paths(get_option('prefix'), get_option('datadir')))
conf.set('LOCALE_DIR', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('PYTHON', PY_INSTALLDIR.full_path())
conf.set('VERSION', meson.project_version())
conf.set('BUILD_TYPE', get_option('buildtype'))

# Subdirs
subdir('data')
subdir('src')
subdir('po')
Expand Down
15 changes: 9 additions & 6 deletions src/adwcustomizer.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ import signal
import locale
import gettext

VERSION = '@VERSION@'
pkgdatadir = '@pkgdatadir@'
localedir = '@localedir@'
pkgdatadir = '@PKGDATA_DIR@'
localedir = '@LOCALE_DIR@'
version = '@VERSION@'

sys.path.insert(1, pkgdatadir)
signal.signal(signal.SIGINT, signal.SIG_DFL)
gettext.install('adwcustomizer', localedir)

locale.bindtextdomain('adwcustomizer', localedir)
locale.textdomain('adwcustomizer')
gettext.install('adwcustomizer', localedir)


if __name__ == '__main__':
import gi
Expand All @@ -43,8 +45,9 @@ if __name__ == '__main__':
gi.require_version('XdpGtk4', '1.0')

from gi.repository import Gio
resource = Gio.Resource.load(os.path.join(pkgdatadir, 'adwcustomizer.gresource'))
resource = Gio.Resource.load(
os.path.join(pkgdatadir, 'adwcustomizer.gresource'))
resource._register()

from adwcustomizer import main
sys.exit(main.main(VERSION))
sys.exit(main.main(version))
6 changes: 3 additions & 3 deletions src/app_type_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

from gi.repository import Gtk, Adw

from .constants import rootdir

@Gtk.Template(
resource_path="/com/github/AdwCustomizerTeam/AdwCustomizer/ui/app_type_dialog.ui"
)

@Gtk.Template(resource_path=f"{rootdir}/ui/app_type_dialog.ui")
class AdwcustomizerAppTypeDialog(Adw.MessageDialog):
__gtype_name__ = "AdwcustomizerAppTypeDialog"

Expand Down
4 changes: 4 additions & 0 deletions src/constants.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rootdir = '/com/github/AdwCustomizerTeam/AdwCustomizer'
app_id = '@APP_ID@'
version = '@VERSION@'
build_type = '@BUILD_TYPE@'
6 changes: 3 additions & 3 deletions src/custom_css_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

from gi.repository import Gtk, Adw

from .constants import rootdir

@Gtk.Template(
resource_path="/com/github/AdwCustomizerTeam/AdwCustomizer/ui/custom_css_group.ui"
)

@Gtk.Template(resource_path=f"{rootdir}/ui/custom_css_group.ui")
class AdwcustomizerCustomCSSGroup(Adw.PreferencesGroup):
__gtype_name__ = "AdwcustomizerCustomCSSGroup"

Expand Down
4 changes: 3 additions & 1 deletion src/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

from gi.repository import Gtk

from .constants import rootdir

@Gtk.Template(resource_path="/com/github/AdwCustomizerTeam/AdwCustomizer/ui/error.ui")

@Gtk.Template(resource_path=f"{rootdir}/ui/error.ui")
class AdwcustomizerError(Gtk.ListBoxRow):
__gtype_name__ = "AdwcustomizerError"

Expand Down
2 changes: 0 additions & 2 deletions src/info.py.in

This file was deleted.

12 changes: 6 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from .app_type_dialog import AdwcustomizerAppTypeDialog
from .custom_css_group import AdwcustomizerCustomCSSGroup
from .plugins_list import AdwcustomizerPluginsList
from . import info
from .constants import rootdir, app_id, version


def to_slug_case(non_slug):
Expand All @@ -47,7 +47,7 @@ class AdwcustomizerApplication(Adw.Application):

def __init__(self, version):
super().__init__(
application_id="com.github.AdwCustomizerTeam.AdwCustomizer",
application_id=app_id,
flags=Gio.ApplicationFlags.FLAGS_NONE,
)
self.version = version
Expand Down Expand Up @@ -100,11 +100,11 @@ def do_activate(self):
self.style_manager = Adw.StyleManager.get_default()
if self.style_manager.get_dark():
self.load_preset_from_resource(
"/com/github/AdwCustomizerTeam/AdwCustomizer/presets/adwaita-dark.json"
f"{rootdir}/presets/adwaita-dark.json"
)
else:
self.load_preset_from_resource(
"/com/github/AdwCustomizerTeam/AdwCustomizer/presets/adwaita.json"
f"{rootdir}/presets/adwaita.json"
)

self.win.present()
Expand Down Expand Up @@ -412,7 +412,7 @@ def load_preset_action(self, _unused, *args):
)
else:
self.load_preset_from_resource(
"/com/github/AdwCustomizerTeam/AdwCustomizer/presets/"
f"{rootdir}/presets/"
+ args[0].get_string()
+ ".json"
)
Expand Down Expand Up @@ -665,7 +665,7 @@ def show_about_window(self, *_args):
Taylan Tatlı https://www.transifex.com/user/profile/TaylanTatli34/""",
copyright="© 2022 Adwaita Manager Team",
license_type=Gtk.License.GPL_3_0,
version=f"{info.version}",
version=f"{version}",
release_notes="""
<ul>
<li>Add AdwViewSwitcher in the header bar.</li>
Expand Down
32 changes: 9 additions & 23 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, 'adwcustomizer')
pluginsdir = join_paths(pkgdatadir, 'adwcustomizer', 'plugins')
gnome = import('gnome')

blueprints = custom_target('blueprints',
Expand All @@ -20,18 +17,10 @@ gnome.compile_resources('adwcustomizer',
'adwcustomizer.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
install_dir: PKGDATA_DIR,
dependencies: blueprints,
)

python = import('python')

conf = configuration_data()
conf.set('PYTHON', python.find_installation('python3').full_path())
conf.set('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)

configure_file(
input: 'adwcustomizer.in',
output: 'adwcustomizer',
Expand All @@ -41,16 +30,14 @@ configure_file(
)

configure_file(
input: 'info.py.in',
output: '@BASENAME@',
install: true,
install_dir: moduledir,
configuration: configuration_data({
'version': meson.project_version(),
'build_type': get_option('buildtype'),
}),
input: 'constants.py.in',
output: 'constants.py',
configuration: conf,
install: true,
install_dir: MODULE_DIR
)

# Install sources
adwcustomizer_sources = [
'__init__.py',
'settings_schema.py',
Expand All @@ -65,11 +52,10 @@ adwcustomizer_sources = [
'app_type_dialog.py',
'custom_css_group.py',
]
install_data(adwcustomizer_sources, install_dir: MODULE_DIR)

plugins_sources = [
'plugins/__init__.py',
'plugins/gtk4.py'
]

install_data(adwcustomizer_sources, install_dir: moduledir)
install_data(plugins_sources, install_dir: pluginsdir)
install_data(plugins_sources, install_dir: PLUGINS_DIR)
4 changes: 3 additions & 1 deletion src/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

from gi.repository import Gtk, Gdk, Adw

from .constants import rootdir

@Gtk.Template(resource_path="/com/github/AdwCustomizerTeam/AdwCustomizer/ui/option.ui")

@Gtk.Template(resource_path=f"{rootdir}/ui/option.ui")
class AdwcustomizerOption(Adw.ActionRow):
__gtype_name__ = "AdwcustomizerOption"

Expand Down
6 changes: 3 additions & 3 deletions src/palette_shades.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

from gi.repository import Gtk, Gdk, Adw

from .constants import rootdir

@Gtk.Template(
resource_path="/com/github/AdwCustomizerTeam/AdwCustomizer/ui/palette_shades.ui"
)

@Gtk.Template(resource_path=f"{rootdir}/ui/palette_shades.ui")
class AdwcustomizerPaletteShades(Adw.ActionRow):
__gtype_name__ = "AdwcustomizerPaletteShades"

Expand Down
7 changes: 6 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
from .app_type_dialog import AdwcustomizerAppTypeDialog
from .custom_css_group import AdwcustomizerCustomCSSGroup
from material_color_utilities_python import *
from .constants import rootdir, build_type


@Gtk.Template(resource_path="/com/github/AdwCustomizerTeam/AdwCustomizer/ui/window.ui")
@Gtk.Template(resource_path=f"{rootdir}/ui/window.ui")
class AdwcustomizerMainWindow(Adw.ApplicationWindow):
__gtype_name__ = "AdwcustomizerMainWindow"

Expand All @@ -57,6 +58,10 @@ def __init__(self, **kwargs):
"show", self.on_presets_dropdown_activate
)

# Set devel style
if build_type == "debug":
self.get_style_context().add_class("devel")

self.setup_monet_page()
self.setup_plugins_page()
self.setup_colors_page()
Expand Down

0 comments on commit fd010a8

Please sign in to comment.