Making the search a bit more pythonic
[quicknote] / src / libhistory.py
1 #!/usr/bin/env python2.5
2 # -*- coding: utf-8 -*-
3
4 """
5  Copyright (C) 2007 Christoph Würstle
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
10 """
11
12
13 import gtk
14
15
16 try:
17         _
18 except NameError:
19         _ = lambda x: x
20
21
22 class Dialog(gtk.Dialog):
23
24         def __init__(self, daten = None):
25                 super(Dialog, self).__init__(
26                         _("History:"),
27                         None,
28                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
29                         (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT),
30                 )
31                 self.set_position(gtk.WIN_POS_CENTER)
32
33                 self.noteHistory = gtk.ListStore(
34                         int, #pcdatum
35                         str, #datum
36                         str, #sql
37                         str, #param
38                         str #param schön
39                 )
40
41                 # create the TreeView using liststore
42                 self._historyView = gtk.TreeView(self.noteHistory)
43                 self._historyView.set_rules_hint(True)
44                 # create a CellRenderers to render the data
45                 self._timestampCell = gtk.CellRendererText()
46                 self._noteCell = gtk.CellRendererText()
47
48                 # create the TreeViewColumns to display the data
49                 self._timestampColumn = gtk.TreeViewColumn(_('Timestamp'))
50                 self._noteColumn = gtk.TreeViewColumn(_('Note'))
51                 # add columns to treeview
52                 self._historyView.append_column(self._timestampColumn)
53                 self._historyView.append_column(self._noteColumn)
54
55                 # add the cells to the columns - 2 in the first
56                 self._timestampColumn.pack_start(self._timestampCell, True)
57                 self._noteColumn.pack_start(self._noteCell, True)
58                 self._timestampColumn.set_attributes(self._timestampCell, text = 1) #Spalten setzten hier!!!!
59                 self._noteColumn.set_attributes(self._noteCell, text = 4)
60
61                 self._historyView.set_reorderable(False)
62
63                 scrolled_window = gtk.ScrolledWindow()
64                 scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
65                 scrolled_window.add(self._historyView)
66                 self.vbox.pack_start(scrolled_window, expand = True, fill = True, padding = 0)
67
68                 self.noteHistory.clear()
69
70                 if daten is not None:
71                         for data in daten:
72                                 self.noteHistory.append(data)
73
74         def get_selected_row(self):
75                 path = self._historyView.get_cursor()[0]
76                 if path is None or path == "":
77                         return None
78
79                 iter1 = self._historyView.get_model().get_iter(path)
80                 return self._historyView.get_model().get(iter1, 0, 1, 2, 3, 4)