Evangelos Ribeiro Tzaras: 1 Whitespace cleanups 7 files changed, 112 insertions(+), 113 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~fabrixxm/confy-dev/patches/23274/mbox | git am -3Learn more about email & git
--- src/main.py | 4 +- src/migrations/001_event_person_unique.py | 2 +- src/migrations/002_full_text_search.py | 2 +- src/models.py | 57 +++++++------- src/pages.py | 96 +++++++++++------------ src/widgets.py | 18 ++--- src/window.py | 46 +++++------ 7 files changed, 112 insertions(+), 113 deletions(-) diff --git a/src/main.py b/src/main.py index 3f5899d..0c4e0c7 100644 --- a/src/main.py +++ b/src/main.py @@ -89,7 +89,7 @@ class Application(Gtk.Application): if not win: win = ConfyWindow(application=self) win.present() - + def on_shutdown(self, *_): local.close() @@ -99,7 +99,7 @@ class Application(Gtk.Application): w.set_transient_for(self.props.active_window) w.props.view_name = None w.show() - + def main(version): diff --git a/src/migrations/001_event_person_unique.py b/src/migrations/001_event_person_unique.py index 3e64e43..31df702 100644 --- a/src/migrations/001_event_person_unique.py +++ b/src/migrations/001_event_person_unique.py @@ -9,4 +9,4 @@ def up(cursor): def down(cursor): ... - + diff --git a/src/migrations/002_full_text_search.py b/src/migrations/002_full_text_search.py index ee9fee4..e73e5df 100644 --- a/src/migrations/002_full_text_search.py +++ b/src/migrations/002_full_text_search.py @@ -4,4 +4,4 @@ def up(cursor): def down(cursor): ... - + diff --git a/src/models.py b/src/models.py index 71747f8..39c7f8f 100644 --- a/src/models.py +++ b/src/models.py @@ -43,7 +43,7 @@ def _build_filter(day=None, room=None, track=None, event=None, **kwargs): __f("track", track.name) if event is not None: __f("id", event.id) - + for k,v in kwargs.items(): __f(k, v) @@ -57,10 +57,10 @@ class Conference: self.user = False for k, v in obj.items(): setattr(self, k, v) - + self.start = datetime.date(*[int(s) for s in self.start.split("-")]) self.end = datetime.date(*[int(s) for s in self.end.split("-")]) - + return self def get_map_links(self): @@ -172,13 +172,13 @@ class Day: def _init(self, data): self.date = data['date'] return self - + def __repr__(self): return "<{} {!r}>".format(self.__class__.__name__, self.date) - + def __str__(self): return self.date.strftime("%x") - + @classmethod def all(cls): for row in local.getDb().execute("SELECT date FROM events GROUP BY date"): @@ -192,11 +192,11 @@ class Day: @classmethod def filter(cls, room=None, track=None, event=None): filterdata, wherestm = _build_filter(room=room, track=track, event=event) - - query = """SELECT date FROM events + + query = """SELECT date FROM events WHERE {} GROUP BY date""".format(" AND ".join(wherestm)) - + for row in local.getDb().execute(query, filterdata): yield cls()._init(row) @@ -212,7 +212,7 @@ class Room: def __str__(self): return self.name or "- no room -" - + @classmethod def all(cls): for row in local.getDb().execute("SELECT room FROM events GROUP BY room"): @@ -222,19 +222,19 @@ class Room: def count(cls): for row in local.getDb().execute("SELECT count(DISTINCT room) FROM events"): return row[0] - + @classmethod def filter(cls, day=None, track=None, event=None): filterdata, wherestm = _build_filter(day=day, track=track, event=event) - - query = """SELECT room FROM events + + query = """SELECT room FROM events WHERE {} GROUP BY room""".format(" AND ".join(wherestm)) - + for row in local.getDb().execute(query, filterdata): yield cls()._init(row) - + class Track: def _init(self, data): self.name = data['track'] @@ -267,13 +267,13 @@ class Person: self.id = data['id'] self.name = data['name'] return self - + def events(self): for row in local.getDb().execute( """SELECT e.* FROM events as e LEFT JOIN event_person AS ep ON e.id = ep.event_id WHERE ep.person_id = ?""", (self.id,)): - yield Event()._init(row) + yield Event()._init(row) def __repr__(self): return "<{} {!r}>".format(self.__class__.__name__, self.name) @@ -285,7 +285,7 @@ class Person: def all(cls): for row in local.getDb().execute( "SELECT id, name FROM persons"): - yield cls()._init(row) + yield cls()._init(row) class Link: @@ -307,7 +307,7 @@ class Event(GObject.GObject): __gsignals__ = { 'update': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, ()) } - + def _init(self, data): self.id = data['id'] self.date = data['date'] @@ -324,13 +324,13 @@ class Event(GObject.GObject): self.starred = data['starred'] == 1 self.notified = data['notified'] == 1 return self - + def set_star(self, starred): local.getDb().execute("UPDATE events SET starred=? WHERE id=?",(starred,self.id,)) local.getDb().commit() self.starred = starred self.emit('update') - + def set_notified(self, notified): local.getDb().execute("UPDATE events SET notified=? WHERE id=?",(notified,self.id,)) local.getDb().commit() @@ -344,19 +344,19 @@ class Event(GObject.GObject): LEFT JOIN event_person AS ep ON p.id = ep.person_id WHERE ep.event_id = ?""", (self.id,)): yield Person()._init(row) - + def links(self): for row in local.getDb().execute( """SELECT href, name FROM links WHERE event_id=?""", (self.id,)): - yield Link()._init(self, row) - + yield Link()._init(self, row) + def __repr__(self): return "<{} {!r} in {!r} @ {!r}>".format(self.__class__.__name__, self.title, self.room, self.start) def __str__(self): return self.title - + def get_conflicts(self): query = """SELECT * FROM events WHERE starred = 1 AND id != ? AND date = ? @@ -369,12 +369,12 @@ class Event(GObject.GObject): def all(cls): for row in local.getDb().execute("SELECT * FROM events"): yield cls()._init(row) - + @classmethod def filter(cls, day:Day = None, room:Room = None, track:Track = None, **kwargs): filterdata, wherestm = _build_filter(day=day, room=room, track=track, **kwargs) - - query = """SELECT * FROM events + + query = """SELECT * FROM events WHERE {} ORDER BY start, room""".format(" AND ".join(wherestm)) for row in local.getDb().execute(query, filterdata): @@ -411,4 +411,3 @@ class Event(GObject.GObject): yield cls()._init(row) - diff --git a/src/pages.py b/src/pages.py index 4a57c89..5e6c09f 100644 --- a/src/pages.py +++ b/src/pages.py @@ -71,9 +71,9 @@ class BasePage(Gtk.ScrolledWindow): self.column = Handy.Clamp( tightening_threshold=500, # dimensione sotto la quale decide di occupare tutto lo spazio maximum_size=640) # dimensione massima allragandosi - + super().add(self.column) - + def add(self, widget): self.column.add(widget) @@ -85,16 +85,16 @@ class BaseListPage(BasePage): """Base class for ListBox based pages""" title = "" subtitle = "" - + def __init__(self, title=None, subtitle=None, **kwargs): super().__init__(**kwargs) - + title = title or self.title subtitle = subtitle or self.subtitle box = Gtk.VBox() box.get_style_context().add_class("main-box") - + if title != "" or subtitle != "": titlebox = Gtk.VBox(margin_left=8, margin_right=8) if title != "": @@ -109,40 +109,40 @@ class BaseListPage(BasePage): titlebox.pack_start(label, False, False, 0) box.pack_start(titlebox, False, False, 2) - - + + frame = Gtk.Frame(valign=Gtk.Align.START) - + listbox = Gtk.ListBox() listbox.connect('row-activated', self.on_activate) #listbox.get_style_context().add_class("content") listbox.set_header_func(self.build_list_header, None) - + self.listbox = listbox # TODO: use list model? self.update_list() - + frame.add(listbox) box.pack_start(frame, True, True, 2) - + self.add(box) - + def update_list(self, *args): self.data = list(self.get_objects()) for w in self.listbox.get_children(): w.destroy() - + lastgroup = None for obj in self.data: mn = self.build_row(obj) self.listbox.add(mn) self.listbox.show_all() - + def get_objects(self): return [] - + def build_list_header(self, row, before, *user_data): if len(self.data) == 0: return @@ -159,15 +159,15 @@ class BaseListPage(BasePage): if group_txt2 != group_txt1: h = ListRowHeader(group_txt1) row.set_header(h) - + def group_by(self, obj): return None - + def build_row(self, obj): row = Handy.ActionRow(activatable=True, selectable=False) row.set_title(str(obj)) return row - + def on_activate(self, listbox, actionrow): ... @@ -182,7 +182,7 @@ class ConferencePage(BasePage): def __init__(self, conf, **kwargs): super().__init__(**kwargs) - + meta = models.Meta() LBL_PROPS = { @@ -192,7 +192,7 @@ class ConferencePage(BasePage): } box = Gtk.VBox(valign=Gtk.Align.CENTER) - + self.logoimage = MaxSizedImage(max_width=200, max_height=200) f = conf.get_logo_file(cbk=self._set_logo) box.pack_start(self.logoimage, False, False, 16) @@ -200,7 +200,7 @@ class ConferencePage(BasePage): label = Gtk.Label(**LBL_PROPS) label.set_markup("<big><b>{}</b></big>".format(_clean_markup(meta.title))) box.pack_start(label, False, False, 16) - + if meta.venue is not None: label = Gtk.Label(html.unescape(meta.venue), **LBL_PROPS) label.get_style_context().add_class("dim-label") @@ -219,7 +219,7 @@ class ConferencePage(BasePage): datebox.pack_start(label, False, False, 8) box.pack_start(datebox, False, False, 16) - + links = conf.metadata.get('links',None) if links is not None: frame = Gtk.Frame() @@ -229,7 +229,7 @@ class ConferencePage(BasePage): if l['title'] != "Map": row = WebLinkActionRow(html.unescape(l['title']), l['url'], l.get('type', None)) listbox.add(row) - + frame.add(listbox) box.pack_start(frame, False, False, 16) @@ -245,10 +245,10 @@ class ConferencePage(BasePage): class DaysPage(BaseListPage): """Days list page""" title = _("Days") - + def get_objects(self): return models.Day.all() - + def build_row(self, obj): row = Handy.ActionRow(activatable=True, selectable=False) row.set_title(obj.date.strftime(FMT_DAY_LIST)) @@ -267,10 +267,10 @@ class DaysPage(BaseListPage): class TracksPage(BaseListPage): """Tracks list page""" title = _("Tracks") - + def get_objects(self): return models.Track.all() - + #def group_by(self, obj): # return obj.date.strftime(FMT_DAY_LIST) @@ -286,7 +286,7 @@ class TracksPage(BaseListPage): subtitle = [] if len(obj.room) == 1 and obj.room[0].name != "": subtitle.append(obj.room[0].name) - + if len(obj.date) == 1: subtitle.append(obj.date[0].date.strftime(FMT_DAY_LIST)) @@ -301,7 +301,7 @@ class TracksPage(BaseListPage): class RoomsPage(BaseListPage): """Rooms list page""" title = _("Rooms") - + def get_objects(self): return models.Room.all() @@ -326,7 +326,7 @@ class EventsPage(BaseListPage): self.filters = filters self._group_by = group_by super().__init__(title=title, subtitle=subtitle) - + def group_by(self, obj): if self._group_by == "day": return obj.date.strftime(FMT_DAY_LIST) @@ -336,14 +336,14 @@ class EventsPage(BaseListPage): return obj.room else: return None - + def get_objects(self): return models.Event.filter(**self.filters) - + def build_row(self, obj): row = EventActionRow(obj) return row - + def on_activate(self, listbox, actionrow): idx = actionrow.get_index() obj = self.data[idx] @@ -387,12 +387,12 @@ class EventDetailPage(BasePage): LBL_PROPS = { 'justify': Gtk.Justification.FILL, - 'halign' : Gtk.Align.START, + 'halign' : Gtk.Align.START, 'wrap' : True, } box = Gtk.VBox( margin_left=8, margin_right=8) - + titlebox = Gtk.VBox() label = Gtk.Label(**LBL_PROPS) @@ -404,17 +404,17 @@ class EventDetailPage(BasePage): label.set_markup("{}".format(_clean_markup(obj.subtitle))) #label.get_style_context().add_class("dim-label") titlebox.pack_start(label, False, False, 0) - + label = Gtk.Label(**LBL_PROPS) label.set_markup("<small>{}</small>".format( ", ".join([ _clean_markup(str(p)) for p in obj.persons()]))) label.get_style_context().add_class("dim-label") titlebox.pack_start(label, False, False, 0) - + box.pack_start(titlebox, False, False, 16) starbox = Gtk.HBox() - + titlebox = Gtk.VBox() label = Gtk.Label(**LBL_PROPS) label.set_markup("<b>{}-{}</b>".format( @@ -426,7 +426,7 @@ class EventDetailPage(BasePage): label = Gtk.Label(**LBL_PROPS) label.set_markup(_("Room: <b>{}</b>").format(obj.room)) titlebox.pack_start(label, False, False, 0) - + if obj.track: label = Gtk.Label(**LBL_PROPS) label.set_markup(_("Track: <b>{}</b>").format(obj.track)) @@ -434,11 +434,11 @@ class EventDetailPage(BasePage): starbox.pack_start(titlebox, False, True, 0) - icon_name = "starred-symbolic" if obj.starred else "non-starred-symbolic" + icon_name = "starred-symbolic" if obj.starred else "non-starred-symbolic" self.toggle_btn = Gtk.Button.new_from_icon_name(icon_name, Gtk.IconSize.BUTTON) self.toggle_btn.connect("clicked", self.toggle_starred) starbox.pack_end(self.toggle_btn, False, False, 16) - + box.pack_start(starbox, False, False, 16) self.conflicts = list(obj.get_conflicts()) @@ -485,7 +485,7 @@ class EventDetailPage(BasePage): for l in obj.links(): row = WebLinkActionRow(l.name, l.href) listbox.add(row) - + frame.add(listbox) linkbox.pack_start(frame, False, False, 0) box.pack_start(linkbox, False, False, 16) @@ -514,7 +514,7 @@ class EventDetailPage(BasePage): cr.move_to(0, 1) cr.line_to(x, 1) cr.stroke() - + def toggle_starred(self, button): self.obj.set_star(not self.obj.starred) icon_name = "starred-symbolic" if self.obj.starred else "non-starred-symbolic" @@ -550,7 +550,7 @@ class StarredPage(BaseListPage): self.get_style_context().add_class("starred-page") self.get_style_context().add_class("clean-list") self.listbox.set_placeholder(self.empty_placeholder) - + def get_objects(self): return models.Event.filter(starred = True) @@ -578,13 +578,13 @@ class StarredPage(BaseListPage): class MainMenuPage(Gtk.ScrolledWindow): """Leaflet sidebar menu""" - + ITEMS = ( ["EVENT", "emblem-system-symbolic", ConferencePage, None], (_("Days"), "x-office-calendar-symbolic", DaysPage, models.Day.count), (_("Tracks"), "format-justify-fill-symbolic", TracksPage, models.Track.count), (_("Rooms"),"display-projector-symbolic", RoomsPage, models.Room.count)) - + def __init__(self, pageStack, conf): super().__init__( width_request=270, @@ -594,9 +594,9 @@ class MainMenuPage(Gtk.ScrolledWindow): self.pageStack = pageStack self.conf = conf - + self.ITEMS[0][0] = conf.title - + self.listbox = Gtk.ListBox() self.update() self.listbox.connect('row-activated', self.on_activate) diff --git a/src/widgets.py b/src/widgets.py index d865249..528244d 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -59,7 +59,7 @@ class WebLinkActionRow(Handy.ActionRow): icontype = ftype if fmin == 'pdf' or 'document' in fmin: icontype = ftype - + self.content_type = icontype ficon = Gio.content_type_get_icon(icontype) @@ -77,11 +77,11 @@ def weblinkactionrowactivated(listbox, actionrow): - + class EventActionRow(Handy.ActionRow): def __init__(self, obj): super().__init__(activatable=True, selectable=False) - + subtitle = "{}-{}".format( obj.start.strftime("%a %H:%M"), obj.end.strftime("%H:%M")) @@ -101,14 +101,14 @@ class EventActionRow(Handy.ActionRow): subtitle = "{} - {}".format( subtitle, ", ".join([str(p) for p in ps])) - + self.set_title(html.unescape(obj.title)) self.set_subtitle(html.unescape(subtitle)) self.obj = obj obj.connect('update', self.on_update) - - icon_name = "starred-symbolic" if obj.starred else "non-starred-symbolic" + + icon_name = "starred-symbolic" if obj.starred else "non-starred-symbolic" self.toggle_btn = Gtk.Button.new_from_icon_name(icon_name, Gtk.IconSize.BUTTON) self.toggle_btn.connect("clicked", self.toggle_starred) self.add(self.toggle_btn) @@ -138,7 +138,7 @@ class EventActionRow(Handy.ActionRow): def on_update(self, *args): icon_name = "starred-symbolic" if self.obj.starred else "non-starred-symbolic" self.toggle_btn.get_image().set_from_icon_name(icon_name, Gtk.IconSize.BUTTON) - + def toggle_starred(self, button): self.obj.set_star(not self.obj.starred) @@ -221,7 +221,7 @@ class ErrorWidget(Gtk.VBox): lbl1.set_markup("<b>{}</b>".format(msg)) lbl2 = Gtk.Label(str(error)) lbl2.get_style_context().add_class("dim-label") - + self.pack_start(img, False, False, 16) self.pack_start(lbl1, False, False, 0) self.pack_start(lbl2, False, False, 0) @@ -615,4 +615,4 @@ class MaxSizedImage(Gtk.Image): h, GdkPixbuf.InterpType.BILINEAR) super().set_from_pixbuf(pixbuf) - + diff --git a/src/window.py b/src/window.py index 86a9bf0..6b29e13 100644 --- a/src/window.py +++ b/src/window.py @@ -173,7 +173,7 @@ class StartView(pages.BaseListPage): is_connected = self.nm.props.isconnected self.update_button.set_sensitive(is_connected) self.open_button.set_sensitive(is_connected) - + def update_schedules(self, *args): fetcher = local.update_menu() def _done(s, f): @@ -186,7 +186,7 @@ class StartView(pages.BaseListPage): self.window.loading.show(fetcher) fetcher.connect("done", _done) fetcher.connect("error", _error) - + def edit_meta(self, url): conf = models.Conference.by_url(url) if conf is None: @@ -259,7 +259,7 @@ class StartView(pages.BaseListPage): return _("Past") else: return _("Coming up") - + def build_row(self, obj): row = Handy.ActionRow(activatable=True, selectable=False) row.set_title(obj.title) @@ -306,7 +306,7 @@ class MainView(Gtk.VBox): def __init__(self, window, conf): super().__init__() - + title_bar = Handy.HeaderBar( centering_policy = Handy.CenteringPolicy.STRICT, show_close_button = True, @@ -375,7 +375,7 @@ class MainView(Gtk.VBox): self.back_button.set_tooltip_text(_("Go back")) self.back_button.connect('clicked', self.goBack) title_bar.pack_start(self.back_button) - + # search button _search_button_icon = Gtk.Image.new_from_pixbuf( Gtk.IconTheme.get_default().load_icon( @@ -397,7 +397,7 @@ class MainView(Gtk.VBox): transition_type=Gtk.StackTransitionType.NONE, vexpand_set=True, vexpand=True) - + self.leaflet = Handy.Leaflet( can_swipe_back=True, hhomogeneous_folded=True, @@ -411,14 +411,14 @@ class MainView(Gtk.VBox): can_swipe_back=True, can_swipe_forward=False) self.stack_schedule.connect("notify::transition-running", self.on_stack_changed) - + # add main menu and stack to leaflet self.leaflet.add(self.main_menu) sep = Gtk.Separator() self.leaflet.add(sep) self.leaflet.child_set_property(sep, 'navigatable', False) self.leaflet.add(self.stack_schedule) - + # add first page to stack_schedule self.stack_schedule.add(pages.ConferencePage(self.conf)) self.stack_schedule.count = 1 @@ -436,7 +436,7 @@ class MainView(Gtk.VBox): # add first page to stack_starred self.stack_starred.add(self.starred) self.stack_starred.count = 1 - + # set current stack self.stack = self.stack_schedule @@ -445,11 +445,11 @@ class MainView(Gtk.VBox): self.mainstack.add_titled(self.leaflet, "schedule", _("Schedule")) self.mainstack.child_set_property(self.leaflet, "icon-name", "x-office-calendar-symbolic") - + self.mainstack.add_titled(self.stack_starred, "starred", _("Starred")) self.mainstack.child_set_property(self.stack_starred, "icon-name", "starred-symbolic") - + if len(self.conf.get_map_links()) > 0: self.map = pages.MapPage(self.conf) @@ -462,10 +462,10 @@ class MainView(Gtk.VBox): stack=self.mainstack) self.bottom_switcher = Handy.ViewSwitcherBar( stack=self.mainstack) - + #mainstack event self.mainstack.connect("notify::visible-child", self.on_mainstack_changed) - + squeezer = Handy.Squeezer() squeezer.add(self.top_switcher) title_label = Gtk.Label() @@ -473,15 +473,15 @@ class MainView(Gtk.VBox): squeezer.add(title_label) title_bar.set_custom_title(squeezer) squeezer.connect("notify::visible-child",self.on_headerbar_squeezer_notify) - + # main box contanier self.pack_start(self.mainstack, True, True, 0) self.pack_start(self.bottom_switcher, False, False, 0) - + title_bar.show_all() self.show_all() - + # Check if there are notifications to send Gio.Application.get_default().connect( 'tick', self.check_event_notification @@ -514,11 +514,11 @@ class MainView(Gtk.VBox): elif (self.mainstack.get_visible_child() == self.leaflet): self.stack = self.stack_schedule self.update_titlebar_buttons() - + def on_headerbar_squeezer_notify(self, squeezer, event): child = squeezer.get_visible_child() self.bottom_switcher.set_reveal(child != self.top_switcher) - + def on_leaflet_notify(self, sender, prop): self.update_titlebar_buttons() @@ -681,7 +681,7 @@ class MainView(Gtk.VBox): previous = self.stack.get_children()[-2] self.stack.set_visible_child(previous) self.stack.count = self.stack.count - 1 - + folded = self.leaflet.get_property('folded') while not folded and self.leaflet.get_child_transition_running(): pass @@ -710,11 +710,11 @@ class MainView(Gtk.VBox): self.leaflet.set_visible_child(self.stack) self.stack.set_visible_child(page) self.stack.count = 1 - + #folded = self.leaflet.get_property('folded') #while not folded and self.leaflet.get_child_transition_running(): # pass - + for w in self.stack.get_children()[:-1]: w.destroy() @@ -776,7 +776,7 @@ class ConfyWindow(Gtk.ApplicationWindow): self.view = None self.show_all() - + self.show_start() def show_preferences(self, *args): @@ -814,7 +814,7 @@ class ConfyWindow(Gtk.ApplicationWindow): self.view = StartView(self) self.box.pack_start(self.view, True, True, 0) local.close() - + def show_main(self, conf): """start page, list conferences""" if self.view is not None: -- 2.30.2
Merged, thought I'm not so strict with whitespaces :)