[chronojump] compujump tasks update gui



commit eb3f8e3b79fb76d203a8b8db29aeafdd62092f6b
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jun 28 18:16:52 2017 +0200

    compujump tasks update gui

 glade/dialog_person_popup.glade |   88 +++++++++++++++++++++++----------
 src/gui/dialogPersonPopup.cs    |  102 +++++++++++++++++++++++++++-----------
 src/gui/networks.cs             |   34 +++++++++++++-
 3 files changed, 166 insertions(+), 58 deletions(-)
---
diff --git a/glade/dialog_person_popup.glade b/glade/dialog_person_popup.glade
index 9c26160..197099e 100644
--- a/glade/dialog_person_popup.glade
+++ b/glade/dialog_person_popup.glade
@@ -3,12 +3,11 @@
   <!-- interface-requires gtk+ 3.0 -->
   <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkDialog" id="dialog_person_popup">
-    <property name="width_request">600</property>
+    <property name="width_request">800</property>
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="border_width">10</property>
     <property name="title" translatable="yes">Chronojump</property>
-    <property name="resizable">False</property>
     <property name="modal">True</property>
     <property name="type_hint">dialog</property>
     <signal name="delete_event" handler="on_delete_event" swapped="no"/>
@@ -92,7 +91,7 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkFrame" id="frame2">
+              <widget class="GtkFrame" id="frame_tasks_parametrized">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="label_xalign">0</property>
@@ -111,28 +110,63 @@
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <child>
-                          <widget class="GtkScrolledWindow" id="scrolledwindow5">
-                            <property name="can_focus">True</property>
-                            <property name="hscrollbar_policy">automatic</property>
-                            <property name="vscrollbar_policy">never</property>
+                          <widget class="GtkVBox" id="vbox_tasks_parametrized">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="spacing">10</property>
                             <child>
-                              <widget class="GtkTextView" id="textview_task">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="border_width">2</property>
-                                <property name="editable">False</property>
-                                <property name="cursor_visible">False</property>
-                              </widget>
+                              <placeholder/>
                             </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="position">0</property>
                           </packing>
                         </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label23">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label">Tasques automàtiques</property>
+                    <property name="use_markup">True</property>
+                  </widget>
+                  <packing>
+                    <property name="type">label_item</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkFrame" id="frame_tasks_free">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label_xalign">0</property>
+                <property name="label_yalign">0.69999998807907104</property>
+                <property name="shadow_type">out</property>
+                <child>
+                  <widget class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="top_padding">10</property>
+                    <property name="bottom_padding">10</property>
+                    <property name="left_padding">10</property>
+                    <property name="right_padding">10</property>
+                    <child>
+                      <widget class="GtkVBox" id="vbox2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
                         <child>
-                          <widget class="GtkVBox" id="vbox_tasks">
+                          <widget class="GtkVBox" id="vbox_tasks_free">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="spacing">10</property>
@@ -141,9 +175,9 @@
                             </child>
                           </widget>
                           <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">1</property>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
                           </packing>
                         </child>
                       </widget>
@@ -151,10 +185,10 @@
                   </widget>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="label23">
+                  <widget class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="label">TODO Tasks</property>
+                    <property name="label">Tasques lliures</property>
                     <property name="use_markup">True</property>
                   </widget>
                   <packing>
@@ -163,15 +197,15 @@
                 </child>
               </widget>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">4</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="position">1</property>
           </packing>
         </child>
diff --git a/src/gui/dialogPersonPopup.cs b/src/gui/dialogPersonPopup.cs
index 8685de3..9ae1ea4 100644
--- a/src/gui/dialogPersonPopup.cs
+++ b/src/gui/dialogPersonPopup.cs
@@ -31,11 +31,19 @@ public class DialogPersonPopup
        [Widget] Gtk.Label label_name;
        [Widget] Gtk.Image image;
        [Widget] Gtk.Label label_rfid;
-       [Widget] Gtk.TextView textview_task;
-       [Widget] Gtk.VBox vbox_tasks;
+       [Widget] Gtk.Frame frame_tasks_parametrized;
+       [Widget] Gtk.Frame frame_tasks_free;
+       [Widget] Gtk.VBox vbox_tasks_parametrized;
+       [Widget] Gtk.VBox vbox_tasks_free;
 
        private List<Gtk.CheckButton> list_checks;
+       private List<Gtk.Button> list_buttons;
        private List<int> list_tasks_id;
+       private List<int> list_buttons_id;
+
+       private List<Task> list_tasks;
+       private Task taskActive;
+       public Button Fake_button_start_task;
 
        public DialogPersonPopup (int personID, string name, string rfid, List<Task> tasks)
        {
@@ -49,6 +57,7 @@ public class DialogPersonPopup
                label_name.Text = "<b>" + name + "</b>";
                label_name.UseMarkup = true;
                label_rfid.Text = rfid;
+               list_tasks = tasks;
 
                string photoFile = Util.GetPhotoFileName(false, personID);
                if(File.Exists(photoFile)) {
@@ -65,48 +74,76 @@ public class DialogPersonPopup
                        }
                }
 
-               TextBuffer tb = new TextBuffer (new TextTagTable());
-               tb.Text = "";
-               foreach(Task t in tasks)
-                       tb.Text += t.ToString() + "\n";
-
-               textview_task.Buffer = tb;
-
                list_checks = new List<Gtk.CheckButton>();
+               list_buttons = new List<Gtk.Button>();
                list_tasks_id = new List<int>();
