[chronojump] Persons top window can "double click", rewritten and much improved



commit 842b2147725245944c27bce8635baf44fe4d51d5
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Feb 10 19:03:09 2018 +0100

    Persons top window can "double click", rewritten and much improved

 glade/person_select_window.glade     |  151 +++++++++--------------
 images/md/ic_select_blue_24dp_2x.png |  Bin 0 -> 1100 bytes
 src/Makefile.am                      |    1 +
 src/gui/personSelect.cs              |  222 +++++++++++++++++++++++++---------
 4 files changed, 221 insertions(+), 153 deletions(-)
---
diff --git a/glade/person_select_window.glade b/glade/person_select_window.glade
index 5b1609a..3bf99c5 100644
--- a/glade/person_select_window.glade
+++ b/glade/person_select_window.glade
@@ -3,7 +3,7 @@
   <!-- interface-requires gtk+ 3.0 -->
   <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkWindow" id="person_select_window">
-    <property name="width_request">800</property>
+    <property name="width_request">820</property>
     <property name="height_request">550</property>
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -2396,6 +2396,18 @@
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -2421,7 +2433,7 @@
                   <widget class="GtkLabel" id="label_selected_person_name">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="ellipsize">end</property>
+                    <property name="wrap">True</property>
                     <property name="width_chars">16</property>
                   </widget>
                   <packing>
@@ -2431,52 +2443,6 @@
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button_select">
-                    <property name="visible">True</property>
-                    <property name="sensitive">False</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <signal name="clicked" handler="on_button_select_clicked" swapped="no"/>
-                    <child>
-                      <widget class="GtkVBox" id="vbox3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="spacing">4</property>
-                        <child>
-                          <widget class="GtkImage" id="image1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="stock">gtk-yes</property>
-                            <property name="icon-size">6</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkLabel" id="label1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="label" translatable="yes">Select</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                      </widget>
-                    </child>
-                  </widget>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
                   <widget class="GtkButton" id="button_edit">
                     <property name="visible">True</property>
                     <property name="sensitive">False</property>
@@ -2519,7 +2485,7 @@
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">2</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
@@ -2642,13 +2608,13 @@
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">3</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
               </widget>
               <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="position">0</property>
               </packing>
             </child>
@@ -2747,59 +2713,58 @@
                     <property name="position">1</property>
                   </packing>
                 </child>
+              </widget>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="button_close">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <signal name="clicked" handler="on_button_cancel_clicked" swapped="no"/>
+                <accelerator key="Escape" signal="clicked"/>
                 <child>
-                  <widget class="GtkButton" id="button_close">
+                  <widget class="GtkVBox" id="vbox7">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <signal name="clicked" handler="on_button_cancel_clicked" swapped="no"/>
-                    <accelerator key="Escape" signal="clicked"/>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">4</property>
                     <child>
-                      <widget class="GtkVBox" id="vbox7">
+                      <widget class="GtkImage" id="image4">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="spacing">4</property>
-                        <child>
-                          <widget class="GtkImage" id="image4">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="stock">gtk-cancel</property>
-                            <property name="icon-size">3</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkLabel" id="label4">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="label" translatable="yes">Cancel</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
+                        <property name="stock">gtk-close</property>
+                        <property name="icon-size">3</property>
                       </widget>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="label4">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Close</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
                     </child>
                   </widget>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="pack_type">end</property>
-                    <property name="position">2</property>
-                  </packing>
                 </child>
               </widget>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="pack_type">end</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </widget>
diff --git a/images/md/ic_select_blue_24dp_2x.png b/images/md/ic_select_blue_24dp_2x.png
new file mode 100644
index 0000000..b755c70
Binary files /dev/null and b/images/md/ic_select_blue_24dp_2x.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
index 28763ef..2ad43a6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -398,6 +398,7 @@ RESOURCES = \
        ../images/md/ic_person_blue_24dp_1x.png,image_person.png \
        ../images/md/ic_person_logout_blue_24dp_1x.png,image_person_logout.png \
        ../images/md/ic_photo_camera_blue_24dp_2x.png,image_no_photo.png \
+       ../images/md/ic_select_blue_24dp_2x.png,image_selected.png \
        ../images/md/ic_cached_blue_24dp_1x.png,image_recalculate.png \
        ../images/md/ic_delete_blue_24dp_1x.png,stock_delete.png \
        ../images/md/ic_create_new_folder_blue_24dp_2x.png,folder_new_big.png \
