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

[tor-commits] [arm/release] Support TimeInterval confs.



commit 051793007724ebbb2532cd8ac5532e2580cf8fd9
Author: Kamran Riaz Khan <krkhan@xxxxxxxxxxxxxx>
Date:   Sun Jul 31 01:05:17 2011 +0500

    Support TimeInterval confs.
---
 src/gui/configPanel.py |    6 +++++
 src/util/gtkTools.py   |   57 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/src/gui/configPanel.py b/src/gui/configPanel.py
index 8f09f40..1b57341 100644
--- a/src/gui/configPanel.py
+++ b/src/gui/configPanel.py
@@ -26,6 +26,10 @@ def input_conf_value_size(option, oldValue):
   prompt = "Enter value for %s" % option
   return gtkTools.input_size(prompt, oldValue)
 
+def input_conf_value_time(option, oldValue):
+  prompt = "Enter value for %s" % option
+  return gtkTools.input_time(prompt, oldValue)
+
 def input_conf_value_int(option, oldValue):
   prompt = "Enter value for %s" % option
   return gtkTools.input_int(prompt, oldValue)
@@ -127,6 +131,8 @@ class ConfigPanel(object, CliConfigPanel):
 
     if configType == 'DataSize':
       newValue = input_conf_value_size(configOption, oldValue)
+    elif configType == 'TimeInterval':
+      newValue = input_conf_value_time(configOption, oldValue)
     elif configType == 'Integer':
       newValue = input_conf_value_int(configOption, oldValue)
     elif configType == 'String':
diff --git a/src/util/gtkTools.py b/src/util/gtkTools.py
index b7cf082..56a5718 100644
--- a/src/util/gtkTools.py
+++ b/src/util/gtkTools.py
@@ -132,7 +132,6 @@ def input_size(prompt, default=None):
   comboBox.append_text("GB")
   comboBox.append_text("TB")
   comboBox.append_text("PB")
-  comboBox.set_active(0)
 
   hBox.pack_end(comboBox, False, False, 0)
 
@@ -159,6 +158,62 @@ def input_size(prompt, default=None):
 
   return "%d %s" % (value, units) if response == gtk.RESPONSE_OK else None
 
+def input_time(prompt, default=None):
+  dialog = gtk.MessageDialog(None,
+      gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+      gtk.MESSAGE_QUESTION,
+      gtk.BUTTONS_OK_CANCEL,
+      None)
+
+  dialog.set_markup(prompt)
+
+  hBox = gtk.HBox()
+
+  dialog.vbox.pack_end(hBox, True, True, 0)
+
+  spinButton = gtk.SpinButton(None)
+  spinButton.connect('activate', response_to_dialog, dialog, gtk.RESPONSE_OK)
+
+  spinButton.set_increments(1, 10)
+  spinButton.set_range(0, 1024)
+
+  hBox.pack_start(spinButton, True, True, 0)
+
+  comboBox = gtk.combo_box_new_text()
+
+  comboBox.append_text("seconds")
+  comboBox.append_text("minutes")
+  comboBox.append_text("hours")
+  comboBox.append_text("days")
+
+  hBox.pack_end(comboBox, False, False, 0)
+
+  if default:
+    if default[:-1] != 's':
+      default = default + 's'
+
+    value, units = default.split()
+
+    spinButton.set_value(float(value))
+
+    model = comboBox.get_model()
+    modelUnits = [row[0] for row in model]
+    index = modelUnits.index(units)
+    comboBox.set_active(index)
+
+  dialog.show_all()
+  response = dialog.run()
+
+  value = spinButton.get_value_as_int()
+
+  model = comboBox.get_model()
+  active = comboBox.get_active()
+  (units,) = model[active]
+
+  dialog.destroy()
+
+  return "%d %s" % (value, units) if response == gtk.RESPONSE_OK else None
+
 def input_int(prompt, default=None):
   dialog = gtk.MessageDialog(None,
       gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits