1 | import gi |
---|
2 | gi.require_version('Gtk', '3.0') |
---|
3 | from gi.repository import Gtk,GdkPixbuf,GLib,GObject, Pango |
---|
4 | |
---|
5 | import os |
---|
6 | import ImageManager |
---|
7 | import Core |
---|
8 | import Screenshot |
---|
9 | |
---|
10 | class SearchBox(Gtk.VBox): |
---|
11 | |
---|
12 | def __init__(self): |
---|
13 | |
---|
14 | Gtk.VBox.__init__(self) |
---|
15 | |
---|
16 | self.core=Core.Core.get_core() |
---|
17 | ui_path=self.core.ui_path |
---|
18 | builder=Gtk.Builder() |
---|
19 | builder.add_from_file(ui_path) |
---|
20 | |
---|
21 | self.label_max_width=53 |
---|
22 | |
---|
23 | self.current_category="" |
---|
24 | self.current_pkg_list=[] |
---|
25 | |
---|
26 | self.search_box=builder.get_object("search_box2") |
---|
27 | self.search_box.set_name("DETAILS_BOX") |
---|
28 | self.results_search_box=builder.get_object("search_results_box") |
---|
29 | self.search_sw=builder.get_object("results_scrolledwindow") |
---|
30 | self.search_categories_box=builder.get_object("search_categories_box") |
---|
31 | self.categories_sw=builder.get_object("categories_scrolledwindow") |
---|
32 | |
---|
33 | #self.search_categories_box.set_name("LIGHT_BLUE_BOX") |
---|
34 | |
---|
35 | self.add(self.search_box) |
---|
36 | self.show_all() |
---|
37 | |
---|
38 | #def init |
---|
39 | |
---|
40 | |
---|
41 | def populate_search_results(self,pkg_list,categories=None): |
---|
42 | |
---|
43 | |
---|
44 | for child in self.results_search_box.get_children(): |
---|
45 | self.results_search_box.remove(child) |
---|
46 | |
---|
47 | for child in self.search_categories_box.get_children(): |
---|
48 | self.search_categories_box.remove(child) |
---|
49 | |
---|
50 | # restore scroll bar to top |
---|
51 | self.search_sw.get_vadjustment().set_value(0) |
---|
52 | |
---|
53 | self.current_pkg_list=pkg_list |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | if categories!=None: |
---|
60 | |
---|
61 | found_categories=set() |
---|
62 | |
---|
63 | for pkg in pkg_list: |
---|
64 | for category in categories: |
---|
65 | if category in pkg["categories"]: |
---|
66 | found_categories.add(category) |
---|
67 | break |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | found_categories=list(sorted(found_categories)) |
---|
72 | found_categories.insert(0,"All") |
---|
73 | |
---|
74 | counter=0 |
---|
75 | |
---|
76 | for c in found_categories: |
---|
77 | |
---|
78 | hbox=Gtk.HBox() |
---|
79 | hbox.set_name("PKG_BOX") |
---|
80 | |
---|
81 | label=Gtk.Label(c) |
---|
82 | label.set_name("SHORT_DESCRIPTION") |
---|
83 | |
---|
84 | hbox.pack_start(label,True,True,5) |
---|
85 | |
---|
86 | |
---|
87 | b=Gtk.Button() |
---|
88 | b.set_name("RELATED_BUTTON") |
---|
89 | b.add(hbox) |
---|
90 | b.show_all() |
---|
91 | |
---|
92 | #b.set_size_request(150,10) |
---|
93 | b.set_halign(Gtk.Align.FILL) |
---|
94 | |
---|
95 | if counter==0: |
---|
96 | c=None |
---|
97 | |
---|
98 | b.connect("clicked",self.filter_by,c) |
---|
99 | self.search_categories_box.pack_start(b,False,False,3) |
---|
100 | counter+=1 |
---|
101 | |
---|
102 | self.categories_sw.show() |
---|
103 | |
---|
104 | else: |
---|
105 | self.categories_sw.hide() |
---|
106 | |
---|
107 | for pkg in pkg_list: |
---|
108 | |
---|
109 | self.add_pkg_to_list(pkg) |
---|
110 | |
---|
111 | |
---|
112 | #self.results_search_box.set_size_request(50,0) |
---|
113 | self.results_search_box.set_halign(Gtk.Align.FILL) |
---|
114 | self.results_search_box.show_all() |
---|
115 | |
---|
116 | |
---|
117 | #def populate_search_results |
---|
118 | |
---|
119 | |
---|
120 | def add_pkg_to_list(self,pkg): |
---|
121 | |
---|
122 | item_box=Gtk.HBox() |
---|
123 | item_box.set_name("PKG_BOX") |
---|
124 | |
---|
125 | i={} |
---|
126 | i["x"]=64 |
---|
127 | i["y"]=64 |
---|
128 | i["aspect_ratio"]=True |
---|
129 | i["image_path"]=pkg["icon_uri"] |
---|
130 | i["name"]=pkg["name"] |
---|
131 | i["image_id"]=pkg["package"]+"_icon" |
---|
132 | s=Screenshot.ScreenshotNeo() |
---|
133 | s.set_from_file(i) |
---|
134 | |
---|
135 | vbox=Gtk.VBox() |
---|
136 | |
---|
137 | label=Gtk.Label(pkg["name"]) |
---|
138 | label.set_name("RELATED_LABEL") |
---|
139 | label.set_valign(Gtk.Align.END) |
---|
140 | label.set_halign(Gtk.Align.START) |
---|
141 | |
---|
142 | description=Gtk.Label(pkg["summary"]) |
---|
143 | description.set_name("SHORT_DESCRIPTION") |
---|
144 | description.set_valign(Gtk.Align.START) |
---|
145 | description.set_halign(Gtk.Align.START) |
---|
146 | description.set_ellipsize(Pango.EllipsizeMode.END) |
---|
147 | description.set_max_width_chars(self.label_max_width) |
---|
148 | |
---|
149 | vbox.pack_start(label,True,True,1) |
---|
150 | vbox.pack_start(description,True,True,1) |
---|
151 | vbox.set_halign(Gtk.Align.START) |
---|
152 | |
---|
153 | item_box.pack_start(s,False,False,5) |
---|
154 | item_box.pack_start(vbox,True,True,5) |
---|
155 | |
---|
156 | b=Gtk.Button() |
---|
157 | b.add(item_box) |
---|
158 | b.set_name("RELATED_BUTTON") |
---|
159 | b.set_valign(Gtk.Align.START) |
---|
160 | b.set_halign(Gtk.Align.FILL) |
---|
161 | b.connect("clicked",self.result_clicked,pkg) |
---|
162 | |
---|
163 | b.set_size_request(0,80) |
---|
164 | |
---|
165 | self.results_search_box.pack_start(b,False,False,3) |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | #def create_item |
---|
170 | |
---|
171 | def filter_by(self,widget,filter): |
---|
172 | |
---|
173 | for child in self.results_search_box.get_children(): |
---|
174 | self.results_search_box.remove(child) |
---|
175 | |
---|
176 | |
---|
177 | for pkg in self.current_pkg_list: |
---|
178 | |
---|
179 | if filter==None: |
---|
180 | self.add_pkg_to_list(pkg) |
---|
181 | continue |
---|
182 | if filter in pkg["categories"]: |
---|
183 | self.add_pkg_to_list(pkg) |
---|
184 | |
---|
185 | self.results_search_box.show_all() |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | #def filter_by |
---|
190 | |
---|
191 | def result_clicked(self,widget,pkg_data): |
---|
192 | |
---|
193 | self.core.main_window.load_pkg_data(pkg_data["package"]) |
---|
194 | |
---|
195 | |
---|
196 | #class SearchBox |
---|