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

[tor-commits] [arm/release] Provide a list with add and delete options for LineList confs.



commit df60a8383458a05a66bc94d1b94941e2863a5ae6
Author: Kamran Riaz Khan <krkhan@xxxxxxxxxxxxxx>
Date:   Fri Jul 29 17:09:18 2011 +0500

    Provide a list with add and delete options for LineList confs.
---
 src/gui/configPanel.py |    6 ++++
 src/util/gtkTools.py   |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/src/gui/configPanel.py b/src/gui/configPanel.py
index c5b631a..b87c1b3 100644
--- a/src/gui/configPanel.py
+++ b/src/gui/configPanel.py
@@ -17,6 +17,10 @@ def input_conf_value_size(option):
   prompt = "Enter value for %s" % option
   return gtkTools.input_size(prompt)
 
+def input_conf_value_list(option):
+  prompt = "Enter value for %s" % option
+  return gtkTools.input_list(prompt)
+
 def input_conf_value_text(option):
   prompt = "Enter value for %s" % option
   return gtkTools.input_text(prompt)
@@ -85,6 +89,8 @@ class ConfigPanel(object, CliConfigPanel):
 
     if configType == 'DataSize':
       newValue = input_conf_value_size(configOption)
+    elif configType == 'LineList':
+      newValue = input_conf_value_list(configOption)
     elif configType == 'Boolean':
       newValue = input_conf_value_boolean(configOption)
     else:
diff --git a/src/util/gtkTools.py b/src/util/gtkTools.py
index 860a587..37e818e 100644
--- a/src/util/gtkTools.py
+++ b/src/util/gtkTools.py
@@ -171,6 +171,66 @@ def input_text(prompt):
 
   return text if response == gtk.RESPONSE_OK else None
 
+def input_list(prompt):
+  def on_add_button_clicked(widget, listStore):
+    newValue = input_text("Enter new value:")
+
+    if newValue:
+      row = (newValue,)
+      listStore.append(row)
+
+  def on_delete_button_clicked(widget, treeView):
+    selection = treeView.get_selection()
+    model, selectionIter = selection.get_selected()
+
+    if (selectionIter):
+      model.remove(selectionIter)
+
+  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_start(hBox, False, False, 0)
+
+  addButton = gtk.Button(stock=gtk.STOCK_ADD)
+
+  hBox.pack_start(addButton, False, False, 0)
+
+  deleteButton = gtk.Button(stock=gtk.STOCK_DELETE)
+
+  hBox.pack_start(deleteButton, False, False, 0)
+
+  scrolledWindow = gtk.ScrolledWindow()
+
+  dialog.vbox.pack_end(scrolledWindow, True, True, 0)
+
+  listStore = gtk.ListStore(str)
+  treeView = gtk.TreeView(listStore)
+  treeViewColumn = gtk.TreeViewColumn("Value")
+  cellRenderer = gtk.CellRendererText()
+
+  treeViewColumn.pack_start(cellRenderer, True)
+  treeViewColumn.add_attribute(cellRenderer, 'text', 0)
+  treeView.append_column(treeViewColumn)
+
+  scrolledWindow.add(treeView)
+
+  addButton.connect('clicked', on_add_button_clicked, listStore)
+  deleteButton.connect('clicked', on_delete_button_clicked, treeView)
+
+  dialog.show_all()
+  response = dialog.run()
+
+  dialog.destroy()
+
+  return None if len(listStore) == 0 else " ".join([row[0] for row in listStore])
+
 def input_boolean(prompt):
   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