[chronojump] chronopicRegisterWin shows real data and chan change type on SQL



commit d211b8947d7d604dd7060407757d03f1689a9ca5
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Oct 9 16:06:49 2016 +0200

    chronopicRegisterWin shows real data and chan change type on SQL

 glade/chronojump.glade       |   14 +++
 src/chronopicRegister.cs     |   12 ++-
 src/gui/chronojump.cs        |   15 ++--
 src/gui/chronopicRegister.cs |  196 +++++++++++++++++++++++++++++++-----------
 4 files changed, 179 insertions(+), 58 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 3efc5a0..81effdf 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -1672,6 +1672,20 @@ Carles</property>
                                         <property name="position">2</property>
                                       </packing>
                                     </child>
+                                    <child>
+                                      <widget class="GtkButton" id="button_chronopic_register">
+                                        <property name="label">Chronopic Register</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <signal name="clicked" 
handler="on_button_chronopic_register_clicked" swapped="no"/>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">3</property>
+                                      </packing>
+                                    </child>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
diff --git a/src/chronopicRegister.cs b/src/chronopicRegister.cs
index 1f8a4e3..0b891cf 100644
--- a/src/chronopicRegister.cs
+++ b/src/chronopicRegister.cs
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2016  Xavier de Blas <xaviblas gmail com>
+ * Copyright (C) 2016  Xavier de Blas <xaviblas gmail com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ public class ChronopicRegisterPort
        public string Port;
        public bool FTDI;
        public string SerialNumber;
-       public enum Types { UNKNOWN, NOT_CHRONOPIC, CONTACTS, ENCODER }
+       public enum Types { UNKNOWN, CONTACTS, ENCODER }
        public Types Type;
 
        //constructor when port is known (searching FTDI stuff on a serial port)
@@ -51,6 +51,9 @@ public class ChronopicRegisterPort
                this.FTDI = true;
                this.SerialNumber = serialNumber;
                this.Type = type;
+
+               if(Type == null)
+                       Type = Types.UNKNOWN;
        }
 
        public override string ToString()
@@ -226,6 +229,11 @@ public abstract class ChronopicRegister
        {
                return crp;
        }
+
+       public ChronopicRegisterPortList Crpl
+       {
+               get { return crpl; }
+       }
 }
 
 public class ChronopicRegisterLinux : ChronopicRegister
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index c9fec6b..10c67fe 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -684,12 +684,6 @@ public partial class ChronoJumpWindow
                 */
                pingThread = new Thread (new ThreadStart (pingAtStart));
                pingThread.Start();
-
-               //testing ChronopicRegister
-               ChronopicRegisterSelectOS cros = new ChronopicRegisterSelectOS();
-               ChronopicRegister cr = cros.Do();
-
-               ChronopicRegisterWindow crw = new ChronopicRegisterWindow();
                
                //moveStartTestInitial();
        }
@@ -6793,6 +6787,15 @@ LogB.Debug("X");
                chronopicWizardWin.HideAndNull();
        }
 
