Skip to content

Commit

Permalink
Merge pull request #51 from t00m/0.0.31
Browse files Browse the repository at this point in the history
0.0.31
  • Loading branch information
t00m authored May 31, 2024
2 parents 9d2223b + 6bf01a3 commit bfc17f6
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 116 deletions.
2 changes: 1 addition & 1 deletion MiAZ/backend/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def load(self, path):
self.config['Project'] = MiAZConfigProjects(self.backend, repo_dir_conf)
self.config['Plugin'] = MiAZConfigUserPlugins(self.backend, repo_dir_conf)
self.backend.add_service('Projects', MiAZProject(self.backend))
watcher = MiAZWatcher('source', path)
watcher = MiAZWatcher(path)
watcher.set_active(active=True)
self.backend.add_service('watcher', watcher)
self.log.debug("Config repo loaded from: %s", repo_dir_conf)
Expand Down
12 changes: 5 additions & 7 deletions MiAZ/backend/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ class MiAZWatcher(GObject.GObject):
before = {}
active = False

def __init__(self, name: str, dirpath: str):
def __init__(self, dirpath: str):
super(MiAZWatcher, self).__init__()
self.log = get_logger('MiAZ.Watcher')
self.name = name.lower()
self.dirpath = dirpath
sid = GObject.signal_lookup('repository-updated', MiAZWatcher)
if sid == 0:
Expand Down Expand Up @@ -67,7 +66,7 @@ def __files_with_timestamp(self, rootdir):

def set_path(self, dirpath: str):
self.dirpath = dirpath
self.log.debug("Monitoring '%s'", self.dirpath)
self.log.debug("Watcher monitoring '%s'", self.dirpath)

def set_active(self, active: bool = True) -> None:
self.active = active
Expand Down Expand Up @@ -95,18 +94,17 @@ def watch(self):
modified.append(f)

if added:
self.log.debug("Watcher[%s] > %d files added", self.name, len(added))
self.log.debug("Watcher > %d files added", len(added))
updated |= True
if removed:
self.log.debug("Watcher[%s] > %d files removed", self.name, len(removed))
self.log.debug("Watcher > %d files removed", len(removed))
updated |= True
if modified:
self.log.debug("Watcher[%s] > %d files modified", self.name, len(modified))
self.log.debug("Watcher > %d files modified", len(modified))
updated |= True

if updated:
self.emit('repository-updated')
# ~ self.log.debug("Signal 'repository-updated' emitted", self.name)

self.before = after
return True
7 changes: 2 additions & 5 deletions MiAZ/frontend/desktop/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _on_window_close_request(self, window):

def _update_repo_settings(self, *args):
repo_active = self.conf['App'].get('current')
self.actions.statusbar_message("Switched to repository '%s'" % repo_active)
# ~ self.actions.statusbar_message("Switched to repository '%s'" % repo_active)

def _finish_configuration(self, *args):
self.log.debug("Finish loading app")
Expand Down Expand Up @@ -167,10 +167,6 @@ def check_repository(self, repo_id: str = None):
self._setup_page_rename()
self.actions.show_stack_page_by_name('workspace')
valid = True
statusbar = self.get_widget('statusbar')
name = self.conf['App'].get('current')
statusbar.repo(name)
statusbar.message("Repository loaded")
self.emit('start-application-completed')
else:
valid = False
Expand Down Expand Up @@ -243,6 +239,7 @@ def set_widget(self, name: str, widget):
return widget
else:
self.log.error("A widget with name '%s' doesn't exists", name)
return None

def get_widget(self, name):
try:
Expand Down
8 changes: 4 additions & 4 deletions MiAZ/frontend/desktop/services/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def show_stack_page_by_name(self, name: str = 'workspace'):
def noop(self, *args):
pass

def statusbar_message(self, message: str):
"""Statusbar message"""
statusbar = self.app.get_widget('statusbar')
statusbar.message(message)
def toggle_workspace_filters(self, *args):
btnShowFilters = self.app.get_widget('workspace-togglebutton-filters')
active = btnShowFilters.get_active()
btnShowFilters.set_active(not active)