diff --git a/src/gui/personSelect.cs b/src/gui/personSelect.cs
index 85290d1..5a65451 100644
--- a/src/gui/personSelect.cs
+++ b/src/gui/personSelect.cs
@@ -23,13 +23,13 @@ using Gtk;
 using Gdk;
 using Glade;
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List
 using System.IO; 
 
 public class PersonSelectWindow 
 {
        [Widget] Gtk.Window person_select_window;
        [Widget] Gtk.Table table1;
-       [Widget] Gtk.Button button_select;
        [Widget] Gtk.Button button_edit;
        [Widget] Gtk.Button button_delete;
        [Widget] Gtk.VBox vbox_button_delete_confirm;
@@ -42,6 +42,7 @@ public class PersonSelectWindow
        static PersonSelectWindow PersonSelectWindowBox;
        
        private ArrayList persons;
+       private int selectedFirstClickPersonID; //contains the uniqueID of person selected on first button 
click
        public Person SelectedPerson;
        public Gtk.Button FakeButtonAddPerson;
        public Gtk.Button FakeButtonLoadPerson;
@@ -49,6 +50,8 @@ public class PersonSelectWindow
        public Gtk.Button FakeButtonDeletePerson;
        public Gtk.Button FakeButtonDone;
 
+       private List<PersonPhotoButton> list_ppb;
+
        
        PersonSelectWindow (Gtk.Window parent) {
                Glade.XML gladeXML;
@@ -115,8 +118,10 @@ public class PersonSelectWindow
                
                label_selected_person_name.Text = "";
                SelectedPerson = null;
+               selectedFirstClickPersonID = -1;
                personButtonsSensitive(false);
                vbox_button_delete_confirm.Visible = false;
+               list_ppb = new List<PersonPhotoButton>();
                
                for (int row_i = 0; row_i < rows; row_i ++) {
                        for (int col_i = 0; col_i < cols; col_i ++) 
@@ -126,8 +131,10 @@ public class PersonSelectWindow
                                
                                Person p = (Person) persons[count ++];
 
-                               PersonPhotoButton ppb = new PersonPhotoButton(p);
-                               Gtk.Button b = ppb.CreateButton();
+                               PersonPhotoButton ppb = new PersonPhotoButton(p.UniqueID, p.Name); //creates 
the button
+                               list_ppb.Add(ppb);
+                               Gtk.Button b = ppb.Button;
+
                                b.Show();
                        
                                b.Clicked += new EventHandler(on_button_portrait_clicked);
@@ -150,33 +157,41 @@ public class PersonSelectWindow
 
                //access the button
                Button b = (Button) o;
-       
-               int personID = PersonPhotoButton.GetPersonID(b);
 
-               LogB.Information("UniqueID: " + personID.ToString());
-                               
-               //TODO: now need to process the signal and close
-               foreach(Person p in persons)
-                       if(p.UniqueID == personID) {
-                               SelectedPerson = p;
-                               label_selected_person_name.Text = p.Name;
+               foreach(PersonPhotoButton ppb in list_ppb)
+               {
+                       if(ppb.Button == b)
+                       {
+                               if(ppb.PersonID == selectedFirstClickPersonID)
+                               {
+                                       FakeButtonDone.Click();
+                                       close_window();
+                                       return;
+                               }
+
+                               ppb.Select(true);
 
-                               personButtonsSensitive(true);
+                               foreach(Person p in persons)
+                                       if(p.UniqueID == ppb.PersonID)
+                                       {
+                                               SelectedPerson = p;
+                                               label_selected_person_name.Text = "<b>" + p.Name + "</b>";
+                                               label_selected_person_name.UseMarkup = true;
+                                               personButtonsSensitive(true);
+                                               selectedFirstClickPersonID = p.UniqueID;
+                                       }
                        }
+                       else if(ppb.Selected)
+                               ppb.Select(false);
+               }
        }
        
-       private void personButtonsSensitive(bool sensitive) {
-               button_select.Sensitive = sensitive;
+       private void personButtonsSensitive(bool sensitive)
+       {
                button_edit.Sensitive = sensitive;
                button_delete.Sensitive = sensitive;
        }
        
-       
-       private void on_button_select_clicked (object o, EventArgs args) {
-               FakeButtonDone.Click();
-               close_window();
-       }
-       
        private void on_button_add_clicked (object o, EventArgs args) {
                FakeButtonAddPerson.Click();
        }
@@ -220,7 +235,6 @@ public class PersonSelectWindow
                close_window();
        }
        
-       //TODO: allow to close with ESC
        private void on_delete_event (object o, DeleteEventArgs args)
        {
                PersonSelectWindowBox.person_select_window.Hide();
@@ -231,67 +245,155 @@ public class PersonSelectWindow
 //used by PersonSelectWindow
 public class PersonPhotoButton
 {
-       private Person p;
+       private int personID;
+       private string personName;
+       private Gtk.Button button;
+       public bool Selected;
+
+       //constructors -------------------------------
+
+       /*
+       //undefined
+       public PersonPhotoButton ()
+       {
+               personID = -1;
+               personName = "";
+               button = new Gtk.Button();
+               Selected = false;
+       }
+       */
+
+       //used to create button
+       public PersonPhotoButton (int id, string name)
+       {
+               personID = id;
+               personName = name;
+
+               createButton();
+               Selected = false;
+       }
+
+       //used to get button on clicking
+       public PersonPhotoButton (Gtk.Button button)
+       {
+               this.button = button;
+               assignPersonData();
+       }
+
+       //public methods -------------------------------
+
+       public void Select (bool select)
+       {
+               Array box_elements = getButtonBoxElements(button);
+
+               //image
+               Gtk.Image image = (Gtk.Image) box_elements.GetValue(0); //the image
+
+               if(select)
+                       assignPhotoToPixbuf(image, false, Util.GetImagePath(false) + "image_selected.png");
+               else
+                       addUserPhotoIfExists(image);
+
+               Selected = select;
+       }
+
+
+       //private methods -------------------------------
+
+       private void assignPersonData ()
+       {
+               Array box_elements = getButtonBoxElements(button);
+
+               //access uniqueID
+               Gtk.Label l = (Gtk.Label) box_elements.GetValue(1); //the ID
+               personID = Convert.ToInt32(l.Text);
+               //LogB.Information("UniqueID: " + l.Text.ToString());
 
-       public PersonPhotoButton (Person p) {
-               this.p = p;
+               //access name
+               l = (Gtk.Label) box_elements.GetValue(2); //the name
+               personName = l.Text;
+               //LogB.Information("Name: " + l.Text.ToString());
        }
 
-       public Gtk.Button CreateButton () {
+       private void createButton ()
+       {
                Gtk.VBox vbox = new Gtk.VBox();
 
                Gtk.Image image = new Gtk.Image();
-               string photoFile = Util.UserPhotoURL(true, p.UniqueID);
-               if(photoFile != "" && File.Exists(photoFile)) {
-                       try {
-                               Pixbuf pixbuf = new Pixbuf (photoFile); //from a file
-                               image.Pixbuf = pixbuf;
-                               image.Visible = true;
-                       }
-                       catch {
-                               LogB.Warning("catched while adding photo");
-                       }
-               }
+               addUserPhotoIfExists(image);
+               image.HeightRequest = 150;
+               image.Visible = true;
+
+               Gtk.Label label_select = new Gtk.Label("Select !");
+               label_select.Visible = false; //hide this to the user until button is clicked first time
 
-               Gtk.Label label_id = new Gtk.Label(p.UniqueID.ToString());
+               Gtk.Label label_id = new Gtk.Label(personID.ToString());
                label_id.Visible = false; //hide this to the user
 
-               Gtk.Label label_name = new Gtk.Label(p.Name);
+               Gtk.Label label_name = new Gtk.Label(personName);
                label_name.Visible = true;
 
-               vbox.PackStart(image);
-               vbox.PackStart(label_id);
-               vbox.PackEnd(label_name, false, false, 1);
+               vbox.PackStart(image);                          //0
+               vbox.PackStart(label_id);                       //1
+               vbox.PackEnd(label_name, false, false, 1);      //2
 
                vbox.Show();
 
-               Button b = new Button(vbox);
-               b.WidthRequest=150;
-
-               return b;
+               button = new Button(vbox);
+               button.WidthRequest = 150;
        }
 
-       public static int GetPersonID (Gtk.Button b) 
+       private Array getButtonBoxElements (Gtk.Button b)
        {
                //access the vbox
                Gtk.VBox box = (Gtk.VBox) b.Child;
-               
-               //access the memebers of vbox
-               Array box_elements = box.Children;
-               
-               //access uniqueID       
-               Gtk.Label l = (Gtk.Label) box_elements.GetValue(1); //the ID
-               int personID = Convert.ToInt32(l.Text);
 
-               //LogB.Information("UniqueID: " + l.Text.ToString());
-               
-               //access name
                /*
-               l = (Gtk.Label) box_elements.GetValue(2); //the name
-               LogB.Information("Name: " + l.Text.ToString());
+               LogB.Information("printing children");
+               foreach(Gtk.Widget w in box.Children)
+                       LogB.Information(w.ToString());
                */
 
-               return personID;
+               //access the memebers of vbox
+               return box.Children;
+       }
+
+       private void addUserPhotoIfExists (Gtk.Image image)
+       {
+               string photoFile = Util.UserPhotoURL(true, personID);
+
+               if(photoFile != "" && File.Exists(photoFile))
+                       assignPhotoToPixbuf(image, true, photoFile);
+               else
+                       assignPhotoToPixbuf(image, false, Util.GetImagePath(false) + "image_no_photo.png");
+       }
+
+       private void assignPhotoToPixbuf (Gtk.Image image, bool fromFile, string photoFile)
+       {
+               Pixbuf pixbuf;
+               try {
+                       if(fromFile)
+                               pixbuf = new Pixbuf (photoFile); //from a file
+                       else
+                               pixbuf = new Pixbuf (null, photoFile); //from assemblies
+
+                       image.Pixbuf = pixbuf;
+               }
+               catch {
+                       LogB.Warning("catched while assigning image: " + photoFile);
+               }
+       }
+
+       //------------------ accessors
+
+       public int PersonID
+       {
+               get { return personID; }
+       }
+
+       public Gtk.Button Button
+       {
+               get { return button; }
        }
 }
 


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