+               list_buttons_id = new List<int>();
+               taskActive = new Task();
+               Fake_button_start_task = new Gtk.Button();
+
+               bool task_parametrized_exist = false;
+               bool task_free_exist = false;
                foreach(Task t in tasks)
                {
-                       CheckButton check = new Gtk.CheckButton(t.ToString());
-                       check.Toggled += on_task_toggled;
-                       check.Active = true;
-                       vbox_tasks.Add(check);
+                       Gtk.Label l = new Gtk.Label(t.ToString());
+                       HBox hbox = new Gtk.HBox(false, 12);
+                       Button button_do;
+
+                       if(t.Type == 'P')
+                       {
+                               button_do = new Gtk.Button("Inicia");
+                               button_do.Clicked += new EventHandler(button_clicked);
+                               hbox.PackStart(button_do, false, false, 0);
+                               hbox.PackStart(l, false, false, 0);
+                               vbox_tasks_parametrized.PackStart(hbox, false, false, 0);
+                               task_parametrized_exist = true;
+                       } else // 'F'
+                       {
+                               button_do = new Gtk.Button("Fet!");
+                               button_do.Clicked += new EventHandler(button_clicked);
+                               hbox.PackStart(l, false, false, 0);
+                               hbox.PackStart(button_do, false, false, 0);
+                               vbox_tasks_free.PackStart(hbox, false, false, 0);
+                               task_free_exist = true;
+                       }
 
-                       list_checks.Add(check);
+                       list_buttons.Add(button_do);
                        list_tasks_id.Add(t.Id);
+                       list_buttons_id.Add(t.Id);
                }
-               vbox_tasks.ShowAll();
+               if(task_parametrized_exist)
+                       vbox_tasks_parametrized.ShowAll();
+               else
+                       frame_tasks_parametrized.Visible = false;
+
+               if(task_free_exist)
+                       vbox_tasks_free.ShowAll();
+               else
+                       frame_tasks_free.Visible = false;
        }
 
-       private void on_task_toggled(object o, EventArgs args)
+       private void button_clicked(object o, EventArgs args)
        {
-               CheckButton checkToggled = o as CheckButton;
+               Button buttonClicked = o as Button;
                if (o == null)
                        return;
 
                int count = 0;
-               foreach(Gtk.CheckButton check in list_checks)
+               foreach(Gtk.Button button in list_buttons)
                {
-                       if(check == checkToggled)
+                       if(button == buttonClicked)
                        {
-                               LogB.Information("check toggled row: " + count.ToString());
-                               LogB.Information(check.Active.ToString());
-
-                               Json json = new Json();
-                               /*
-                                * pass negative check because on this dialog "active" means to do task
-                                * on server the boolean is called "done" and means the opposite
-                                */
-                               json.UpdateTask(list_tasks_id[count], Util.BoolToInt(! check.Active));
+                               LogB.Information("Clicked button" + count.ToString());
+                               if(list_tasks[count].Type == 'P')
+                               {
+                                       taskActive = list_tasks[count];
+                                       Fake_button_start_task.Click();
+                               } else { // 'F'
+                                       Json json = new Json();
+                                       json.UpdateTask(list_tasks_id[count], 1);
+                                       button.Sensitive = false;
+                               }
+                               return;
                        }
                        count ++;
                }
@@ -125,8 +162,13 @@ public class DialogPersonPopup
        //call this if a new person put his rfid code before showing it's data
        public void DestroyDialog ()
        {
-               LogB.Information("Destroying dialogPersonPupopu");
+               LogB.Information("Destroying dialogPersonPopup");
                dialog_person_popup.Destroy ();
-               LogB.Information("Destroyed dialogPersonPupopu");
+               LogB.Information("Destroyed dialogPersonPopup");
+       }
+
+       public Task TaskActive
+       {
+               get { return taskActive; }
        }
 }
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 6612d1c..23475dd 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -90,7 +90,10 @@ public partial class ChronoJumpWindow
                if(
                                configChronojump.Compujump &&
                                configChronojump.CompujumpServerURL != null &&
-                               configChronojump.CompujumpServerURL != "")
+                               configChronojump.CompujumpServerURL != "" &&
+                               configChronojump.CompujumpStationID != -1 &&
+                               configChronojump.CompujumpStationMode != Constants.Menuitem_modes.UNDEFINED
+                               )
                {
                        LogB.Information(configChronojump.Compujump.ToString());
                        LogB.Information(configChronojump.CompujumpServerURL);
@@ -487,6 +490,35 @@ public partial class ChronoJumpWindow
 
                dialogPersonPopup = new DialogPersonPopup(
                                currentPerson.UniqueID, currentPerson.Name, capturedRFID, tasks);
+
+               dialogPersonPopup.Fake_button_start_task.Clicked -= new EventHandler(compujumpTaskStart);
+               dialogPersonPopup.Fake_button_start_task.Clicked += new EventHandler(compujumpTaskStart);
+       }
+
+       private void compujumpTaskStart(object o, EventArgs args)
+       {
+               dialogPersonPopup.Fake_button_start_task.Clicked -= new EventHandler(compujumpTaskStart);
+               Task task = new Task();
+               if(dialogPersonPopup != null)
+               {
+                       task = dialogPersonPopup.TaskActive;
+               }
+               dialogPersonPopup.DestroyDialog();
+               LogB.Information("Selected task from gui/networks.cs:" + task.ToString());
+
+               //laterality
+               if(task.Laterality == "RL")
+                       radio_encoder_laterality_both.Active = true;
+               else if(task.Laterality == "R")
+                       radio_encoder_laterality_r.Active = true;
+               else if(task.Laterality == "L")
+                       radio_encoder_laterality_l.Active = true;
+
+               if(task.Load > 0)
+               {
+                       entry_raspberry_extra_weight.Text = Convert.ToInt32(task.Load).ToString();
+               }
+
        }
 
 


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