๐Ÿ“ฆ wasuaje / test_payroll_gtk

๐Ÿ“„ tree.py ยท 333 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333#!/usr/bin/env python
#coding=utf-8
# -*- coding: utf-8 -*-

# PyTPV, software point of sale for restaurant, bar and pizzeria.
# Copyright (C) 2007 Juan Jose Rojo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Can you contact with author by means of email: <jjrojoc@gmail.com> or the
# next postal address:
# Juan Jose Rojo. San Lazaro, 13. 30840 Alhama de Murcia. Murcia. Spain
# This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
# This is free software, and you are welcome to redistribute it
# under certain conditions; type `show c' for details.

import gtk
import pango
#import gobject
#import pango

class TreeView(gtk.TreeView):
    def __init__(self):
        """
        This class is an intermediate class for construct
        the store and views of the treeviews, also contain
        the methods for add, addlist, del, getCount of all 
        treeviews
        """
        gtk.TreeView.__init__(self)  
        self.get_selection().set_mode(gtk.SELECTION_SINGLE)
        self.set_rules_hint(True)
#        self.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_VERTICAL)
        
    def _new_column(self,name,size,visible,sort,width,height,renderer,columna):
        if renderer == 'cell':
            cell = gtk.CellRendererText()
            col = gtk.TreeViewColumn(name, cell, text=columna)
#            font = pango.FontDescription('9')
#            cell.set_property('font-desc', font)
        elif renderer == 'pixbuf':
            cell = gtk.CellRendererPixbuf()        
            col = gtk.TreeViewColumn(name, cell, stock_id=columna)
        col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        col.set_fixed_width(size)
        col.set_resizable(True)
        col.set_visible(visible)
        col.set_sort_column_id(sort)
        col.set_alignment(0.5)
        
        
        cell.set_fixed_size(width, height)
        #col.pack_start(cell,True)
        #col.set_cell_data_func(cell, None)
        return col
    
    
    def update(self, iter, column, newtext):
        selection = self.get_selection() 
        model, iter = selection.get_selected()
        self.liststore.set_value(iter, column, newtext)
        
        
    def add(self, value):
        return self.liststore.append(value)
       
    
    def prepend(self, value):
        return self.liststore.prepend(value)
#        iter = self.liststore.append(value)
#
#        # select new row and start editing it
#        path = self.liststore.get_path(iter)
#        self.get_selection().select_path(path)
#        
#        self.scroll_to_cell(path)
#        self.get_selection().select_path(path)
    
    
    def insert(self, count, value):
        return self.liststore.insert(count, value)
        
    
    def addList(self, values):
        # Removes the model so the addition is quicker
        self.set_model(None)
        # Freezes list so to cancel refresh event
        self.freeze_child_notify()

        for value in values:
            self.liststore.append(value)

        # set model back
        self.set_model(self.liststore)
        # Unfreeze the list
        self.thaw_child_notify()
        
    
    def remove(self):
        #http://eccentric.cx/misc/pygtk/pygtkfaq.html#13.8
        selection = self.get_selection() 
        model, iter = selection.get_selected()
        if iter:
            path = model.get_path(iter)
            model.remove(iter)
          
            selection.select_path(path)

            if not selection.path_is_selected(path):
                row = path[0]-1
             
                if row >= 0:
                    selection.select_path((row,))
                    
                    
    def getSelectedRow(self):
        selection = self.get_selection()
        model, paths = selection.get_selected_rows()
        # Returns first selected row
        return paths[0]
    

    def getSelectedItem(self, index):
        selection = self.get_selection()
        model, iter, = selection.get_selected()
        print model, iter
        return  self.liststore.get_value(iter, index)
    

    def getCount(self):
        return len(self.liststore)
    
    
    def clear(self):
        self.liststore.clear()
        
    
    def model_foreach(self, value):
        iter = self.liststore.foreach(self.change_tier, value)
        
        
    def change_tier(self, model, path, iter, data):
        t = self.liststore.get_value(iter, 0)

        if t == data[0]:
            a = 2
            b = 0
            datos = ("%0.2f" % data[1]) + ("%0.2f" % 1), ("%0.2f" % data[2])
            for x in range(6):
                self.liststore.set_value(iter, a, datos[b])
                a += 2
                b += 1
                
        
         
class TicketView(TreeView):
    def __init__(self, liststore):
        """
        This class represent ticketview of ticketstore
        """
        TreeView.__init__(self)
        # Defines the TreeStore
        self.liststore = gtk.ListStore(int, str, str, str, str, str, str, str)
#        # Associates the listStore to the ListView object
        
#       self.sorted = gtk.TreeModelSort(self.liststore)
#        self.sorted.set_sort_column_id(0, gtk.SORT_ASCENDING)

        self.set_model(self.liststore)
    
        cols = (\
                (("ID"),30, False, -1, -1, 35, 'cell', 0),\
                (("CR"),30, True, -1, -1, 35, 'pixbuf', 1),\
                (("SD"),30, True, -1, -1, 35, 'pixbuf', 2),\
                (("CO"),30, True, -1, -1, 35, 'pixbuf', 3),\
                (("NOMBRE"),220, True, -1, -1, 35, 'cell', 4),\
                (("DIRECCION"),220, True, -1, -1, 35, 'cell', 5),\
                (("IMP"),40, True, -1, -1, 35, 'cell', 6),\
                (("HORA"),40, True, -1, -1, 35,'cell', 7))
        
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))

