[chronojump] encoder curves,signals can delete at genericWin



commit 608ede30c7f3144dfa651d4161f38bea4e74a324
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Apr 1 14:28:13 2013 +0200

    encoder curves,signals can delete at genericWin

 src/gui/encoder.cs       |   48 +++++++++++--
 src/gui/genericWindow.cs |    8 ++
 src/util.cs              |   12 ++++
 src/utilGtk.cs           |  161 +++++++++++++++++++++++++++++-----------------
 4 files changed, 162 insertions(+), 67 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index e109659..cf5a660 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -454,6 +454,7 @@ public partial class ChronoJumpWindow
                genericWin.MarkActiveCurves(checkboxes);
                genericWin.ShowButtonCancel(false);
                genericWin.SetButtonAcceptSensitive(true);
+               genericWin.SetButtonCancelLabel(Catalog.GetString("Close"));
                //manage selected, unselected curves
                genericWin.Button_accept.Clicked += new EventHandler(on_encoder_show_curves_done);
                genericWin.Button_row_edit.Clicked += new EventHandler(on_encoder_show_curves_row_edit);
@@ -510,7 +511,17 @@ public partial class ChronoJumpWindow
        
        protected void on_encoder_show_curves_row_delete (object o, EventArgs args) {
                Log.WriteLine("row delete at show curves");
-               Log.WriteLine(genericWin.TreeviewSelectedUniqueID.ToString());
+
+               int uniqueID = genericWin.TreeviewSelectedUniqueID;
+               Log.WriteLine(uniqueID.ToString());
+
+               EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, uniqueID, 0, 0, "", false)[0];
+               //remove the file
+               bool deletedOk = Util.FileDelete(eSQL.GetFullURL(false));       //don't convertPathToR
+               if(deletedOk)  {
+                       Sqlite.Delete(Constants.EncoderTable, Convert.ToInt32(uniqueID));
+                       updateUserCurvesLabelsAndCombo();
+               }
        }
        
        
@@ -745,6 +756,7 @@ public partial class ChronoJumpWindow
                genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList(), true);
                genericWin.ShowButtonCancel(true);
                genericWin.SetButtonAcceptLabel(Catalog.GetString("Load"));
+               genericWin.SetButtonCancelLabel(Catalog.GetString("Close"));
                genericWin.SetButtonAcceptSensitive(false);
                genericWin.Button_accept.Clicked += new EventHandler(on_encoder_load_signal_accepted);
                genericWin.Button_row_edit.Clicked += new EventHandler(on_encoder_load_signal_row_edit);
@@ -796,7 +808,23 @@ public partial class ChronoJumpWindow
        
        protected void on_encoder_load_signal_row_delete (object o, EventArgs args) {
                Log.WriteLine("row delete at load signal");
-               Log.WriteLine(genericWin.TreeviewSelectedUniqueID.ToString());
+
+               int uniqueID = genericWin.TreeviewSelectedUniqueID;
+               Log.WriteLine(uniqueID.ToString());
+
+               //if it's current signal use the delete signal from the gui interface that updates gui
+               if(uniqueID == Convert.ToInt32(encoderSignalUniqueID))
+                       on_button_encoder_delete_signal_accepted (o, args);
+               else {
+                       EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, uniqueID, 0, 0, "", 
false)[0];
+                       //remove the file
+                       bool deletedOk = Util.FileDelete(eSQL.GetFullURL(false));       //don't convertPathToR
+                       if(deletedOk)  
+                               Sqlite.Delete(Constants.EncoderTable, Convert.ToInt32(uniqueID));
+
+                       //genericWin selected row is deleted, unsensitive the "load" button
+                       genericWin.SetButtonAcceptSensitive(false);
+               }
        }
        
        void on_button_encoder_export_all_curves_clicked (object o, EventArgs args) 
@@ -980,12 +1008,7 @@ public partial class ChronoJumpWindow
                                        if(ecconLast == "c" || ! Util.IsEven(i)) //use only uneven (spanish: 
"impar") values
                                                encoder_pulsebar_capture.Text = 
encoderSaveSignalOrCurve("allCurves", i);
 
-                       ArrayList data = SqliteEncoder.Select(
-                                       false, -1, currentPerson.UniqueID, currentSession.UniqueID, "curve", 
false);
-                       int activeCurvesNum = getActiveCurvesNum(data);
-                       label_encoder_user_curves_active_num.Text = activeCurvesNum.ToString();
-                       label_encoder_user_curves_all_num.Text = data.Count.ToString();
-                       updateComboEncoderAnalyzeCurveNum(data, activeCurvesNum);       
+                       updateUserCurvesLabelsAndCombo();
                }
        }
 
