Add manifest to manifest
[gpytage.git] / leftpanel.py
blobb5ac9c2dca75625162c332fcd6c64118005bf7d9
1 #!/usr/bin/env python
3 # GPytage leftpanel.py module
5 ############################################################################
6 # Copyright (C) 2008 by Kenneth Prugh #
7 # ken69267@gmail.com #
8 # #
9 # This program is free software; you can redistribute it and#or modify #
10 # it under the terms of the GNU General Public License as published by #
11 # the Free Software Foundation under version 2 of the license. #
12 # #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
17 # #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program; if not, write to the #
20 # Free Software Foundation, Inc., #
21 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
22 ############################################################################
24 import pygtk; pygtk.require("2.0")
25 import gtk
26 import datastore
27 import rightpanel
28 from panelfunctions import switchListView
30 leftview = gtk.TreeView(datastore.datastore) #create the container
32 leftview.set_search_column(0)
33 #columns
34 namecol = gtk.TreeViewColumn('Package File')
35 testcol = gtk.TreeViewColumn('Flags')
36 boolcol = gtk.TreeViewColumn() #editable col
37 filecol = gtk.TreeViewColumn()
38 #add to tree
39 leftview.append_column(namecol)
40 leftview.append_column(testcol)
41 leftview.append_column(boolcol)
42 leftview.append_column(filecol)
44 #render cell
45 cell = gtk.CellRendererText()
46 cell1 = gtk.CellRendererText()
48 #add cols to cell
49 namecol.pack_start(cell, True)
50 namecol.set_attributes(cell, text=0)
51 namecol.add_attribute(cell, "editable", 2)#set row editable
52 namecol.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
54 boolcol.set_visible(False)
55 filecol.set_visible(False)
57 testcol.pack_start(cell1, True)
58 testcol.set_attributes(cell1, text=1)
59 testcol.add_attribute(cell1, "editable", 2)#set row editable
60 testcol.set_expand(True)
61 testcol.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
62 testcol.set_visible(False)
64 ###########Scroll Window#########################
65 scroll = gtk.ScrolledWindow()
66 scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
67 scroll.add_with_viewport(leftview)
69 ############Drag and Drop####################
70 #note: is DND even needed for left panel?
71 leftview.enable_model_drag_dest([('text/plain', 0, 0)], gtk.gdk.ACTION_DEFAULT)
72 import panelfunctions
73 leftview.connect("drag_data_received", panelfunctions.get_dragdestdata)
74 leftview.connect("drag-motion", switchListView)
76 ###########some variables####################
77 last_parent = None
79 def _clicked(treeview, *args):
80 """ Handle treeview clicks """
81 global last_parent
82 model, iter = treeview.get_selection().get_selected()
83 if iter: parent = model.get_value(iter, 3).strip('*')
84 else: parent = last_parent.strip('*')
85 # has the selection really changed?
86 if parent.strip('*') != last_parent:
87 print("LEFTPANEL: parent change detected")
88 list = model.get_value(iter, 0).strip('*')
89 print list
90 print parent
91 if parent.strip('*') == 'package.' + list:
92 rightpanel.setListModel(parent.strip('*'))
93 else:
94 rightpanel.setListModel(list.strip('*'))
95 else: #fixes bug: if two subfiles are selected after each other with same parent
96 list = model.get_value(iter, 0).strip('*')
97 rightpanel.setListModel(list)
98 # save current selection as last selected
99 last_parent = parent.strip('*')
101 #Signals
102 leftview.connect("cursor-changed", _clicked)