Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.31 #51

Merged
merged 12 commits into from
May 31, 2024
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
4 changes: 2 additions & 2 deletions MiAZ/frontend/desktop/services/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,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,7 +225,7 @@ 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()
t00m marked this conversation as resolved.
Show resolved Hide resolved
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()

4 changes: 2 additions & 2 deletions MiAZ/frontend/desktop/widgets/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,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 +436,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
51 changes: 27 additions & 24 deletions MiAZ/frontend/desktop/widgets/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def _setup_toolbar_filters(self):
body = self.factory.create_box_horizontal(margin=3, spacing=6, hexpand=True, vexpand=True)
body.set_homogeneous(True)
body.set_margin_top(margin=6)
body.set_margin_start(margin=12)
body.set_margin_end(margin=12)
widget.append(body)
widget.append(Gtk.Separator.new(orientation=Gtk.Orientation.HORIZONTAL))

Expand Down Expand Up @@ -199,8 +201,9 @@ def update_dropdown_filter(self, config, item_type):
self.actions.dropdown_populate(config, dropdowns[i_type], item_type)
# ~ self.log.debug("Dropdown %s updated", i_type)

def _on_filters_toggled(self, button, data=None):
active = button.get_active()
def _on_filters_toggled(self, *args):
btnShowFilters = self.app.get_widget('workspace-togglebutton-filters')
active = btnShowFilters.get_active()
self.toolbar_filters.set_visible(active)

def _on_selection_changed(self, selection, position, n_items):
Expand All @@ -223,24 +226,28 @@ def _on_selection_changed(self, selection, position, n_items):
# ~ menu = self.app.get_widget('workspace-menu-selection')
# ~ self.popDocsSel.set_menu_model(menu)

def _setup_searchbar(self):
# ~ window = self.app.get_widget('window')
# ~ mainbox = self.app.get_widget('window-mainbox')
# ~ search = self.app.add_widget('searchbar', SearchBar(window))
# ~ self.append(mainbox)
# ~ searchbar = self.app.get_widget('searchbar')
# ~ searchbar.set_callback(self._on_filter_selected)
pass

t00m marked this conversation as resolved.
Show resolved Hide resolved
def _setup_toolbar_top(self):
hdb_left = self.app.get_widget('headerbar-left-box')
hdb_right = self.app.get_widget('headerbar-right-box')
hdb_right.get_style_context().add_class(class_name='linked')

## Show/Hide Filters
self.tgbFilters = self.factory.create_button_toggle('miaz-filters2', callback=self._on_filters_toggled)
self.tgbFilters.set_active(False)
self.tgbFilters.set_hexpand(False)
self.tgbFilters.get_style_context().remove_class(class_name='flat')
self.tgbFilters.set_valign(Gtk.Align.CENTER)
hdb_left.append(self.tgbFilters)

## Searchbox
self.ent_sb = Gtk.SearchEntry(placeholder_text=_('Type here'))
self.ent_sb.set_hexpand(False)
self.ent_sb.get_style_context().add_class(class_name='caption')
hdb_left.append(self.ent_sb)
tgbFilters = self.factory.create_button_toggle('miaz-filters2', callback=self._on_filters_toggled)
self.app.add_widget('workspace-togglebutton-filters', tgbFilters)
tgbFilters.set_active(False)
tgbFilters.set_hexpand(False)
tgbFilters.get_style_context().remove_class(class_name='flat')
tgbFilters.set_valign(Gtk.Align.CENTER)
hdb_left.append(tgbFilters)

## Dropdowns
dropdowns = self.app.get_widget('ws-dropdowns')
Expand Down Expand Up @@ -357,6 +364,7 @@ def _setup_workspace(self):
self.app.add_widget('workspace-toolbar-filters', self.toolbar_filters)
# ~ toolbar_top = self.app.add_widget('workspace-toolbar-top', self._setup_toolbar_top())
self._setup_toolbar_top()
self._setup_searchbar()
# ~ headerbar = self.app.get_widget('headerbar')
# ~ headerbar.set_title_widget(toolbar_top)
frmView = self._setup_columnview()
Expand All @@ -381,7 +389,7 @@ def _setup_workspace(self):

# Trigger events
self._do_connect_filter_signals()
self._on_filters_toggled(self.tgbFilters)
self._on_filters_toggled()

return widget

Expand Down Expand Up @@ -573,7 +581,8 @@ def update(self, *args):
self.selected_items = []

def _do_eval_cond_matches_freetext(self, item):
left = self.ent_sb.get_text()
entry = self.app.get_widget('searchbar_entry')
left = entry.get_text()
right = item.id
if left.upper() in right.upper():
return True
Expand Down Expand Up @@ -685,7 +694,8 @@ def _do_filter_view(self, item, filter_list_model):
return show_item

def _do_connect_filter_signals(self):
self.ent_sb.connect('changed', self._on_filter_selected)
searchbar = self.app.get_widget('searchbar')
searchbar.set_callback(self._on_filter_selected)
t00m marked this conversation as resolved.
Show resolved Hide resolved
dropdowns = self.app.get_widget('ws-dropdowns')
for dropdown in dropdowns:
dropdowns[dropdown].connect("notify::selected-item", self._on_filter_selected)
Expand Down Expand Up @@ -721,10 +731,3 @@ def _on_select_none(self, *args):
selection = self.view.get_selection()
selection.unselect_all()

def display_dashboard(self, *args):
self.view.column_subtitle.set_title(_('Concept'))
self.view.column_subtitle.set_expand(True)
self.column_sentto.set_expand(False)
self.column_sentby.set_expand(False)
self.view.refilter()
self.tgbFilters.set_visible(True)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/resources/plugins/renameitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _on_selection_changed(self, *args):
def add_toolbar_button(self, *args):
if self.app.get_widget('toolbar-top-button-rename') is None:
toolbar_top_right = self.app.get_widget('headerbar-right-box')
button = self.factory.create_button(icon_name='miaz-res-manage', callback=self.callback)
button = self.factory.create_button(icon_name='com.github.t00m.MiAZ-text-editor-symbolic', callback=self.callback)
# ~ button.get_style_context().add_class(class_name='flat')
button.set_visible(False)
self.app.add_widget('toolbar-top-button-rename', button)
Expand Down
2 changes: 1 addition & 1 deletion data/resources/plugins/viewitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _on_selection_changed(self, *args):
def add_toolbar_button(self, *args):
if self.app.get_widget('toolbar-top-button-view') is None:
toolbar_top_right = self.app.get_widget('headerbar-right-box')
button = self.factory.create_button(icon_name='miaz-display', callback=self.callback)
button = self.factory.create_button(icon_name='com.github.t00m.MiAZ-view-document', callback=self.callback)
# ~ button.get_style_context().add_class(class_name='flat')
button.set_visible(False)
self.app.add_widget('toolbar-top-button-view', button)
Expand Down
Loading