@@ -997,6 +1020,15 @@ public partial class ChronoJumpWindow
                
                return countActiveCurves;
        }
+
+       private void updateUserCurvesLabelsAndCombo() {
+               ArrayList data = SqliteEncoder.Select(
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, "curve", false);
+               int activeCurvesNum = getActiveCurvesNum(data);
+               label_encoder_user_curves_active_num.Text = activeCurvesNum.ToString();
+               label_encoder_user_curves_all_num.Text = data.Count.ToString();
+               updateComboEncoderAnalyzeCurveNum(data, activeCurvesNum);       
+       }
        
        private string [] getActiveCheckboxesList(string [] checkboxes, int activeCurvesNum) {
                if(activeCurvesNum == 0)
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index 3d59a9d..325645e 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -535,6 +535,10 @@ Log.WriteLine((string) store.GetValue (iter, 3));
        }
 
        private void on_delete_selected_clicked (object o, EventArgs args) {
+               //remove selected row from treeview
+               store = UtilGtk.RemoveRow(treeview, store);
+
+               //activate button to manage on gui/encoder.cs in order to delete from SQL
                button_row_delete.Click();
        }
 
@@ -547,6 +551,10 @@ Log.WriteLine((string) store.GetValue (iter, 3));
                button_accept.Sensitive=show;
        }
        
+       public void SetButtonCancelLabel(string str) {
+               button_cancel.Label=str;
+       }
+       
        public void ShowButtonCancel(bool show) {
                button_cancel.Visible = show;
        }
diff --git a/src/util.cs b/src/util.cs
index 0e76cad..343356e 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -465,6 +465,18 @@ public class Util
                                final[count++] = str;
                return final;
        }