class TicketLineaView(TreeView):
    def __init__(self, ticketstore):
        """
        This class represent ticketview of ticketstore
        """
        TreeView.__init__(self)    
        self.liststore = gtk.ListStore(int, str, str, str, str)
        # Associates the listStore to the ListView object
        self.set_model(self.liststore)
        
        cols = (\
                (("ID"),30, False, -1, -1, 35, 'cell', 0),\
                (("TICKET_FK_ID"),30, False, -1, -1, 35, 'cell', 1),\
                (("UNI"),40, True, -1, -1, 35, 'cell', 2),\
                (("DESCRIPCION"),200, True, -1, -1, 35, 'cell', 3),\
                (("IMP"),50, True, 4, -1, 35, 'cell', 4))
                
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))        
                    
class ClientesView(TreeView):
    def __init__(self, liststore):
        """
        This class represent ticketview of ticketstore
        """
        TreeView.__init__(self)    
        self.liststore = gtk.ListStore(int, str, str, str, str, str)
        # Associates the listStore to the ListView object
        self.set_model(self.liststore)
        #self.cargaDatos(CONSULTA_BASE)
        
        cols = (\
                (("ID"),50, True, 0, -1, 35, 'cell', 0),\
                (("NOMBRE"),300, True, 1, -1, 35, 'cell', 1),\
                (("DIRECCION"),300, True, 2, -1, 35, 'cell', 2),\
                (("TELEFONO"),200, True, 3, -1, 35, 'cell', 3),\
                (("FECHA_ALTA"),200, True, 4, -1, 35, 'cell', 4),\
                (("ULTIMA_COMPRA"),200, True, 5, -1, 35, 'cell', 5))
                        
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))        

class ArticulosView(TreeView):
    def __init__(self, liststore):
        """
        This class represent ticketview of ticketstore
        """
        TreeView.__init__(self)    
        self.liststore = gtk.ListStore(int, str, str, str, str, str, str)
        # Associates the listStore to the ListView object
        self.set_model(self.liststore)
        #self.cargaDatos(CONSULTA_BASE)

        cols = (\
                (("ID"),50, True, 0, -1, 35, 'cell', 0),\
                (("FAMILIA_FK_ID"),100, True, 1, -1, 35, 'cell', 1),\
                (("DESCRIPCION"),300, True, 2, -1, 35, 'cell', 2),\
                (("STOCK"),80, True, 3, -1, 35, 'cell', 3),\
                (("STOCK_MINIMO"),120, True, 4, -1, 35, 'cell', 4),\
                (("PRECIO_VENTA"),120, True, 5, -1, 35, 'cell', 5),\
                (("IMAGEN"),300, True, -1, -1, 35, 'cell', 6))
                #("BOTONERA_FK_ID"),80, True, 6, -1, 25,'cell', 7)
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))
                    

class FamiliaView(TreeView):
    def __init__(self, liststore):
        TreeView.__init__(self)
        self.liststore = gtk.ListStore(int, str, str)
        
        self.set_model(self.liststore)
        
        cols = (\
                (("ID"),50, True, -1, -1, 25, 'cell', 0),\
                (("NOMBRE"),100, True, -1, -1, 25, 'cell', 1),\
                (("DESCRIPCION"),100, True, -1, -1, 25, 'cell', 2))     
        
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))        

class CreditoView(TreeView):
    def __init__(self, liststore):
        # This class represent ticketview of ticketstore
        TreeView.__init__(self)    
        self.liststore = gtk.ListStore(int, str, str, str, str, str,str,str)
        # Associates the listStore to the ListView object
        self.set_model(self.liststore)
        #self.cargaDatos(CONSULTA_BASE)

        cols = (\
                (("ID"),50, True, -1, -1, 25, 'cell', 0),\
                (("FECHA"),100, True, -1, -1, 25, 'cell', 1),\
                (("HORA"),100, True, -1, -1, 25, 'cell', 2),\
                (("TIPO"),100, True, -1, -1, 25, 'cell', 3),\
                (("DESCRIPCION"),300, True, 4, -1, 25, 'cell', 4),\
                (("IMPORTE"),100, True, 5, -1, 25, 'cell', 5),\
                (("ENTREGA"),100, True, -1, -1, 25, 'cell', 6),\
                (("DEUDA"),100, True, 6, -1, 25,'cell', 7))
                
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))

class HistoricoView(TreeView):
    def __init__(self, liststore):
        # This class represent ticketview of ticketstore
        TreeView.__init__(self)    
        self.liststore = gtk.ListStore(int, str, str, str, str, str, str, str)
        # Associates the listStore to the ListView object
        self.set_model(self.liststore)
        #self.cargaDatos(CONSULTA_BASE)

        cols = (\
                (("ID"),50, True, -1, -1, 25, 'cell', 0),\
                (("FAMILIA_FK_ID"),100, True, -1, -1, 25, 'cell', 1),\
                (("DESCRIPCION"),300, True, -1, -1, 25, 'cell', 2),\
                (("STOCK"),80, True, -1, -1, 25, 'cell', 3),\
                (("STOCK_MINIMO"),120, True, 4, -1, 25, 'cell', 4),\
                (("PRECIO_VENTA"),120, True, 5, -1, 25, 'cell', 5),\
                (("IMAGEN"),300, True, -1, -1, 25, 'cell', 6),\
                (("BOTONERA_FK_ID"),80, True, 6, -1, 25,'cell', 7))
                
        for col in cols:
            self.append_column(
                self._new_column(
                    col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7]))