def exit_app(self, *args):
self.log.debug('Closing MiAZ')
Expand Down
17 changes: 2 additions & 15 deletions MiAZ/frontend/desktop/services/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@
# Description: Custom widgets widely used
"""

import os

import gi
gi.require_version('GdkPixbuf', '2.0')
gi.require_version('Gtk', '4.0')

from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Gio
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Pango
from gi.repository.GdkPixbuf import Pixbuf

from MiAZ.backend.log import get_logger
from MiAZ.backend.models import Country
from MiAZ.frontend.desktop.services.icm import MiAZIconManager
from MiAZ.frontend.desktop.widgets.button import MiAZPopoverButton
from MiAZ.frontend.desktop.widgets.filechooser import MiAZFileChooserDialog

Expand Down Expand Up @@ -74,7 +62,7 @@ def create_actionrow(self, title:str = '', subtitle:str = '', prefix: Gtk.Widget
def create_box_filter(self, title, widget: Gtk.Widget) -> Gtk.Box:
box = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=3)
box.set_margin_bottom(margin=12)
lblTitle = self.create_label('<small>%s</small>' % title)
lblTitle = self.create_label('<b>%s</b>' % title)
lblTitle.set_xalign(0.0)
box.append(lblTitle)
box.append(widget)
Expand Down Expand Up @@ -225,10 +213,9 @@ def _on_factory_bind(factory, list_item):
box = list_item.get_child()
label = box.get_last_child()
item = list_item.get_item()
label.set_markup('<small>%s</small>' % item.title)
label.set_markup('%s' % item.title)

def _on_search_changed(search_entry, item_filter):
text = search_entry.get_text()
item_filter.changed(Gtk.FilterChange.DIFFERENT)

def _do_filter(item, filter_list_model, search_entry):
Expand Down
12 changes: 8 additions & 4 deletions MiAZ/frontend/desktop/widgets/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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


class MiAZMainWindow(Gtk.Box):
Expand Down Expand Up @@ -47,9 +48,9 @@ def _setup_ui(self):
self._setup_headerbar_center()
self._setup_headerbar_right()

# Statusbar
statusbar = self.app.add_widget('statusbar', MiAZStatusbar(self.app))
self.append(statusbar)
# On-Demand SearchBar
search = self.app.add_widget('searchbar', SearchBar(self.app))
self.append(search)

def _setup_event_listener(self):
evk = Gtk.EventControllerKey.new()
Expand Down Expand Up @@ -116,6 +117,9 @@ def show_workspace(self, *args):

def _on_key_press(self, event, keyval, keycode, state):
keyname = Gdk.keyval_name(keyval)
self.log.debug(keyname)
# ~ self.log.debug(keyname)
if keyname == 'Escape':
self.actions.show_stack_page_by_name('workspace')
elif keyname == 'F3':
self.actions.toggle_workspace_filters()

19 changes: 4 additions & 15 deletions MiAZ/frontend/desktop/widgets/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@
"""

import os
import sys
from datetime import datetime
from abc import abstractmethod
from gettext import gettext as _

import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import GLib
from gi.repository.GdkPixbuf import Pixbuf

from MiAZ.backend.log import get_logger
from MiAZ.frontend.desktop.widgets.dialogs import MiAZDialogAdd
from MiAZ.backend.models import Group, Person, Country, Purpose, Concept, SentBy, SentTo
from MiAZ.frontend.desktop.widgets.configview import MiAZCountries, MiAZGroups, MiAZPeople, MiAZPurposes, MiAZPeopleSentBy, MiAZPeopleSentTo
from MiAZ.frontend.desktop.widgets.configview import MiAZCountries, MiAZGroups, MiAZPurposes, MiAZPeopleSentBy, MiAZPeopleSentTo


class MiAZRenameDialog(Gtk.Box):
Expand Down Expand Up @@ -100,7 +93,6 @@ def __init__(self, app) -> Gtk.Widget:
def _update_dropdowns(self, *args):
for item_type in [Country, Group, SentBy, Purpose, SentTo]:
i_type = item_type.__gtype_name__
i_title = _(item_type.__title__)
config = self.config[i_type]
self.actions.dropdown_populate(config, self.dropdown[i_type], item_type, False, False)

Expand Down Expand Up @@ -174,7 +166,6 @@ def __create_field_0_date(self):
"""Field 0. Date"""
title = _('Date')
icon_name = 'miaz-res-date'
icon = self.icons.get_image_by_name(name=icon_name)
boxValue = self.__create_box_value()
boxValue.set_hexpand(False)
boxValue.set_valign(Gtk.Align.CENTER)
Expand Down Expand Up @@ -278,15 +269,13 @@ def __create_field_9_result(self, *args):
"""Field 7. extension"""
# Current filename
title = _('Current filename')
boxValueCur = self.__create_box_value()
self.lblFilenameCur = Gtk.Label()
self.lblFilenameCur.get_style_context().add_class(class_name='monospace')
self.row_cur_filename = self.factory.create_actionrow(title=title, suffix=self.lblFilenameCur)
self.boxMain.append(self.row_cur_filename)

