2 # -*- coding: utf-8 -*-
8 import libliststorehandler
11 class Columns_dialog(gtk.VBox):
13 def is_col_selected(self, icol):
14 children=self.framebox.get_children()
15 if icol<len(children):
16 return children[icol].get_active()
20 def save_column_setting(self):
21 i=1 #uid can not be shown
22 while self.liststorehandler.get_colname(i)!=None:
23 name=str(self.liststorehandler.get_colname(i))
24 if self.is_col_selected(i-1)==True:
25 self.db.speichereDirekt("showcol_"+name,"1")
27 self.db.speichereDirekt("showcol_"+name,"0")
33 def __init__(self,db,liststorehandler):
34 gtk.VBox.__init__(self,homogeneous=False, spacing=0)
37 self.liststorehandler=liststorehandler
39 #serverbutton=gtk.ToggleButton("SyncServer starten")
40 #serverbutton.connect("clicked",self.startServer,(None,))
41 #self.pack_start(serverbutton, expand=False, fill=True, padding=1)
44 frame=gtk.Frame("Columns")
45 self.framebox=gtk.VBox(homogeneous=False, spacing=0)
47 self.scrolled_window = gtk.ScrolledWindow()
48 self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
50 self.scrolled_window.add_with_viewport(self.framebox)
53 i=1 #uid can not be shown
54 while self.liststorehandler.get_colname(i)!=None:
55 name=str(self.liststorehandler.get_colname(i))
56 checkbutton=gtk.CheckButton(name)
57 if self.db.ladeDirekt("showcol_"+name)=="1":
58 checkbutton.set_active(True)
60 self.framebox.pack_start(checkbutton)
63 frame.add(self.scrolled_window)
64 self.pack_start(frame, expand=True, fill=True, padding=1)
71 class CellRendererTriple(gtk.GenericCellRenderer):
73 "status": (gobject.TYPE_STRING, "Status",
74 "Status", "", gobject.PARAM_READWRITE),
78 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_STRING)),
83 #self.__gobject_init__()
84 #gtk.GenericCellRenderer.__init__(self,*args,**kwargs)
85 gtk.GenericCellRenderer.__init__(self)
86 #self.__gobject_init__()
90 self.mode = gtk.CELL_RENDERER_MODE_ACTIVATABLE
91 self.xpad = -2; self.ypad = -2
92 self.xalign = 0.5; self.yalign = 0.5
96 self.connect('editing-started', self.on_clicked)
98 def do_set_property(self,property,value):
99 setattr(self, property.name, value)
101 def do_get_property(self, property):
102 return getattr(self, property.name)
104 def get_layout(self, widget):
105 '''Gets the Pango layout used in the cell in a TreeView widget.'''
107 layout = pango.Layout(widget.get_pango_context())
108 layout.set_width(-1) # Do not wrap text.
114 def on_get_size(self, widget, cell_area=None):
121 layout = self.get_layout(widget)
122 width, height = layout.get_pixel_size()
129 x_offset = xalign * (cell_area.width - width)
130 x_offset = max(x_offset, xpad)
131 x_offset = int(round(x_offset, 0))
133 y_offset = yalign * (cell_area.height - height)
134 y_offset = max(y_offset, ypad)
135 y_offset = int(round(y_offset, 0))
137 width = width + (xpad * 2)
138 height = height + (ypad * 2)
141 return x_offset, y_offset, width, height
143 def on_clicked(self, widget, data):
146 def clicked(self, widget, data1=None):
147 x,y=widget.get_pointer()
150 path=widget.get_path_at_pos(x,y)
152 #print "a",widget.get_cursor()
157 path=widget.get_cursor()[0]
160 irow=path[0] #path[0][0]-1
161 rect=widget.get_cell_area(irow, widget.get_column(0)) #FixME 0 is hardcoded
162 if x<rect.x+rect.width:
163 self.emit("status_changed",irow,self.status)
168 #workarround -1 means last item, because bug in treeview?!
170 rect=widget.get_visible_rect() #widget.get_cell_area(-1, widget.get_column(0))
171 #print rect.x,rect.y,rect.width,rect.height,x,y
173 rect=widget.get_cell_area(0, widget.get_column(0)) #FixME 0 is hardcoded
174 if x<rect.x+rect.width:
175 self.emit("status_changed",irow,"-1")
178 def on_render(self, window, widget, background_area, cell_area, expose_area, flags ):
179 if (self.widget==None):
182 self.widget.connect("cursor-changed",self.clicked) #button-press-event
184 self.last_cell=cell_area
186 x=int(cell_area.x+(cell_area.width-2)/2-(cell_area.height-2)/2)
188 height=int(cell_area.height-2)
191 if (self.status=="1"):
192 widget.style.paint_check(window,gtk.STATE_NORMAL, gtk.SHADOW_IN,cell_area, widget, "cellradio",x,y,width,height)
193 elif (self.status=="0"):
198 widget.style.paint_flat_box(window, gtk.STATE_NORMAL, gtk.SHADOW_NONE, cell_area, widget, "cellunselected",x,y,width,height)
200 widget.style.paint_hline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",x,x+width,y)
201 widget.style.paint_hline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",x,x+width,y+height)
202 widget.style.paint_vline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",y,y+height,x)
203 widget.style.paint_vline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",y,y+height,x+width)
206 widget.style.paint_diamond(window, gtk.STATE_NORMAL, gtk.SHADOW_IN, cell_area, widget, "cellunselected",x,y,width,height)
212 def on_start_editing(self, event, widget, path, background_area, cell_area, flags):
213 print "on_start_editing",path
217 def on_activate(self, event, widget, path, background_area, cell_area, flags):
218 print "activate",path
223 class CellRendererCombo2(gtk.GenericCellRenderer):
225 "text": (gobject.TYPE_STRING, "text",
226 "Text", "", gobject.PARAM_READWRITE),
230 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_STRING)),
235 #self.__gobject_init__()
236 #gtk.GenericCellRenderer.__init__(self,*args,**kwargs)
237 gtk.GenericCellRenderer.__init__(self)
238 #self.__gobject_init__()
242 self.mode = gtk.CELL_RENDERER_MODE_ACTIVATABLE
243 self.xpad = -2; self.ypad = -2
244 self.xalign = 0.5; self.yalign = 0.5
249 self.connect('editing-started', self.on_clicked)
251 def do_set_property(self,property,value):
252 #print property,value
253 setattr(self, property.name, value)
255 def do_get_property(self, property):
256 return getattr(self, property.name)
258 def get_layout(self, widget):
259 '''Gets the Pango layout used in the cell in a TreeView widget.'''
261 layout = pango.Layout(widget.get_pango_context())
262 layout.set_width(-1) # Do not wrap text.
264 layout.set_text(self.text)
268 def on_get_size(self, widget, cell_area=None):
275 layout = self.get_layout(widget)
276 width, height = layout.get_pixel_size()
283 x_offset = xalign * (cell_area.width - width)
284 x_offset = max(x_offset, xpad)
285 x_offset = int(round(x_offset, 0))
287 y_offset = yalign * (cell_area.height - height)
288 y_offset = max(y_offset, ypad)
289 y_offset = int(round(y_offset, 0))
291 width = width + (xpad * 2)
292 height = height + (ypad * 2)
295 return x_offset, y_offset, width, height
297 def on_clicked(self, widget, data):
300 def clicked(self, widget, data1=None):
302 x,y=widget.get_pointer()
305 #path=widget.get_path_at_pos(x,y)
307 path=widget.get_cursor()[0]
310 irow=path[0] #path[0][0]-1
311 rect=widget.get_cell_area(irow, widget.get_column(0)) #FixME 0 is hardcoded
312 if x<rect.x+rect.width:
313 self.emit("status_changed",irow,self.status)
318 #workarround -1 means last item, because bug in treeview?!
320 rect=widget.get_visible_rect() #widget.get_cell_area(-1, widget.get_column(0))
321 #print rect.x,rect.y,rect.width,rect.height,x,y
323 rect=widget.get_cell_area(0, widget.get_column(0)) #FixME 0 is hardcoded
324 if x<rect.x+rect.width:
325 self.emit("status_changed",irow,"-1")
328 def on_render(self, window, widget, background_area, cell_area, expose_area, flags ):
329 if (self.widget==None):
331 self.widget.connect("cursor-changed",self.clicked) #button-press-event
333 self.last_cell=cell_area
335 x=int(cell_area.x+(cell_area.width-2)/2-(cell_area.height-2)/2)
337 height=int(cell_area.height-2)
340 widget.style.paint_layout(window,gtk.STATE_NORMAL, True, cell_area, widget, "cellradio",x,y,self.get_layout(widget))
344 def on_start_editing(self, event, widget, path, background_area, cell_area, flags):
345 print "on_start_editing",path
349 def on_activate(self, event, widget, path, background_area, cell_area, flags):
350 print "activate",path
354 gobject.type_register(CellRendererCombo2)
355 gobject.type_register(CellRendererTriple)
359 class View(gtk.VBox):
362 ls=self.liststorehandler.get_liststore()
363 self.treeview.set_model(ls)
364 #self.tvcolumn[i].add_attribute( self.cell[i], "active", 1)
370 def col_edited(self,cell, irow, new_text,icol=None):
372 self.liststorehandler.update_row(irow,icol,new_text)
374 print cell, irow, new_text,icol
376 def col_toggled(self,widget,irow, status ):
377 #print irow,ls[irow][1],status
378 ls=self.treeview.get_model()
380 if self.liststorehandler.selection.get_status()=="0":
382 self.liststorehandler.update_row(irow,1,"1")
384 self.liststorehandler.update_row(irow,1,"0")
387 self.liststorehandler.update_row(irow,1,"-1")
388 elif ls[irow][1]=="0":
389 self.liststorehandler.update_row(irow,1,"1")
391 self.liststorehandler.update_row(irow,1,"0")
393 #self.tvcolumn[i].set_attributes( self.cell[i], active=i)
405 def del_active_row(self):
406 path, col = self.treeview.get_cursor()
410 row_iter=self.treeview.get_model().get_iter(path)
411 self.liststorehandler.del_row(irow,row_iter)
414 #treemodel.get_iter()
418 def sort_func_function(self,model, iter1, iter2, data=None):
422 def reload_view(self):
423 # create the TreeView using liststore
424 self.modelsort = gtk.TreeModelSort(self.liststorehandler.get_liststore())
425 self.modelsort.set_sort_column_id(2, gtk.SORT_ASCENDING)
427 self.treeview = gtk.TreeView(self.modelsort)
428 self.treeview.set_headers_visible(True)
431 self.cell=range(self.liststorehandler.get_colcount())
432 self.tvcolumn=range(self.liststorehandler.get_colcount())
435 m = self.liststorehandler.get_unitsstore()
437 for i in range(self.liststorehandler.get_colcount()):
443 if self.db.ladeDirekt("showcol_"+str(self.liststorehandler.get_colname(i)),default)=="1":
446 self.cell[i] = CellRendererTriple()
447 self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i),self.cell[i])
448 self.cell[i].connect( 'status_changed', self.col_toggled)
449 self.tvcolumn[i].set_attributes( self.cell[i], status=i)
451 elif (i==3)or(i==4)or(i==6):
452 self.cell[i] = gtk.CellRendererCombo()
453 self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i),self.cell[i])
454 self.cell[i].set_property("model",m)
455 self.cell[i].set_property('text-column', i)
456 self.cell[i].set_property('editable',True)
457 self.cell[i].connect("edited", self.col_edited,i)
458 self.tvcolumn[i].set_attributes( self.cell[i], text=i)
460 self.cell[i] = gtk.CellRendererText()
461 self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i),self.cell[i])
462 self.cell[i].set_property('editable',True)
463 self.cell[i].set_property('editable-set',True)
464 self.cell[i].connect("edited", self.col_edited,i)
465 #self.cell[i].connect("editing-canceled", self.col_edited2,i)
466 self.tvcolumn[i].set_attributes(self.cell[i], text=i)
468 self.cell[i].set_property('cell-background', 'lightgray')
469 self.tvcolumn[i].set_sort_column_id(i)
470 self.tvcolumn[i].set_resizable(True)
474 self.treeview.append_column(self.tvcolumn[i])
477 # Allow NOT drag and drop reordering of rows
478 self.treeview.set_reorderable(False)
481 if self.scrolled_window != None:
482 self.scrolled_window.destroy()
484 self.scrolled_window = gtk.ScrolledWindow()
485 self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
487 self.scrolled_window.add(self.treeview)
488 self.pack_start(self.scrolled_window, expand=True, fill=True, padding=0)
493 def __init__(self,db,liststorehandler,parent_window):
496 self.parent_window=parent_window
497 self.liststorehandler = liststorehandler
500 gtk.VBox.__init__(self,homogeneous=False, spacing=0)
502 logging.info("libview, init")
504 self.scrolled_window = None
512 bearbeitenFrame=gtk.Frame("Verteilung kopieren nach")
513 bearbeitenvBox=gtk.VBox(homogeneous=False, spacing=0)
515 bearbeitenhBox=gtk.HBox(homogeneous=False, spacing=0)
516 self.comboKlassen = gtk.combo_box_new_text()
517 bearbeitenhBox.pack_start(self.comboKlassen, expand=False, fill=True, padding=0)
518 button=gtk.Button("Kopieren")
519 button.connect("clicked", self.kopiereStoffverteilung, None)
520 bearbeitenhBox.pack_start(button, expand=False, fill=True, padding=0)
523 bearbeitenhBox.pack_start(label, expand=False, fill=True, padding=0)
525 button=gtk.Button("Export in CSV-Datei")
526 button.connect("clicked", self.exportStoffverteilung, None)
527 bearbeitenhBox.pack_start(button, expand=False, fill=True, padding=0)
529 bearbeitenvBox.pack_start(bearbeitenhBox, expand=False, fill=True, padding=0)
532 bearbeitenFrame.add(bearbeitenvBox)
533 self.pack_start(bearbeitenFrame, expand=False, fill=True, padding=0)
536 #self.connect("unmap", self.speichere)
537 #self.connect("map", self.ladeWirklich)
543 #print "libstoffverteilung 9: ",time.clock()