+       private void on_button_chronopic_register_clicked (object o, EventArgs args)
+       {
+               //testing ChronopicRegister
+               ChronopicRegisterSelectOS cros = new ChronopicRegisterSelectOS();
+               ChronopicRegister cr = cros.Do();
+
+               ChronopicRegisterWindow crw = new ChronopicRegisterWindow(cr.Crpl.L);
+       }
+
        //start/end auto mode
        private void sensitiveGuiAutoStartEnd (bool start) {
                //if automode, sensitiveGuiEventDoing, sensitiveGuiEventDone don't work
diff --git a/src/gui/chronopicRegister.cs b/src/gui/chronopicRegister.cs
index 3dc1a75..7807d67 100644
--- a/src/gui/chronopicRegister.cs
+++ b/src/gui/chronopicRegister.cs
@@ -19,20 +19,25 @@
  */
 
 using System;
+using System.Collections.Generic; //List<T>
 using Gtk;
 
 public class ChronopicRegisterWindow
 {
        Gtk.Window chronopic_register_win;
+       Gtk.VBox vbox_main;
        Gtk.Table table;
 
-       public ChronopicRegisterWindow() 
+       public ChronopicRegisterWindow(List<ChronopicRegisterPort> list)
        {
                createWindow();
                //put an icon to window
                UtilGtk.IconWindow(chronopic_register_win);
 
-               createTable();
+               createVBoxMain();
+               createTreeView(list);
+               createButton();
+
                chronopic_register_win.ShowAll();
        }
 
@@ -41,66 +46,157 @@ public class ChronopicRegisterWindow
        {
                chronopic_register_win = new Window ("Chronopic register");
 
-               /* Set a handler for delete_event that immediately
-                *                          * exits GTK. */ //TODO: change this
-//             chronopic_register_win.DeleteEvent += delete_event;
+               chronopic_register_win.DeleteEvent += on_delete_event;
 
                /* Sets the border width of the window. */
                chronopic_register_win.BorderWidth= 20;
        }
 
-       private void createTable()
+       private void createVBoxMain()
+       {
+               vbox_main = new Gtk.VBox(false, 20);
+               chronopic_register_win.Add(vbox_main);
+       }
+
+
+       Gtk.TreeView treeview;
+       Gtk.ListStore listStoreTypes;
+       Gtk.ListStore listStoreAll;
+
+       //based on: http://www.mono-project.com/docs/gui/gtksharp/widgets/treeview-tutorial/
+       //and: 
http://stackoverflow.com/questions/12679688/updating-treeview-after-changing-cellrenderercombo-gtk
+       private void createTreeView(List<ChronopicRegisterPort> list)
+       {
+               treeview = new Gtk.TreeView();
+
+               // Create column , cell renderer and add the cell to the 1st column
+               Gtk.TreeViewColumn serialNCol = new Gtk.TreeViewColumn ();
+               serialNCol.Title = "Serial Number";
+               Gtk.CellRendererText serialNCell = new Gtk.CellRendererText ();
+               serialNCol.PackStart (serialNCell, true);
+
+               //--------------------- combo start --------------
+               Gtk.TreeViewColumn typeCol = new Gtk.TreeViewColumn ();
+               typeCol.Title = "Type";
+               Gtk.CellRendererCombo typeCell = new Gtk.CellRendererCombo ();
+               typeCell.Editable = true;
+
+               listStoreTypes = new Gtk.ListStore(typeof (string));
+               int maxChars = 0;
+               foreach(string s in Enum.GetNames(typeof(ChronopicRegisterPort.Types))) {
+                       listStoreTypes.AppendValues (s);
+                       if(s.Length > maxChars)
+                               maxChars = s.Length;
+               }
+
+               typeCell.Model = listStoreTypes;
+               typeCell.WidthChars = maxChars + 10; //enough space to show the dropdown list button
+               typeCell.TextColumn = 0;
+               typeCell.Edited += comboChanged;
+
+               typeCol.PackStart (typeCell, false);
+               //--------------------- combo end --------------
+
+
+               // Create column , cell renderer and add the cell to the 3rd column
+               Gtk.TreeViewColumn portCol = new Gtk.TreeViewColumn ();
+               portCol.Title = "Port";
+               Gtk.CellRendererText portCell = new Gtk.CellRendererText ();
+               portCol.PackStart (portCell, true);
+
+               // Add the columns to the TreeView
+               treeview.AppendColumn (serialNCol);
+               treeview.AppendColumn (typeCol);
+               treeview.AppendColumn (portCol);
+
+               //Tell the Cell Renderers which items in the model to display
+               serialNCol.AddAttribute (serialNCell, "text", 0);
+               typeCol.AddAttribute (typeCell, "text", 1);
+               portCol.AddAttribute (portCell, "text", 2);
+
+               //listStoreAll = new Gtk.ListStore (typeof (string), typeof(Gtk.ComboBox), typeof(string));
+               listStoreAll = new Gtk.ListStore (typeof (string), typeof(string), typeof(string));
+
+               treeview.Model = listStoreAll;
+
+               foreach(ChronopicRegisterPort crp in list)
+                       listStoreAll.AppendValues(crp.SerialNumber, crp.Type.ToString(), crp.Port);
+
+
+               Gtk.Label label = new Gtk.Label("To change values:\nClick on Type and the press Enter");
+
+               Gtk.VBox vboxTV = new Gtk.VBox(false, 8);
+               vboxTV.Add(treeview);
+               vboxTV.Add(label);
+
+               vbox_main.Add(vboxTV);
+       }
+
+       /*
+          void comboChangedOld (object o, EditedArgs args)
+          {
+          TreeSelection selection = treeview.Selection;
+          TreeIter iter;
+          if (!selection.GetSelected (out iter))
+          return;
+
+          listStoreAll.SetValue (iter, 1, args.NewText);
+          }
+          */
+
+       void comboChanged (object o, EditedArgs args)
        {
-               table = new Table (3, 3, true); //rows, columns
+               Gtk.TreeIter iter;
+               listStoreAll.GetIter (out iter, new Gtk.TreePath (args.Path));
 
-               createCells();
+               //update value on treeview
+               listStoreAll.SetValue (iter, 1, args.NewText);
 
-               /* Put the table in the main window */
-               chronopic_register_win.Add(table);
+               //store on SQL
+               string serialNumber = (string) listStoreAll.GetValue (iter, 0);
+               ChronopicRegisterPort.Types type = (ChronopicRegisterPort.Types) Enum.Parse(
+                               typeof(ChronopicRegisterPort.Types), args.NewText);
+               string port = (string) listStoreAll.GetValue (iter, 2);
 
-               table.Show();
+               ChronopicRegisterPort crp = new ChronopicRegisterPort(serialNumber, type);
+               crp.Port = port;
+
+               SqliteChronopicRegister.Update(false, crp, type);
        }
 
-       private void createCells()
+       private void createButton()
        {
-               //headers
-               Label header1 = new Label("<b>SerialNumber</b>");
-               Label header2 = new Label("<b>Type</b>");
-               Label header3 = new Label("<b>Port</b>");
-               header1.UseMarkup = true;
-               header2.UseMarkup = true;
-               header3.UseMarkup = true;
-               table.Attach(header1, 0, 1, 0, 1); //left, right, top, bottom
-               table.Attach(header2, 1, 2, 0, 1);
-               table.Attach(header3, 2, 3, 0, 1);
-               //TODO: negretes
-
-
-               Label serialN1 = new Label("aa00");
-               table.Attach(serialN1, 0, 1, 1, 2);
-
-               Label serialN2 = new Label("aa01");
-               table.Attach(serialN2, 0, 1, 2, 3);
-
-               
-               ComboBox combo1 = ComboBox.NewText ();
-               foreach(string s in Enum.GetNames(typeof(ChronopicRegisterPort.Types)))
-                       combo1.AppendText (s);
-               combo1.Active = 0;
-               table.Attach(combo1, 1, 2, 1, 2);
-
-               ComboBox combo2 = ComboBox.NewText ();
-               foreach(string s in Enum.GetNames(typeof(ChronopicRegisterPort.Types)))
-                       combo2.AppendText (s);
-               combo2.Active = 0;
-               table.Attach(combo2, 1, 2, 2, 3);
-
-
-               Label port1 = new Label("COM1");
-               table.Attach(port1, 2, 3, 1, 2);
-
-               Label port2 = new Label("COM2");
-               table.Attach(port2, 2, 3, 2, 3);
+               Gtk.Button button = new Gtk.Button("Close");
+               button.Clicked += new EventHandler(on_button_clicked);
+               vbox_main.Add(button);
+       }
+
+       private void on_button_clicked(object o, EventArgs args)
+       {
+               /*
+                * TODO:
+                * trying to manage if a combobox is changed but focus is still there. "Edited" is not called.
+                TreeSelection selection = treeview.Selection;
+                TreeIter iter;
+                if (selection.GetSelected (out iter)) {
+                LogB.Information("SOMETHING SELECTED");
+                selection.UnselectIter(iter);
+                }
+                else
+                LogB.Information("NOTHING SELECTED");
+                */
+
+               chronopic_register_win.Hide();
+               chronopic_register_win = null;
+       }
+
+       private void on_delete_event (object o, DeleteEventArgs args)
+       {
+               LogB.Information("calling on_delete_event");
+
+               args.RetVal = true;
+
+               on_button_clicked(new object(), new EventArgs());
        }
 }
 


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