Skip to content

Commit 4a3aacb

Browse files
committed
Black formatter
1 parent a4c3ac3 commit 4a3aacb

25 files changed

Lines changed: 1059 additions & 822 deletions

.gitlab-ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include:
99
checks:pylint:
1010
stage: checks
1111
before_script:
12-
- sudo dnf install -y python3-gobject gtk3 xorg-x11-server-Xvfb
12+
- sudo dnf install -y python3-gobject gtk3 xorg-x11-server-Xvfb
1313
python3-pip python3-mypy python3-pyxdg gtk-layer-shell
1414
- pip3 install --quiet -r ci/requirements.txt
1515
- git clone https://github.com/QubesOS/qubes-core-admin-client ~/core-admin-client
@@ -24,7 +24,7 @@ checks:tests:
2424
before_script: &before-script
2525
- "PATH=$PATH:$HOME/.local/bin"
2626
- sudo dnf install -y python3-gobject gtk3 python3-pytest python3-pytest-asyncio
27-
python3-coverage xorg-x11-server-Xvfb python3-inotify sequoia-sqv
27+
python3-coverage xorg-x11-server-Xvfb python3-inotify sequoia-sqv
2828
python3-pip python3-pyxdg gtk-layer-shell
2929
- pip3 install --quiet -r ci/requirements.txt
3030
- git clone https://github.com/QubesOS/qubes-core-admin-client ~/core-admin-client
@@ -35,3 +35,9 @@ checks:tests:
3535
- "PATH=$PATH:$HOME/.local/bin"
3636
- ci/codecov-wrapper
3737

38+
checks:black:
39+
stage: checks
40+
variables:
41+
DIR: .
42+
SKIP_PYLINT: 1
43+
run: black -l88 -v --diff --color --check

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ notes=FIXME,FIX,XXX,TODO
8080
[FORMAT]
8181

8282
# Maximum number of characters on a single line.
83-
max-line-length=80
83+
max-line-length=88
8484

8585
# Maximum number of lines in a module
8686
max-module-lines=3000

qubes_menu/app_widgets.py

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,26 @@
2626
from typing import Optional, List
2727
from functools import reduce
2828

29-
from .custom_widgets import (LimitedWidthLabel, SelfAwareMenu, HoverEventBox,
30-
FavoritesMenu)
29+
from .custom_widgets import (
30+
LimitedWidthLabel,
31+
SelfAwareMenu,
32+
HoverEventBox,
33+
FavoritesMenu,
34+
)
3135
from .desktop_file_manager import ApplicationInfo
3236
from .vm_manager import VMManager, VMEntry
3337
from .utils import load_icon, text_search, highlight_words, remove_from_feature
3438
from . import constants
3539

3640
import gi
37-
gi.require_version('Gtk', '3.0')
41+
42+
gi.require_version("Gtk", "3.0")
3843
from gi.repository import Gtk, Gdk
3944

4045

41-
logger = logging.getLogger('qubes-appmenu')
46+
logger = logging.getLogger("qubes-appmenu")
4247

43-
DISP_TEXT = 'new Disposable Qube from '
48+
DISP_TEXT = "new Disposable Qube from "
4449

4550

4651
class AppEntry(Gtk.ListBoxRow):
@@ -53,6 +58,7 @@ class AppEntry(Gtk.ListBoxRow):
5358
- supports running an application on click; after click signals to the
5459
complete menu it might need hiding
5560
"""
61+
5662
def __init__(self, app_info: ApplicationInfo, **properties):
5763
"""
5864
:param app_info: ApplicationInfo obj with data about related app file
@@ -61,23 +67,21 @@ def __init__(self, app_info: ApplicationInfo, **properties):
6167
super().__init__(**properties)
6268
self.app_info = app_info
6369
self.app_info.entries.append(self)
64-
self.vm_name = app_info.vm.name if app_info.vm else 'dom0'
70+
self.vm_name = app_info.vm.name if app_info.vm else "dom0"
6571

6672
self.menu = SelfAwareMenu()
6773

