1616
1717import logging
1818
19- from gi .repository import GObject
2019from gi .repository import GLib
20+ from gettext import gettext as _
2121from gi .repository import Gtk
2222from gi .repository import Gdk
23+ from gi .repository import GObject
2324
24- from sugar3 .graphics import style
25- from sugar3 .graphics .popwindow import PopWindow
2625from sugar3 .activity import activityfactory
2726from sugar3 .graphics import iconentry
27+ from sugar3 .graphics import style
28+ from sugar3 .graphics .toolbutton import ToolButton
2829
30+ from jarabe .model import shell
2931from jarabe .desktop .activitieslist import ActivitiesList
3032from jarabe .util .normalize import normalize_string
3133
34+
35+ class TitleBox (Gtk .Toolbar ):
36+ def __init__ (self ):
37+ Gtk .Toolbar .__init__ (self )
38+
39+ self .close_button = ToolButton (icon_name = 'dialog-cancel' )
40+ self .close_button .set_tooltip (_ ('Close' ))
41+ self .insert (self .close_button , - 1 )
42+ self .close_button .show ()
43+
44+ self ._label = Gtk .Label ()
45+ self ._label .set_alignment (0 , 0.5 )
46+
47+ tool_item = Gtk .ToolItem ()
48+ tool_item .set_expand (True )
49+ tool_item .add (self ._label )
50+ self ._label .show ()
51+ self .insert (tool_item , 0 )
52+ tool_item .show ()
53+
54+ def set_title (self , title ):
55+ self ._label .set_markup ('<b>%s</b>' % title )
56+ self ._label .show ()
57+
58+
3259_AUTOSEARCH_TIMEOUT = 1000
3360
3461
35- class ActivityChooser (PopWindow ):
62+ class ActivityChooser (Gtk . Window ):
3663
3764 __gtype_name__ = 'ActivityChooser'
3865
@@ -43,16 +70,37 @@ class ActivityChooser(PopWindow):
4370 }
4471
4572 def __init__ (self ):
46- logging .debug ('In the Object Chooser class init hehehe' )
47- PopWindow .__init__ (self )
48- width , height = self .HALF_WIDTH
49-
50- self .set_size ((width * 3 / 2 , height * 2 / 3 ))
73+ Gtk .Window .__init__ (self )
74+
75+ self .set_decorated (False )
76+ self .set_position (Gtk .WindowPosition .CENTER_ALWAYS )
77+ self .set_border_width (style .LINE_WIDTH )
78+ self .set_resizable (False )
79+ self .set_modal (True )
80+ self .set_can_focus (True )
81+
82+ self ._vbox = Gtk .Box (orientation = Gtk .Orientation .VERTICAL )
83+ self .add (self ._vbox )
84+ self ._vbox .show ()
85+
86+ self ._title_box = TitleBox ()
87+ self ._title_box .close_button .connect (
88+ 'clicked' ,
89+ self .__close_button_clicked_cb )
90+ self ._title_box .set_size_request (- 1 , style .GRID_CELL_SIZE )
91+
92+ self ._vbox .pack_start (self ._title_box , False , True , 0 )
93+ self ._title_box .show ()
94+
95+ self .set_size_request ((Gdk .Screen .height () - style .GRID_CELL_SIZE * 3 )* 3 / 4 ,
96+ (Gdk .Screen .height () - style .GRID_CELL_SIZE * 2 )* 2 / 3 )
5197 self .connect ('key-press-event' , self .__key_press_event_cb )
98+ self .connect ('realize' , self .__realize_cb )
99+
52100 self ._list_view = ActivitiesList ()
53101
54102 self .search_bar = SearchBar ()
55- self .get_vbox () .pack_start (self .search_bar , False , False , 0 )
103+ self ._vbox .pack_start (self .search_bar , False , False , 0 )
56104 self .search_bar .connect ('query-changed' ,
57105 self .__toolbar_query_changed_cb )
58106 self .search_bar .search_entry .connect ('key-press-event' ,
@@ -64,7 +112,7 @@ def __init__(self):
64112
65113 self ._scrolled_window .add (self ._list_view )
66114
67- self .get_vbox () .pack_start (self ._scrolled_window , True , True , 0 )
115+ self ._vbox .pack_start (self ._scrolled_window , True , True , 0 )
68116
69117 self ._list_view .show ()
70118 self ._list_view .connect ('clear-clicked' ,
@@ -101,6 +149,17 @@ def __init__(self):
101149
102150 self .show ()
103151
152+ def __close_button_clicked_cb (self , button ):
153+ self .destroy ()
154+
155+ def __realize_cb (self , widget ):
156+ shell .get_model ().push_modal ()
157+ self .set_type_hint (Gdk .WindowTypeHint .DIALOG )
158+ window = self .get_window ()
159+ window .set_accept_focus (True )
160+ shell .get_model ().push_modal ()
161+
162+
104163 def __toolbar_query_changed_cb (self , toolbar , query ):
105164 self ._query = normalize_string (query .decode ('utf-8' ))
106165 self ._list_view .set_filter (self ._query )
@@ -125,6 +184,10 @@ def __toolbar_query_changed_cb(self, toolbar, query):
125184 toolbar .search_entry .select_region (pos , - 1 )
126185
127186 def __key_press_event_cb (self , widget , event ):
187+ keyname = Gdk .keyval_name (event .keyval )
188+ if keyname == 'Escape' :
189+ self .destroy ()
190+
128191 if not self .search_bar .search_entry .has_focus ():
129192 self .search_bar .search_entry .grab_focus ()
130193
@@ -146,7 +209,7 @@ def __activitylist_clear_clicked_cb(self, list_view, toolbar):
146209 toolbar .clear_query ()
147210
148211 def set_title (self , text ):
149- self .get_title_box () .set_title (text )
212+ self ._title_box .set_title (text )
150213
151214 def _got_row_tree_view (self , row ):
152215 bundle_id = row [self .tree_view ._model .column_bundle_id ]
0 commit comments