[pitivi] greeter: search projects functionality



commit c72ebce7a8f4a09f2f5e8445bf865cfd0695e445
Author: HarishFulara07 <harish14143 iiitd ac in>
Date:   Mon Jul 9 20:57:17 2018 +0530

    greeter: search projects functionality

 data/ui/greeter.ui           | 21 +++++++++++++++++++--
 pitivi/greeterperspective.py | 35 ++++++++++++++++++++++++++++++++---
 2 files changed, 51 insertions(+), 5 deletions(-)
---
diff --git a/data/ui/greeter.ui b/data/ui/greeter.ui
index edd05b9b..6acd7259 100644
--- a/data/ui/greeter.ui
+++ b/data/ui/greeter.ui
@@ -9,6 +9,23 @@
     <property name="margin_top">30</property>
     <property name="margin_bottom">10</property>
     <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkSearchEntry" id="search_entry">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="halign">center</property>
+        <property name="margin_bottom">32</property>
+        <property name="width_chars">35</property>
+        <property name="primary_icon_name">edit-find-symbolic</property>
+        <property name="primary_icon_activatable">False</property>
+        <property name="primary_icon_sensitive">False</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
     <child>
       <object class="GtkBox" id="recent_projects_labelbox">
         <property name="name">recent_projects_labelbox</property>
@@ -47,7 +64,7 @@
       <packing>
         <property name="expand">False</property>
         <property name="fill">True</property>
-        <property name="position">0</property>
+        <property name="position">1</property>
       </packing>
     </child>
     <child>
@@ -59,7 +76,7 @@
       <packing>
         <property name="expand">False</property>
         <property name="fill">True</property>
-        <property name="position">1</property>
+        <property name="position">2</property>
       </packing>
     </child>
   </object>
diff --git a/pitivi/greeterperspective.py b/pitivi/greeterperspective.py
index e8469642..e733f74d 100644
--- a/pitivi/greeterperspective.py
+++ b/pitivi/greeterperspective.py
@@ -46,13 +46,13 @@ class ProjectInfoRow(Gtk.ListBoxRow):
     def __init__(self, recent_project_item):
         Gtk.ListBoxRow.__init__(self)
         self.uri = recent_project_item.get_uri()
+        self.name = os.path.splitext(recent_project_item.get_display_name())[0]
 
         builder = Gtk.Builder()
         builder.add_from_file(os.path.join(get_ui_dir(), "project_info.ui"))
         self.add(builder.get_object("project_info_vbox"))
 
-        builder.get_object("project_name_label").set_text(
-            os.path.splitext(recent_project_item.get_display_name())[0])
+        builder.get_object("project_name_label").set_text(self.name)
         builder.get_object("project_uri_label").set_text(
             beautify_project_path(recent_project_item.get_uri_display()))
         builder.get_object("project_last_updated_label").set_text(
@@ -79,6 +79,8 @@ class GreeterPerspective(Perspective):
         self.__topvbox = None
         self.__welcome_vbox = None
         self.__recent_projects_vbox = None
+        self.__search_entry = None
+        self.__recent_projects_labelbox = None
         self.__recent_projects_listbox = None
         self.__project_filter = self.__create_project_filter()
         self.__infobar = None
@@ -94,10 +96,16 @@ class GreeterPerspective(Perspective):
         builder.add_from_file(os.path.join(get_ui_dir(), "greeter.ui"))
 
         self.toplevel_widget = builder.get_object("scrolled_window")
+
         self.__topvbox = builder.get_object("topvbox")
         self.__welcome_vbox = builder.get_object("welcome_vbox")
         self.__recent_projects_vbox = builder.get_object("recent_projects_vbox")
 
+        self.__recent_projects_labelbox = builder.get_object("recent_projects_labelbox")
+
+        self.__search_entry = builder.get_object("search_entry")
+        self.__search_entry.connect("search-changed", self.__search_changed_cb)
+
         self.__recent_projects_listbox = builder.get_object("recent_projects_listbox")
         self.__recent_projects_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
         self.__recent_projects_listbox.connect(
@@ -114,7 +122,13 @@ class GreeterPerspective(Perspective):
 
     def refresh(self):
         """Refreshes the perspective."""
-        self.toplevel_widget.grab_focus()
+        # We are assuming that the users name their projects meaningfully
+        # and are sure of what project they want to search for. Once they
+        # find the project and open it they don't want to come back to the
+        # previous search results. So, we clear out the search entry before
+        # the greeter is shown again.
+        self.__search_entry.set_text("")
+        self.__search_entry.grab_focus()
 
         # Clear the currently displayed list of recent projects.
         for child in self.__recent_projects_listbox.get_children():
@@ -254,3 +268,18 @@ class GreeterPerspective(Perspective):
 
     def __projects_row_activated_cb(self, unused_listbox, row):
         self.app.project_manager.loadProject(row.uri)
+
+    def __search_changed_cb(self, search_entry):
+        search_hit = False
+        search_text = search_entry.get_text().lower()
+        for recent_project_item in self.__recent_projects_listbox.get_children():
+            if search_text in recent_project_item.name.lower():
+                recent_project_item.show()
+                search_hit = True
+            else:
+                recent_project_item.hide()
+
+        if search_hit:
+            self.__recent_projects_labelbox.show()
+        else:
+            self.__recent_projects_labelbox.hide()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]