6874
self.event_box = HoverEventBox(focus_widget=self)
6975
self.add(self.event_box)
7076
self.event_box.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
71-
self.event_box.connect('button-press-event', self.show_menu)
77+
self.event_box.connect("button-press-event", self.show_menu)
7278

73-
self.drag_source_set(
74-
Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.COPY)
79+
self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.COPY)
7580
self.drag_source_add_uri_targets()
7681
self.connect("drag-data-get", self._on_drag_data_get)
7782

7883
def _on_drag_data_get(self, _widget, _drag_context, data, _info, _time):
79-
data.set_uris(['file://' +
80-
urllib.parse.quote(str(self.app_info.file_path))])
84+
data.set_uris(["file://" + urllib.parse.quote(str(self.app_info.file_path))])
8185

8286
def show_menu(self, _widget, event):
8387
"""
@@ -107,6 +111,7 @@ class BaseAppEntry(AppEntry):
107111
"""
108112
A 'normal' Application row, used by main applications menu and system tools.
109113
"""
114+
110115
def __init__(self, app_info: ApplicationInfo, **properties):
111116
"""
112117
:param app_info: ApplicationInfo obj with data about related app file
@@ -115,7 +120,7 @@ def __init__(self, app_info: ApplicationInfo, **properties):
115120
super().__init__(app_info, **properties)
116121
self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
117122
self.event_box.add(self.box)
118-
self.get_style_context().add_class('app_entry')
123+
self.get_style_context().add_class("app_entry")
119124
self.menu = FavoritesMenu(lambda: self.app_info)
120125

121126
self.icon = Gtk.Image()
@@ -137,25 +142,29 @@ def show_menu(self, widget, event):
137142
def update_contents(self):
138143
"""Update icon and app name."""
139144
self.icon.set_from_pixbuf(
140-
load_icon(self.app_info.app_icon, Gtk.IconSize.LARGE_TOOLBAR))
145+
load_icon(self.app_info.app_icon, Gtk.IconSize.LARGE_TOOLBAR)
146+
)
141147
self.label.set_label(self.app_info.app_name)
142148
self.show_all()
143149

144150

145151
class VMIcon(Gtk.Image):
146152
"""Helper class for displaying and auto-updating"""
153+
147154
def __init__(self, vm_entry: Optional[VMEntry]):
148155
super().__init__()
149156
self.vm_entry = vm_entry
150157
if self.vm_entry:
151158
self.vm_entry.entries.append(self)
152159
self.update_contents(update_label=True)
153160

154-
def update_contents(self,
155-
update_power_state=False,
156-
update_label=False,
157-
update_has_network=False,
158-
update_type=False):
161+
def update_contents(
162+
self,
163+
update_power_state=False,
164+
update_label=False,
165+
update_has_network=False,
166+
update_type=False,
167+
):
159168
# pylint: disable=unused-argument
160169
"""
161170
Update own contents (or related widgets, if applicable) based on state
@@ -168,19 +177,18 @@ def update_contents(self,
168177
:return:
169178
"""
170179
if update_label and self.vm_entry:
171-
vm_icon = load_icon(self.vm_entry.vm_icon_name,
172-
Gtk.IconSize.LARGE_TOOLBAR)
180+
vm_icon = load_icon(self.vm_entry.vm_icon_name, Gtk.IconSize.LARGE_TOOLBAR)
173181
self.set_from_pixbuf(vm_icon)
174182
self.show_all()
175183

176184

177185
class AppEntryWithVM(AppEntry):
178186
"""Application Gtk.ListBoxRow with VM description underneath; to be
179187
used in Search and Favorites."""
180-
def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager,
181-
**properties):
188+
189+
def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager, **properties):
182190
super().__init__(app_info, **properties)
183-
self.get_style_context().add_class('favorite_entry')
191+
self.get_style_context().add_class("favorite_entry")
184192
self.grid = Gtk.Grid()
185193
self.event_box.add(self.grid)
186194

