[gevice] add new column 'comments' to model.
- From: Alejandro Valdes Jimenez <avaldes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gevice] add new column 'comments' to model.
- Date: Fri, 28 Dec 2012 15:37:32 +0000 (UTC)
commit 86d947b5ec8ab74ec5d1fd714b9986b434793620
Author: Alejandro ValdÃs Jimenez <avaldes gnome org>
Date: Fri Dec 28 12:32:20 2012 -0300
add new column 'comments' to model.
ChangeLog | 10 ++++++
data/other/db_gevice.sql | 3 +-
data/other/testing.db | Bin 5120 -> 5120 bytes
data/ui/device.xml | 29 ++++++++++++++++-
src/gevice.py | 29 ++++++++++++++----
src/gevicedatabase.py | 15 +++++----
src/gevicedevice.py | 12 ++++++-
src/geviceexport.py | 74 +++++++++++++++++++-------------------------
src/gevicemodel.py | 76 +++++++---------------------------------------
9 files changed, 124 insertions(+), 124 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b3a9733..162efa5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-12-28 Alejandro ValdéJimenez <avaldes gnome org>
+ * data/other/db_gevice.sql: model modified.
+ * data/other/testing.db: update tables.
+ * data/ui/device.xml: add entry-comments
+ * src/gevice.py:
+ * src/gevicedatabase.py:
+ * src/gevicedevice.py:
+ * src/geviceexport.py:
+ * src/gevicemodel.py: add new column 'comments' to model.
+
2012-12-20 Alejandro ValdéJimenez <avaldes gnome org>
* README: add instrctions to install.
diff --git a/data/other/db_gevice.sql b/data/other/db_gevice.sql
index a196286..fb39787 100644
--- a/data/other/db_gevice.sql
+++ b/data/other/db_gevice.sql
@@ -4,7 +4,8 @@
CREATE TABLE device (
id_dev varchar(30) PRIMARY KEY NOT NULL UNIQUE,
- ip_dev varchar(15) DEFAULT '127.0.0.1'
+ ip_dev varchar(15) DEFAULT '127.0.0.1',
+ obs_dev varchar(200) DEFAULT '-'
);
--Table: connect
diff --git a/data/other/testing.db b/data/other/testing.db
index de1de80..df9e157 100644
Binary files a/data/other/testing.db and b/data/other/testing.db differ
diff --git a/data/ui/device.xml b/data/ui/device.xml
index 7e92329..4a23e02 100644
--- a/data/ui/device.xml
+++ b/data/ui/device.xml
@@ -24,10 +24,10 @@
<object class="GtkTable" id="table_data">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="n_rows">2</property>
+ <property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="column_spacing">2</property>
- <property name="row_spacing">2</property>
+ <property name="row_spacing">4</property>
<child>
<object class="GtkEntry" id="entry_ip_device">
<property name="visible">True</property>
@@ -81,6 +81,31 @@
<property name="y_options"/>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Comments</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="entry_comments">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="max_length">200</property>
+ <property name="invisible_char">â</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/gevice.py b/src/gevice.py
index 8ae6c32..e3a9ee1 100755
--- a/src/gevice.py
+++ b/src/gevice.py
@@ -273,7 +273,7 @@ class Gevice:
def insert_data_into_model(self,node,iterp):
for n in node.children:
itern = self.gmodel.treestore.append(iterp)
- self.gmodel.insert_new_item (itern,n.name,n.ip)
+ self.gmodel.insert_new_item (itern,n.name,n.ip,n.com)
self.insert_data_into_model(n,itern)
def on_action_open (self,action):
@@ -296,7 +296,7 @@ class Gevice:
for n in tree.children:
itern = self.gmodel.treestore.append(None)
- self.gmodel.insert_new_item (itern,n.name,n.ip)
+ self.gmodel.insert_new_item (itern,n.name,n.ip,n.com)
self.insert_data_into_model(n, itern)
self.gmodel.treeview.expand_all()
@@ -405,7 +405,7 @@ class Gevice:
result = self.show_infobar_message (self.gdbase.get_error(), Gtk.MessageType.ERROR)
def copy_device_to_dbase (self,model,path,iter,data):
- data = self.gmodel.treestore.get(iter,0,1)
+ data = self.gmodel.treestore.get(iter,0,1,2)
self.gdbase.insert_device (data)
if (self.gdbase.get_status_sql() == False):
@@ -551,9 +551,26 @@ class Gevice:
self.window_main)
def on_action_export (self,action):
- dialogexport = geviceexport.GeviceExport ()
- dialogexport.load_interface (self)
- dialogexport.save_file (self)
+ filechooser = Gtk.FileChooserDialog(title=_("Save file as"),
+ parent=self.window_main,
+ action=Gtk.FileChooserAction.SAVE,
+ buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT))
+
+ filechooser.set_select_multiple(False)
+ response = filechooser.run()
+
+ if response == Gtk.ResponseType.ACCEPT:
+ filename = filechooser.get_filename()
+ if filename:
+ export = geviceexport.GeviceExport(self.gdbase.get_tree(),
+ self.gpref.gsettings.get_string("csvseparator"),filename)
+
+ if (export.get_status()):
+ result = gevice.show_infobar_message (_("Model exported"), Gtk.MessageType.INFO)
+ else:
+ result = gevice.show_infobar_message (_("Can not write to file"), Gtk.MessageType.ERROR)
+
+ filechooser.destroy()
def on_action_find (self,action):
self.gevicefind = gevicefind.GeviceFind ()
diff --git a/src/gevicedatabase.py b/src/gevicedatabase.py
index 8763bc4..f3fa73e 100644
--- a/src/gevicedatabase.py
+++ b/src/gevicedatabase.py
@@ -33,15 +33,18 @@ class Node(object):
Used to store the devices and create the tree of devices. the attributes are:
name = name
ip = ip
+ com = comments
children = []
"""
- def __init__(self, name, ip):
+ def __init__(self, name, ip, com):
"""
@param name The name of device.
@param ip The IP address of device.
+ @param com The comment.
"""
self.name = name
self.ip = ip
+ self.com = com
self.children = []
def add_child(self, obj):
@@ -60,7 +63,7 @@ class GeviceDatabase:
self.__magic = ('\x53', '\x51', '\x4c', '\x69', '\x74', '\x65', '\x20', '\x66', '\x6f', '\x72', '\x6d', '\x61', '\x74', '\x20', '\x33', '\x00')
self.__dbsqlite = dbsqlite
self.__cur = None
- self.__treedevice = Node("root", None)
+ self.__treedevice = Node("root", None, None)
self.__valid_file = False
self.__conn = None
self.__status_sql = False
@@ -194,11 +197,11 @@ class GeviceDatabase:
@param rootnode The root node to which to add the child nodes.
"""
# get data of device
- sql = "select id_dev, ip_dev from device where id_dev='" + str(device) + "'"
+ sql = "select id_dev, ip_dev, obs_dev from device where id_dev='" + str(device) + "'"
row = self.__execute_sql_select(sql)
if row:
- node = Node(row[0][0], row[0][1])
+ node = Node(row[0][0], row[0][1], row[0][2])
rootnode.add_child(node)
# get children of device
@@ -221,8 +224,8 @@ class GeviceDatabase:
Insert data into database.
@param data The [name,ip] as list.
"""
- sql = "insert into device (id_dev,ip_dev) "
- sql = sql + "values ('" + data[0] + "','" + data[1] + "');"
+ sql = "insert into device (id_dev,ip_dev,obs_dev) "
+ sql = sql + "values ('" + data[0] + "','" + data[1] + "','" + data[2] + "');"
self.__execute_sql(sql)
def insert_connections (self,links):
diff --git a/src/gevicedevice.py b/src/gevicedevice.py
index 00e6ec6..41ed533 100644
--- a/src/gevicedevice.py
+++ b/src/gevicedevice.py
@@ -31,16 +31,21 @@ class GeviceDevice:
def add_device (self):
self.action = "add"
+
+ self.entry_name_device.set_sensitive(True)
self.entry_name_device.set_text(_("NoName"))
self.entry_ip_device.set_text("127.0.0.1")
+ self.entry_comments.set_text("-")
self.window_device.set_title (_("New device"))
def modify_device (self,gevice):
self.action = "mod"
data = gevice.gmodel.get_data_of_device_from_model(gevice.gmodel.treeview)
+ self.entry_name_device.set_sensitive(False)
self.entry_name_device.set_text(data[0])
self.entry_ip_device.set_text(data[1])
+ self.entry_comments.set_text(data[2])
self.window_device.set_title (_("Modify device"))
def remove_device (self,gevice):
@@ -63,6 +68,7 @@ class GeviceDevice:
self.window_device = builder.get_object ("window_device")
self.entry_name_device = builder.get_object ("entry_name_device")
self.entry_ip_device = builder.get_object ("entry_ip_device")
+ self.entry_comments = builder.get_object ("entry_comments")
self.button_cancel_device = builder.get_object ("button_cancel_device")
self.button_accept_device = builder.get_object ("button_accept_device")
@@ -83,11 +89,12 @@ class GeviceDevice:
def on_window_device_delete_event (self,window,event):
self.close_window (window)
- def on_button_accept_device_clicked (self,button,gevice):
+ def on_button_accept_device_clicked (self,button,gevice):
alldata = True
name = self.entry_name_device.get_text()
- ip = self.entry_ip_device.get_text()
+ ip = self.entry_ip_device.get_text()
+ com = self.entry_comments.get_text()
if (not name.strip()):
alldata = False
@@ -106,6 +113,7 @@ class GeviceDevice:
gevice.gmodel.treestore.set_value (newiter,0,str(name.strip()))
gevice.gmodel.treestore.set_value (newiter,1,str(ip))
+ gevice.gmodel.treestore.set_value (newiter,2,str(com))
if i["path"]:
gevice.gmodel.treeview.expand_to_path(i["path"][0])
diff --git a/src/geviceexport.py b/src/geviceexport.py
index 348edf7..6929318 100644
--- a/src/geviceexport.py
+++ b/src/geviceexport.py
@@ -17,8 +17,6 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk
-import os
-
import config
import gettext
@@ -28,48 +26,40 @@ gettext.bind_textdomain_codeset (config.PACKAGE, "UTF-8");
from gettext import gettext as _
class GeviceExport:
- def __init__ (self):
- self.endline = "\n"
- self.ext = ".csv"
- self.filename = ""
-
- def load_interface (self,gevice):
- filechooser = Gtk.FileChooserDialog(title=_("Save file as"),
- parent=gevice.window_main,
- action=Gtk.FileChooserAction.SAVE,
- buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT))
-
- filechooser.set_select_multiple(False)
- response = filechooser.run()
-
- if response == Gtk.ResponseType.ACCEPT:
- self.filename = filechooser.get_filename()
-
- filechooser.destroy()
-
- def save_file (self,gevice):
- if self.filename:
- self.filename = self.filename + self.ext
+ def __init__ (self,tree=None,separator="|",filename="gevice",extension=".csv"):
+ self.__extension = extension
+ self.__tree = tree
+ self.__separator = separator
+ self.__endline = "\n"
+ self.__filename = filename + extension
+ self.__status = False
+ self.__FILE = None
+ self.__write_to_file()
- try:
- FILE = open (self.filename,"w")
- if (FILE):
- self.get_all_data_from_dbase (gevice,FILE)
- FILE.close()
- result = gevice.show_infobar_message (_("Model exported"), Gtk.MessageType.INFO)
- except:
- result = gevice.show_infobar_message (_("Can not write to file"), Gtk.MessageType.ERROR)
+ def __write_to_file (self):
+ self.__FILE = open (self.__filename,"w")
+ self.__walking_tree ()
+ self.__FILE.close()
+ self.__status = True
- def get_all_data_from_dbase (self,gevice,FILE):
- sql = "select id_dev, ip_dev from device order by 1;"
+ def __walking_tree(self):
+ for n in self.__tree.children:
+ line = n.name + self.__separator
+ line = line + n.ip + self.__separator
+ line = line + n.com
+ self.__write_line(line)
+ self.__walking_children(n)
- cur = gevice.gdbase.conn.cursor()
- cur.execute(sql)
- rows = cur.fetchall()
+ def __walking_children(self,node):
+ for n in node.children:
+ line = n.name + self.__separator
+ line = line + n.ip + self.__separator
+ line = line + n.com
+ self.__write_line(line)
+ self.__walking_children(n)
- for reg in rows:
- line = ""
- for col in reg:
- line = line + str(col) + gevice.gpref.gsettings.get_string("csvseparator")
+ def __write_line(self,line):
+ self.__FILE.write (line + self.__endline)
- FILE.write (line + self.endline)
+ def get_status(self):
+ return self.__status
diff --git a/src/gevicemodel.py b/src/gevicemodel.py
index b3eb9eb..18fc0f1 100644
--- a/src/gevicemodel.py
+++ b/src/gevicemodel.py
@@ -30,7 +30,7 @@ from gettext import gettext as _
class GeviceModel:
def __init__ (self,gevice):
- self.treestore = Gtk.TreeStore(str,str)
+ self.treestore = Gtk.TreeStore(str,str,str)
self.treeview = Gtk.TreeView (model=self.treestore)
self.treeview.set_rules_hint (True)
@@ -51,15 +51,22 @@ class GeviceModel:
col.pack_start (cell,False)
col.add_attribute (cell,"text",1)
+ col = Gtk.TreeViewColumn (_("Comments"))
+ col.set_resizable (True)
+ self.treeview.append_column (col)
+ cell = Gtk.CellRendererText()
+ col.pack_start (cell,False)
+ col.add_attribute (cell,"text",2)
+
selection = self.treeview.get_selection()
selection.connect ("changed",self.on_device_selection_changed,gevice)
return
- def insert_new_item (self,newiter,name, ip):
+ def insert_new_item (self,newiter,name,ip,com):
self.treestore.set_value (newiter,0,str(name))
self.treestore.set_value (newiter,1,str(ip))
-
+ self.treestore.set_value (newiter,2,str(com))
def on_device_selection_changed (self,selection,gevice):
model,iter = selection.get_selected()
@@ -78,66 +85,5 @@ class GeviceModel:
def get_data_of_device_from_model(self,treeview):
i = self.get_iter_selected (treeview)
- data = i["model"].get(i["iter"],0,1)
+ data = i["model"].get(i["iter"],0,1,2)
return data
-
- def get_model_from_device (self,treestore,path,iter):
- name_model,type = treestore.get(iter,
- config.COLUMN_MODEL,
- config.COLUMN_TYPE)
-
- if int(self.selected) == int(type):
- l_tmp = self.lists_m
-
- it = l_tmp.get_iter_first()
-
- if it:
- exist = False
- while (it):
- tmp = l_tmp.get(it,0)
-
- if tmp[0] == name_model:
- exist = True
- break
- else:
- it = l_tmp.iter_next(it)
-
- if not exist:
- iter = self.lists_m.append ()
- self.lists_m.set (iter,0,name_model)
- else:
- iter = self.lists_m.append ()
- self.lists_m.set (iter,0,name_model)
-
- def get_data_of_device_from_key (self,key,gevice):
- "return data of key"
-
- iter = gevice.list_devices.get_iter_first()
-
- while (iter):
- id = gevice.list_devices.get_value(iter,config.COLUMN_DEVICE)
-
- if str(key) == str(id):
- name_type = gevice.list_devices.get_value(iter,config.COLUMN_NAME_DEVICE)
- pix = gevice.list_devices.get_value(iter,config.COLUMN_PIXBUF)
-
- return name_type, pix
-
- iter = gevice.list_devices.iter_next(iter)
- return None,None
-
- def get_data_of_link_from_key (self,key,gevice):
- links = gevice.gdbase.get_list_of_links (gevice)
- iter = links.get_iter_first()
-
- while (iter):
- id = links.get_value(iter,1)
-
- if str(key) == str(id):
- pix = links.get_value(iter,1)
- name = links.get_value(iter,0)
-
- return pix,name
-
- iter = links.iter_next(iter)
- return None,None
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]