Skip to content

Commit

Permalink
Merge pull request #49 from t00m/0.0.30
Browse files Browse the repository at this point in the history
0.0.30
  • Loading branch information
t00m authored May 30, 2024
2 parents c5022ba + 70a1bf4 commit 3f5d82b
Show file tree
Hide file tree
Showing 22 changed files with 509 additions and 495 deletions.
418 changes: 54 additions & 364 deletions MiAZ/frontend/desktop/app.py

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions MiAZ/frontend/desktop/services/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewMassRename
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewMassDelete
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewMassProject
from MiAZ.frontend.desktop.widgets.settings import MiAZAppSettings

# Conversion Item type to Field Number
Field = {}
Expand Down Expand Up @@ -216,3 +217,55 @@ def manage_resource(self, widget: Gtk.Widget, selector: Gtk.Widget):
selector.update()
dialog = self.factory.create_dialog(self.app.win, _('Manage %s') % config_for, box, 800, 600)
dialog.show()

def show_app_settings(self, *args):
window = self.app.get_widget('window')
settings = self.app.get_widget('settings-app')
if settings is None:
settings = self.app.add_widget('settings-app', MiAZAppSettings(self.app))
settings.set_transient_for(window)
settings.set_modal(True)
settings.present()

def show_app_about(self, *args):
window = self.app.get_widget('window')
ENV = self.app.get_env()
about = Gtk.AboutDialog()
about.set_transient_for=window
about.set_modal(True)
about.set_logo_icon_name(ENV['APP']['ID'])
about.set_program_name(ENV['APP']['name'])
about.set_version(ENV['APP']['VERSION'])
about.set_authors(ENV['APP']['documenters'])
about.set_license_type(Gtk.License.GPL_3_0_ONLY)
about.set_copyright('© 2024 %s' % ENV['APP']['author'])
about.set_website('https://github.com/t00m/MiAZ')
about.set_website_label('Github MiAZ repository')
about.set_comments(ENV['APP']['description'])
about.present()

def get_stack_page_by_name(self, name: str) -> Gtk.Stack:
stack = self.app.get_widget('stack')
widget = stack.get_child_by_name(name)
return stack.get_page(widget)

def get_stack_page_widget_by_name(self, name:str) -> Gtk.Widget:
stack = self.app.get_widget('stack')
return stack.get_child_by_name(name)

def show_stack_page_by_name(self, name: str = 'workspace'):
stack = self.app.get_widget('stack')
stack.set_visible_child_name(name)

def noop(self, *args):
pass

def statusbar_message(self, message: str):
"""Statusbar message"""
statusbar = self.app.get_widget('statusbar')
statusbar.message(message)

def exit_app(self, *args):
self.log.debug('Closing MiAZ')
self.app.emit("exit-application")
self.app.quit()
17 changes: 8 additions & 9 deletions MiAZ/frontend/desktop/services/icm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@

import os

import pkg_resources

import gi
gi.require_version('GdkPixbuf', '2.0')
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import GObject
from gi.repository import Gdk
from gi.repository.GdkPixbuf import Pixbuf

from MiAZ.backend.log import get_logger
Expand All @@ -44,7 +38,7 @@ def choose_icon(self, icon_list: list) -> str:
found = 'unknown'
for icon_name in icon_list:
if self.theme.has_icon(icon_name):
found = icon_name;
found = icon_name
break
return found

Expand All @@ -71,7 +65,7 @@ def get_image_by_name(self, name: str, width: int = 24, height: int = 24) -> Gtk
def get_mimetype_icon(self, mimetype: str) -> Gtk.Image:
try:
gicon = self.gicondict[mimetype]
except:
except Exception:
gicon = Gio.content_type_get_icon(mimetype)
self.gicondict[mimetype] = gicon
return gicon
Expand All @@ -80,7 +74,7 @@ def get_flag_icon(self, code: str) -> Gtk.Image:
ENV = self.app.get_env()
try:
paintable = self.paintable[code]
except:
except Exception:
iconpath = os.path.join(ENV['GPATH']['FLAGS'], "%s.svg" % code)
if not os.path.exists(iconpath):
iconpath = os.path.join(ENV['GPATH']['FLAGS'], "__.svg")
Expand All @@ -89,3 +83,8 @@ def get_flag_icon(self, code: str) -> Gtk.Image:
paintable = image.get_paintable()
self.paintable[code] = paintable
return paintable