+
+       public static string [] DeleteStringAtPosition(string [] initial, int pos) {
+               string [] final = new String [initial.Length -1];
+               int count = 0;
+               foreach(string str in initial) {
+                       if(count != pos)
+                               final[count] = str;
+                       count ++;
+               }
+
+               return final;
+       }
        
        
        //called from jumpRj.Write() and from interval
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 1abfecd..15c732b 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -27,59 +27,13 @@ using Gdk;
 //only Gtk related methods (not used bu the server) this is the differnece with Util
 public class UtilGtk
 {
-       /* howto find nice colors
-        * open R
-        * > colors()
-        * if you like lightblue2 and red2 then:
-        * > col2rgb(colors()[401])
-        * > col2rgb(colors()[554])
-        */
-       public static Gdk.Color WHITE = new Gdk.Color(0xff,0xff,0xff);
-       public static Gdk.Color BLACK = new Gdk.Color(0x00,0x00,0x00);
-       public static Gdk.Color BLUE = new Gdk.Color(0x6c,0x77,0xab);
-       public static Gdk.Color BLUE_CLEAR = new Gdk.Color(0xa0,0xa7,0xca);
-       
-       public static Gdk.Color RED_PLOTS = new Gdk.Color(238,0,0);
-       public static Gdk.Color LIGHT_BLUE_PLOTS = new Gdk.Color(178,223,238);
-       public static Gdk.Color BLUE_PLOTS = new Gdk.Color(0,0,238);
-       
-       public static void ResizeIfNeeded(Gtk.Window win) {
-               int winX, winY;
-               win.GetSize(out winX, out winY);
-               int maxY = ScreenHeightFitted(true);
-               if(winY > maxY)
-                       win.Resize(winX, maxY);
-       }
 
-       //(takes care)? of menu bar
-       public static int ScreenHeightFitted(bool fit) {
-               if(fit)
-                       return ScreenHeight() -25;
-               else
-                       return ScreenHeight();
-       }
-       
-       private static int ScreenHeight() {
-               //libmono-cairo2.0-cil
-               return Gdk.Display.Default.GetScreen(0).Height;
-       }
-       
-       public static int WidgetWidth(Gtk.Widget w) {
-               return w.Allocation.Width;
-       }
-       public static int WidgetHeight(Gtk.Widget w) {
-               return w.Allocation.Height;
-       }
+       /*
+        *
+        * COMBO
+        *
+        */
 
-       public static void IconWindow(Gtk.Window myWindow) {
-               Gdk.Pixbuf chronojumpIcon = new Gdk.Pixbuf (null, Constants.FileNameIcon);
-               myWindow.Icon = chronojumpIcon;
-       }
-
-       public static void IconWindowGraph(Gtk.Window myWindow) {
-               Gdk.Pixbuf chronojumpIcon = new Gdk.Pixbuf (null, Constants.FileNameIconGraph);
-               myWindow.Icon = chronojumpIcon;
-       }
 
        public static string ComboGetActive(ComboBox myCombo) {
                TreeIter iter;
@@ -184,6 +138,20 @@ public class UtilGtk
                myCombo.AppendText (myData);
        }
 
+       public static void ComboPackShowAndSensitive (Gtk.Box box, Gtk.ComboBox combo) {
+               box.PackStart(combo, true, true, 0);
+               box.ShowAll();
+               combo.Sensitive = true;
+       }
+       
+
+       /*
+        *
+        * TREEVIEW
+        *
+        */
+
+
        public static void CreateCols (Gtk.TreeView tv, Gtk.TreeStore store, 
                        string name, int verticalPos, bool visible) {
                Gtk.TreeViewColumn myCol = new Gtk.TreeViewColumn (name, new CellRendererText(), "text", 
verticalPos);
@@ -230,12 +198,40 @@ public class UtilGtk
                
                return (val1-val2);
        }
+       
+       public static Gtk.TreeStore RemoveRow (Gtk.TreeView tv, Gtk.TreeStore store) {
+               TreeModel model;
+               TreeIter iter1;
 
-       public static void ComboPackShowAndSensitive (Gtk.Box box, Gtk.ComboBox combo) {
-               box.PackStart(combo, true, true, 0);
-               box.ShowAll();
-               combo.Sensitive = true;
+               if (tv.Selection.GetSelected (out model, out iter1)) {
+                       store.Remove(ref iter1);
+               }
+               return store;
        }
+
+
+
+       /*
+        *
+        * COLORS
+        *
+        */
+
+       /* howto find nice colors
+        * open R
+        * > colors()
+        * if you like lightblue2 and red2 then:
+        * > col2rgb(colors()[401])
+        * > col2rgb(colors()[554])
+        */
+       public static Gdk.Color WHITE = new Gdk.Color(0xff,0xff,0xff);
+       public static Gdk.Color BLACK = new Gdk.Color(0x00,0x00,0x00);
+       public static Gdk.Color BLUE = new Gdk.Color(0x6c,0x77,0xab);
+       public static Gdk.Color BLUE_CLEAR = new Gdk.Color(0xa0,0xa7,0xca);
+       
+       public static Gdk.Color RED_PLOTS = new Gdk.Color(238,0,0);
+       public static Gdk.Color LIGHT_BLUE_PLOTS = new Gdk.Color(178,223,238);
+       public static Gdk.Color BLUE_PLOTS = new Gdk.Color(0,0,238);
        
 
        public static void ColorsMenuLabel(Gtk.Label l) {
@@ -286,6 +282,50 @@ public class UtilGtk
                }
        }
 
+       /*
+        *
+        * PRETTY THINGS
+        *
+        */
+
+       public static void ResizeIfNeeded(Gtk.Window win) {
+               int winX, winY;
+               win.GetSize(out winX, out winY);
+               int maxY = ScreenHeightFitted(true);
+               if(winY > maxY)
+                       win.Resize(winX, maxY);
+       }
+
+       //(takes care)? of menu bar
+       public static int ScreenHeightFitted(bool fit) {
+               if(fit)
+                       return ScreenHeight() -25;
+               else
+                       return ScreenHeight();
+       }
+       
+       private static int ScreenHeight() {
+               //libmono-cairo2.0-cil
+               return Gdk.Display.Default.GetScreen(0).Height;
+       }
+       
+       public static int WidgetWidth(Gtk.Widget w) {
+               return w.Allocation.Width;
+       }
+       public static int WidgetHeight(Gtk.Widget w) {
+               return w.Allocation.Height;
+       }
+
+       public static void IconWindow(Gtk.Window myWindow) {
+               Gdk.Pixbuf chronojumpIcon = new Gdk.Pixbuf (null, Constants.FileNameIcon);
+               myWindow.Icon = chronojumpIcon;
+       }
+
+       public static void IconWindowGraph(Gtk.Window myWindow) {
+               Gdk.Pixbuf chronojumpIcon = new Gdk.Pixbuf (null, Constants.FileNameIconGraph);
+               myWindow.Icon = chronojumpIcon;
+       }
+
 
        
        public static TextBuffer TextViewPrint(string message) {
@@ -325,7 +365,13 @@ public class UtilGtk
                l.TooltipText = Util.RemoveMarkup(s);
        }
 
-       // -- drawingarea stuff
+
+       /*
+        *
+        * DRAWINGAREA
+        *
+        */
+
        
        public static void ErasePaint(Gtk.DrawingArea da, Gdk.Pixmap px) {
                px.DrawRectangle (da.Style.WhiteGC, true, 0, 0, da.Allocation.Width, da.Allocation.Height);
@@ -343,7 +389,4 @@ public class UtilGtk
        
 
 
-
-
-       // -- end of drawingarea stuff
 }


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