# New filename
title = _('<b>New filename</b>')
boxValueNew = self.__create_box_value()
self.lblFilenameNew = Gtk.Label()
self.lblFilenameNew.get_style_context().add_class(class_name='monospace')
self.row_new_filename = self.factory.create_actionrow(title=title, suffix=self.lblFilenameNew)
Expand Down Expand Up @@ -380,7 +369,7 @@ def validate_date(self, sdate: str) -> bool:
self.calendar.select_day(GLib.DateTime.new_from_iso8601(iso8601))
self.label_date.set_markup(adate.strftime("%A, %B %d %Y"))
return True
except Exception as error:
except Exception:
return False

def get_filepath_source(self) -> str:
Expand Down Expand Up @@ -410,7 +399,7 @@ def on_answer_question_rename(self, dialog, response):
dialog.destroy()

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

def _on_document_display(self, *args):
doc = self.get_filepath_source()
Expand All @@ -436,4 +425,4 @@ def on_answer_question_delete(self, dialog, response):
self.log.error("Something went wrong: %s", error)
self.log.error("Doesn't it exist? Really?")
else:
self.app.show_stack_page_by_name('workspace')
self.actions.show_stack_page_by_name('workspace')
46 changes: 46 additions & 0 deletions MiAZ/frontend/desktop/widgets/searchbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
# File: searchbar.py
# Author: Tomás Vírseda
# License: GPL v3
# Description: Custom SearchBar widget
# Borrowed from: https://github.com/timlau/gtk4-python
"""

from gi.repository import Gtk

class SearchBar(Gtk.SearchBar):
""" Wrapper for Gtk.Searchbar Gtk.SearchEntry"""

def __init__(self, app):
super(SearchBar, self).__init__()
self.app = app
window = self.app.get_widget('window')
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
box.set_spacing(24)

# Add SearchEntry
entry = self.app.add_widget('searchbar_entry', Gtk.SearchEntry())
entry.set_hexpand(True)
box.append(entry)
self.set_child(box)

# connect search entry to seach bar
self.connect_entry(entry)

# set key capture from main window, it will show searchbar, when you start typing
if window:
self.set_key_capture_widget(window)

# show close button in search bar
self.set_show_close_button(True)

# Set search mode to off by default
self.set_search_mode(False)

def set_callback(self, callback):
""" Connect the search entry activate to an callback handler"""
entry = self.app.get_widget('searchbar_entry')
entry.connect('changed', callback)
24 changes: 0 additions & 24 deletions MiAZ/frontend/desktop/widgets/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ def __init__(self, app, edit=True):
boxViews.append(boxRight)
self.append(boxViews)

# Status bar...
statusbar = self.factory.create_box_horizontal(hexpand=True)
self.sbicon = Gtk.Image() #.new_from_icon_name('info')
self.sbicon.set_pixel_size(32)
self.sbtext = Gtk.Label()
statusbar.append(self.sbicon)
statusbar.append(self.sbtext)
# ~ self.append(statusbar)
# ~ self.actions.statusbar_message('', '')

# Available
self.frmViewAv = Gtk.Frame()
title = Gtk.Label()
Expand All @@ -112,16 +102,6 @@ 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 add_columnview_available(self, columnview):
columnview.set_filter(self._do_filter_view)
columnview.column_title.set_expand(True)
Expand All @@ -143,7 +123,6 @@ def _setup_view_finish(self, *args):
def update(self, *args):
self._update_view_available()
self._update_view_used()
# ~ self.statusbar_message('', '')

def _on_item_used_add(self, *args):
changed = False
Expand Down Expand Up @@ -178,12 +157,9 @@ def _on_item_used_remove(self, *args):
changed = True
text = _('Removed %s (%s) from used') % (item_used.id, item_used.title)
self.log.debug(text)
# ~ self.statusbar_message('info', text)
else:
# ~ 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)
window = self.app.get_widget('window')
dtype = 'error'
title = "Item can't be removed"
Expand Down
2 changes: 1 addition & 1 deletion MiAZ/frontend/desktop/widgets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _on_plugin_remove(self, *args):
deleted = plugin_manager.remove_plugin(plugin)
if deleted:
self.log.debug("Plugin '%s' deleted", module.id)
self.actions.statusbar_message("Plugin '%s' deleted" % module.id)
# ~ self.actions.statusbar_message("Plugin '%s' deleted" % module.id)
self.update_user_plugins()

def get_plugin_status(self, name: str) -> bool:
Expand Down
Loading

0 comments on commit bfc17f6

Please sign in to comment.