def get_gicon(self, name:str):
gicon = Gio.Icon.new_for_string(name)
self.log.debug(gicon)
return gicon
6 changes: 1 addition & 5 deletions MiAZ/frontend/desktop/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
# Description: Custom popover button
"""

from gettext import gettext as _

import gi
from gi.repository import Gtk


class MiAZPopoverButton(Gtk.Box):
"""Custom Popover Button"""
def __init__(self, app, icon_name: str = '', title: str = '', css_classes: list = [], widgets: list = []):
super(Gtk.Box, self).__init__(spacing=0, orientation=Gtk.Orientation.HORIZONTAL)
super(Gtk.Box, self).__init__(spacing=0, orientation=Gtk.Orientation.VERTICAL)
self.app = app
ENV = app.get_env()
self.icon_name = icon_name
self.title = title
self.css_classes = css_classes
Expand Down
2 changes: 2 additions & 0 deletions MiAZ/frontend/desktop/widgets/configview.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def _setup_view_finish(self):
def on_item_available_add(self, *args):
dialog = MiAZDialogAddRepo(self.app, self.app.win, 'Add a new repository', 'Repository name', 'Folder')
dialog.connect('response', self._on_response_item_available_add)
search_term = self.entry.get_text()
dialog.set_value1(search_term)
dialog.show()

def _on_response_item_available_add(self, dialog, response):
Expand Down
34 changes: 20 additions & 14 deletions MiAZ/frontend/desktop/widgets/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
# Description: Custom dialogs
"""

import os
import json
from gettext import gettext as _

import gi
gi.require_version(namespace='Gtk', version='4.0')
from gi.repository import Gio
from gi.repository import Gtk
from gi.repository import Pango
from gi.repository.GdkPixbuf import Pixbuf

from MiAZ.backend.log import get_logger

