2626from typing import Optional , List
2727from 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+ )
3135from .desktop_file_manager import ApplicationInfo
3236from .vm_manager import VMManager , VMEntry
3337from .utils import load_icon , text_search , highlight_words , remove_from_feature
3438from . import constants
3539
3640import gi
37- gi .require_version ('Gtk' , '3.0' )
41+
42+ gi .require_version ("Gtk" , "3.0" )
3843from 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
4651class 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
145151class 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
177185class 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
250258class 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