Skip to content

Commit

Permalink
refactor: clean code as suggested by coderabbit.ai
Browse files Browse the repository at this point in the history
  • Loading branch information
t00m committed May 30, 2024
1 parent 13c9fd6 commit c772413
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 52 deletions.
12 changes: 3 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 Down
4 changes: 0 additions & 4 deletions MiAZ/frontend/desktop/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
# Description: Custom popover button
"""

from gettext import gettext as _

import gi
from gi.repository import Gtk


Expand All @@ -19,7 +16,6 @@ class MiAZPopoverButton(Gtk.Box):
def __init__(self, app, icon_name: str = '', title: str = '', css_classes: list = [], widgets: list = []):
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
8 changes: 0 additions & 8 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 Down
15 changes: 4 additions & 11 deletions MiAZ/frontend/desktop/widgets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import os
from gettext import gettext as _

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

from MiAZ.backend.log import get_logger
Expand All @@ -27,15 +23,10 @@
from MiAZ.frontend.desktop.widgets.configview import MiAZRepositories
from MiAZ.frontend.desktop.widgets.configview import MiAZUserPlugins
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewPlugin
from MiAZ.frontend.desktop.widgets.dialogs import CustomDialog
from MiAZ.frontend.desktop.widgets.window import MiAZCustomWindow
from MiAZ.backend.models import MiAZItem, File, Group, Person, Country
from MiAZ.backend.models import Purpose, Concept, SentBy, SentTo, Date
from MiAZ.backend.models import Extension, Project, Repository, Plugin
from MiAZ.backend.config import MiAZConfigRepositories
from MiAZ.backend.pluginsystem import MiAZPluginType


Configview = {}
Configview['Country'] = MiAZCountries
Configview['Group'] = MiAZGroups
Expand All @@ -46,11 +37,13 @@
Configview['Plugin'] = MiAZUserPlugins
# ~ Configview['Date'] = Gtk.Calendar


class MiAZAppSettings(MiAZCustomWindow):
__gtype_name__ = 'MiAZAppSettings'

def __init__(self, app, **kwargs):
self.app = app
self.log = get_logger('MiAZ.AppSettings')
self.name = 'app-settings'
self.title = 'Application settings'
super().__init__(app, self.name, self.title, **kwargs)
Expand Down Expand Up @@ -109,7 +102,6 @@ def _create_widget_for_repositories(self):

def _on_use_repo(self, *args):
repo_id = self.dd_repo.get_selected_item().id
repo_dir = self.dd_repo.get_selected_item().title
self.config['App'].set('current', repo_id)
valid = self.app.check_repository()
if valid:
Expand Down Expand Up @@ -299,13 +291,14 @@ class MiAZRepoSettings(MiAZCustomWindow):
__gtype_name__ = 'MiAZRepoSettings'

def __init__(self, app, **kwargs):
self.app = app
self.log = get_logger('MiAZ.RepoSettings')
self.name = 'repo-settings'
self.title = 'Repository settings'
super().__init__(app, self.name, self.title, **kwargs)

def _build_ui(self):
self.set_default_size(1024, 728)
headerbar = self.app.get_widget('window-%s-headerbar' % self.name)
self.notebook = Gtk.Notebook()
self.notebook.set_show_border(False)
self.notebook.set_tab_pos(Gtk.PositionType.TOP)
Expand Down
1 change: 0 additions & 1 deletion MiAZ/frontend/desktop/widgets/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from gettext import gettext as _

import gi
from gi.repository import Gtk


Expand Down
8 changes: 2 additions & 6 deletions MiAZ/frontend/desktop/widgets/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@

import os
from datetime import datetime
from datetime import timedelta
from gettext import gettext as _

import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gdk
from gi.repository import Gio
from gi.repository import Gtk
from gi.repository import GLib
Expand Down Expand Up @@ -129,8 +125,8 @@ def _on_filename_renamed(self, util, source, target):
lprojects = projects.assigned_to(source)
self.log.debug("%s found in these projects: %s", source, ', '.join(lprojects))
for project in lprojects:
srvprj.remove(project, source)
srvprj.add(project, target)
projects.remove(project, source)
projects.add(project, target)
self.log.debug("P[%s]: %s -> %s", project, source, target)

def _on_filename_deleted(self, util, target):
Expand Down
1 change: 0 additions & 1 deletion data/resources/plugins/menurepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Description: Plugin for exporting items to CSV
"""

import tempfile
from gettext import gettext as _

from gi.repository import GObject
Expand Down
12 changes: 0 additions & 12 deletions data/resources/plugins/renameitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@
# Description: Plugin for rename documents
"""

from datetime import datetime
from gettext import gettext as _

from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Peas

from MiAZ.backend.log import get_logger
from MiAZ.backend.models import MiAZItem, File, Group, Person, Country, Purpose, Concept, SentBy, SentTo, Date, Extension, Project, Repository
from MiAZ.frontend.desktop.widgets.configview import MiAZCountries, MiAZGroups, MiAZPeople, MiAZPurposes, MiAZPeopleSentBy, MiAZPeopleSentTo, MiAZProjects
from MiAZ.frontend.desktop.widgets.rename import MiAZRenameDialog
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewWorkspace
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewMassRename
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewMassDelete
from MiAZ.frontend.desktop.widgets.views import MiAZColumnViewMassProject


class MiAZToolbarRenameItemPlugin(GObject.GObject, Peas.Activatable):
Expand Down

0 comments on commit c772413

Please sign in to comment.