@@ -192,8 +200,8 @@ def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager,
192200
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
193201
box.pack_start(self.vm_icon, False, False, 5)
194202
box.pack_start(self.vm_label, False, False, 5)
195-
self.vm_label.get_style_context().add_class('favorite_vm_name')
196-
self.app_label.get_style_context().add_class('favorite_app_name')
203+
self.vm_label.get_style_context().add_class("favorite_vm_name")
204+
self.app_label.get_style_context().add_class("favorite_app_name")
197205
self.app_label.set_halign(Gtk.Align.START)
198206

199207
self.grid.attach(self.app_icon, 0, 0, 1, 2)
@@ -210,8 +218,7 @@ def update_contents(self):
210218
self.app_icon.set_from_pixbuf(app_icon)
211219

212220
if self.app_info.disposable:
213-
self.vm_label.set_text(
214-
DISP_TEXT + str(self.app_info.vm))
221+
self.vm_label.set_text(DISP_TEXT + str(self.app_info.vm))
215222
elif self.app_info.vm:
216223
self.vm_label.set_text(str(self.app_info.vm))
217224
else:
@@ -228,11 +235,11 @@ class FavoritesAppEntry(AppEntryWithVM):
228235
constants.py, as a space-separated list containing a subset of menu-items
229236
feature.
230237
"""
231-
def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager,
232-
**properties):
238+
239+
def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager, **properties):
233240
super().__init__(app_info, vm_manager, **properties)
234-
self.remove_item = Gtk.MenuItem(label='Remove from favorites')
235-
self.remove_item.connect('activate', self._remove_from_favorites)
241+
self.remove_item = Gtk.MenuItem(label="Remove from favorites")
242+
self.remove_item.connect("activate", self._remove_from_favorites)
236243
self.menu.add(self.remove_item)
237244
self.menu.show_all()
238245

@@ -241,16 +248,17 @@ def _remove_from_favorites(self, *_args, **_kwargs):
241248
feature"""
242249
if not self.app_info.entry_name:
243250
return # there is nothing to remove
244-
vm = self.app_info.vm or self.app_info.qapp.domains[
245-
self.app_info.qapp.local_name]
246-
remove_from_feature(vm, constants.FAVORITES_FEATURE,
247-
self.app_info.entry_name)
251+
vm = (
252+
self.app_info.vm
253+
or self.app_info.qapp.domains[self.app_info.qapp.local_name]
254+
)
255+
remove_from_feature(vm, constants.FAVORITES_FEATURE, self.app_info.entry_name)
248256

249257

250258
class SearchAppEntry(AppEntryWithVM):
251259
"""Entry for apps listed on the Search tab."""
252-
def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager,
253-
**properties):
260+
261+
def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager, **properties):
254262

255263
super().__init__(app_info, vm_manager, **properties)
256264
self.menu = FavoritesMenu(lambda: self.app_info)
@@ -269,17 +277,21 @@ def __init__(self, app_info: ApplicationInfo, vm_manager: VMManager,
269277

270278
if self.app_info.vm:
271279
self.search_words.extend(
272-
self.app_info.vm.name.lower().replace('_', '-').split('-'))
280+
self.app_info.vm.name.lower().replace("_", "-").split("-")
281+
)
273282
else:
274-
self.search_words.append('dom0')
283+
self.search_words.append("dom0")
275284

276285
if self.app_info.disposable:
277286
self.search_words.extend(DISP_TEXT.lower().split())
278287

279288
if self.app_info.app_name:
280289
self.search_words.extend(
281-
self.app_info.app_name.lower().replace(
282-
'_', ' ').replace('-', ' ').split())
290+
self.app_info.app_name.lower()
291+
.replace("_", " ")
292+
.replace("-", " ")
293+
.split()
294+
)
283295

284296
if self.app_info.keywords:
285297
self.search_words.extend(k.lower() for k in self.app_info.keywords)
@@ -293,9 +305,10 @@ def find_text(self, search_words: List[str]):
293305
return self.last_search_result
294306

295307
if search_words:
296-
result = reduce(lambda x, y: x*y,
297-
[text_search(word, self.search_words)
298-
for word in search_words])
308+
result = reduce(
309+
lambda x, y: x * y,
310+
[text_search(word, self.search_words) for word in search_words],
311+
)
299312
else:
300313
result = 0
301314

0 commit comments

Comments
 (0)