Expand All @@ -44,7 +36,7 @@ def __init__(self,
self.app = app
self.set_transient_for(parent)
self.set_title(title=title)
self.use_header_bar = True
self.use_header_bar = use_header_bar

if callback is not None:
self.connect('response', callback)
Expand All @@ -70,6 +62,7 @@ def __init__(self,

action_box = btn_ok.get_ancestor(Gtk.Box)
action_box.get_style_context ().add_class ('toolbar')
action_box.set_homogeneous(True)

# Content area
content_area = self.get_content_area()
Expand All @@ -86,7 +79,7 @@ def __init__(self,
icon.set_pixel_size(48)
label = Gtk.Label.new(dtype.title())
label.get_style_context().add_class(class_name='title-1')
hbox_title.append(icon)
# ~ hbox_title.append(icon)
hbox_title.append(label)
vbox.append(hbox_title)
lblDesc = Gtk.Label()
Expand All @@ -96,15 +89,28 @@ def __init__(self,
content_area.append(child=vbox)

def dialog_response(self, dialog, response):
# ~ if response == Gtk.ResponseType.OK:
# ~ return True
# ~ elif response == Gtk.ResponseType.CANCEL:
# ~ return False
dialog.hide()

def get_entry_text(self):
return self.entry.get_text()

class Question(CustomDialog):
def __init__(self,
app,
parent: Gtk.Window,
title: str = '',
text: str = '',
callback = None
):
super().__init__(app=app, parent=parent, use_header_bar=False, dtype='question', title=title, text=text, callback=callback)

def dialog_response(self, dialog, response):
if response == Gtk.ResponseType.OK:
return True
elif response == Gtk.ResponseType.CANCEL:
return False
dialog.hide()

class MiAZDialogAdd(Gtk.Dialog):
""" MiAZ Doc Browser Widget"""
__gtype_name__ = 'MiAZDialogAdd'
Expand Down
121 changes: 121 additions & 0 deletions MiAZ/frontend/desktop/widgets/mainwindow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
# File: mainwindow.py
# Author: Tomás Vírseda
# License: GPL v3
# Description: Setup widget for the main window
"""

from gi.repository import Gdk, Gio, GLib, Gtk

from MiAZ.backend.log import get_logger
from MiAZ.frontend.desktop.widgets.statusbar import MiAZStatusbar


class MiAZMainWindow(Gtk.Box):
def __init__(self, app, edit=True):
self.app = app
self.backend = self.app.get_service('backend')
self.actions = self.app.get_service('actions')
self.util = self.app.get_service('util')
self.icm = self.app.get_service('icons')
self.factory = self.app.get_service('factory')
self.repository = self.app.get_service('repository')
self.log = get_logger('MiAZ.Selector')
super(MiAZMainWindow, self).__init__(orientation=Gtk.Orientation.VERTICAL, hexpand=True, vexpand=True, spacing=0)
self.win = self.app.get_widget('window')
self._setup_ui()
self._setup_event_listener()

def _setup_ui(self):
# Widgets
## HeaderBar
headerbar = self.app.add_widget('headerbar', Gtk.HeaderBar())
self.win.set_titlebar(headerbar)

## Stack & Stack.Switcher
stack = self._setup_stack()
self.append(stack)

# Setup system menu
self._setup_menu_app()

# Setup headerbar widgets
self._setup_headerbar_left()
self._setup_headerbar_center()
self._setup_headerbar_right()

# Statusbar
statusbar = self.app.add_widget('statusbar', MiAZStatusbar(self.app))
self.append(statusbar)

def _setup_event_listener(self):
evk = Gtk.EventControllerKey.new()
self.app.add_widget('window-event-controller', evk)
evk.connect("key-pressed", self._on_key_press)
self.win.add_controller(evk)

def _setup_headerbar_left(self):
headerbar = self.app.get_widget('headerbar')

# System menu
menubutton = self.app.get_widget('headerbar-button-menu-system')
menubutton.set_has_frame(False)
menubutton.get_style_context().add_class(class_name='flat')
menubutton.set_valign(Gtk.Align.CENTER)
headerbar.pack_start(menubutton)

# Filters and Search box
hbox = self.factory.create_box_horizontal(margin=0, spacing=0)
hbox.get_style_context().add_class(class_name='linked')
self.app.add_widget('headerbar-left-box', hbox)
headerbar.pack_start(hbox)

def _setup_headerbar_right(self):
headerbar = self.app.get_widget('headerbar')
hbox = self.factory.create_box_horizontal(margin=0, spacing=0)
hbox.get_style_context().add_class(class_name='linked')
self.app.add_widget('headerbar-right-box', hbox)
headerbar.pack_end(hbox)

def _setup_headerbar_center(self):
pass

def _setup_stack(self):
self.stack = self.app.add_widget('stack', Gtk.Stack())
self.switcher = self.app.add_widget('switcher', Gtk.StackSwitcher())
self.switcher.set_stack(self.stack)
self.stack.set_vexpand(True)
return self.stack

def _setup_menu_app(self):
menu = self.app.add_widget('window-menu-app', Gio.Menu.new())
section_common_in = self.app.add_widget('app-menu-section-common-in', Gio.Menu.new())
section_common_out = self.app.add_widget('app-menu-section-common-out', Gio.Menu.new())
section_danger = self.app.add_widget('app-menu-section-common-danger', Gio.Menu.new())
menu.append_section(None, section_common_in)
menu.append_section(None, section_common_out)
menu.append_section(None, section_danger)
menuitem = self.app.factory.create_menuitem('app-settings', _('Application settings'), self.actions.show_app_settings, None, [])
section_common_in.append_item(menuitem)
menuitem = self.app.factory.create_menuitem('app-about', _('About'), self.actions.show_app_about, None, [])
section_common_out.append_item(menuitem)
menuitem = self.app.factory.create_menuitem('app-quit', _('Exit application'), self.actions.exit_app, None, [])
section_danger.append_item(menuitem)

menubutton = Gtk.MenuButton(child=self.app.factory.create_button_content(icon_name='miaz-system-menu'))
popover = Gtk.PopoverMenu()
popover.set_menu_model(menu)
menubutton.set_popover(popover=popover)
self.app.add_widget('headerbar-button-menu-system', menubutton)

def show_workspace(self, *args):
self.actions.show_stack_page_by_name('workspace')

def _on_key_press(self, event, keyval, keycode, state):
keyname = Gdk.keyval_name(keyval)
self.log.debug(keyname)
if keyname == 'Escape':
self.actions.show_stack_page_by_name('workspace')
22 changes: 11 additions & 11 deletions MiAZ/frontend/desktop/widgets/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, app, edit=True):
statusbar.append(self.sbicon)
statusbar.append(self.sbtext)
# ~ self.append(statusbar)
self.statusbar_message('', '')
# ~ self.actions.statusbar_message('', '')

# Available
self.frmViewAv = Gtk.Frame()
Expand All @@ -112,15 +112,15 @@ def __init__(self, app, edit=True):
boxRight.append(self.frmViewSl)
self._setup_view_finish()

def statusbar_message(self, dtype: str = 'warning', message: str = ''):
icon_name = {}
icon_name["info"] = "dialog-information-symbolic"
icon_name["warning"] = "dialog-warning-symbolic"
icon_name["error"] = "dialog-error-symbolic"
icon_name["question"] = "dialog-question-symbolic"
icon_name[""] = None
self.sbicon.set_from_icon_name(icon_name[dtype])
self.sbtext.set_markup(message)
# ~ def statusbar_message(self, dtype: str = 'warning', message: str = ''):
# ~ icon_name = {}
# ~ icon_name["info"] = "dialog-information-symbolic"
# ~ icon_name["warning"] = "dialog-warning-symbolic"
# ~ icon_name["error"] = "dialog-error-symbolic"
# ~ icon_name["question"] = "dialog-question-symbolic"
# ~ icon_name[""] = None
# ~ self.sbicon.set_from_icon_name(icon_name[dtype])
# ~ self.sbtext.set_markup(message)

def add_columnview_available(self, columnview):
columnview.set_filter(self._do_filter_view)
Expand Down Expand Up @@ -183,7 +183,7 @@ def _on_item_used_remove(self, *args):
# ~ title = "%s %s not removed" % (self.config.model.__title__, item_used.id)
dtype = "warning"
text = _('%s %s is still being used by some docs') % (self.config.model.__title__, item_used.id)
self.statusbar_message(dtype, text)
# ~ self.statusbar_message(dtype, text)
window = self.app.get_widget('window')
dtype = 'error'
title = "Item can't be removed"
Expand Down
Loading

0 comments on commit 3f5d82b

Please sign in to comment.