~barcc/lp-browser/trunk

« back to all changes in this revision

Viewing changes to lp_browser/lpmodel.py

  • Committer: B. Clausius
  • Date: 2013-01-13 00:36:25 UTC
  • Revision ID: barcc@gmx.de-20130113003625-3bd15f5eib9n6uq4
Finally removed get_path

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
            pri += 10
102
102
        return pri
103
103
 
104
 
    def get_path(self):
105
 
        if self.parent is None:
106
 
            return None
107
 
        path = self.parent.get_path()
108
 
        return (path or ()) + (self.index,)
109
 
 
110
104
    def get_row(self, path):
111
105
        for i in path:
112
106
            self = self.first_child
191
185
    Treeiter:   tree path, type: (int,)*n
192
186
    '''
193
187
    column_func = [
194
 
        lambda self, row: '<i>{0}</i>'.format(row.attrname),#0
195
 
        lambda self, row: row.attrtype,#1
196
 
        lambda self, row: ' '.join(('' if row.attrtype not in 'AE' else
197
 
                        self.link_rows.get(row.self_link, dummy_row).display_value
 
188
        lambda self, tpath, row: '<i>{0}</i>'.format(row.attrname),#0
 
189
        lambda self, tpath, row: row.attrtype,#1
 
190
        lambda self, tpath, row: ' '.join(('' if row.attrtype not in 'AE' else
 
191
                        self.link_rows.get(row.self_link, dummy_row)[1].display_value
198
192
                            if row.state == ROW_LINK else
199
193
                            row.display_value).splitlines()),#2
200
 
        lambda self, row: (row.state != ROW_LOADING and row.attrtype in 'AE' and
 
194
        lambda self, tpath, row: (row.state != ROW_LOADING and row.attrtype in 'AE' and
201
195
                    not (row.long_value and Row.long_value)),#3
202
 
        lambda self, row: row.is_visible(),#4
203
 
        lambda self, row: row.state != ROW_OK,#5
204
 
        lambda self, row: (self.link_rows.get(row.self_link, dummy_row)
 
196
        lambda self, tpath, row: row.is_visible(),#4
 
197
        lambda self, tpath, row: row.state != ROW_OK,#5
 
198
        lambda self, tpath, row: (self.link_rows.get(row.self_link, dummy_row)[0]
205
199
                            if row.state == ROW_LINK
206
 
                            else row).get_path(),#6
207
 
        lambda self, row: bool(row.self_link),#7
208
 
        lambda self, row: not row.long_value or not Row.long_value,#8
209
 
        lambda self, row: '<i>{0}:</i>\n{1}'
 
200
                            else tpath),#6
 
201
        lambda self, tpath, row: bool(row.self_link),#7
 
202
        lambda self, tpath, row: not row.long_value or not Row.long_value,#8
 
203
        lambda self, tpath, row: '<i>{0}:</i>\n{1}'
210
204
                            .format(row.attrname, GLib.markup_escape_text(row.display_value))
211
205
                            .strip(),#9
212
 
        lambda self, row: row.long_value and Row.long_value,#10
213
 
        lambda self, row: Row.row_icons[row.state],#11
214
 
        lambda self, row: ('Loading' if row.state == ROW_LOADING else
 
206
        lambda self, tpath, row: row.long_value and Row.long_value,#10
 
207
        lambda self, tpath, row: Row.row_icons[row.state],#11
 
208
        lambda self, tpath, row: ('Loading' if row.state == ROW_LOADING else
215
209
                            'Activate row to show attributes' if row.state == ROW_LINK else
216
210
                            (row.error.strip().splitlines() or [''])[0] if row.state == ROW_ERROR else
217
211
                            ''),#12
218
 
        lambda self, row: False,#13
 
212
        lambda self, tpath, row: False,#13
219
213
    ]
220
214
    placeholder_data = ['<i>&lt;placeholder&gt;</i>','','',False,True,False,None,False,True,
221
215
                        '',False,'gtk-refresh','',True]
245
239
        self.cache_filename = cache_filename
246
240
        self.rows_info = {}  # key: treepath tuple, value: Row object
247
241
        self.root_row = None
248
 
        self.link_rows = {}
 
242
        self.link_rows = {}  # key: self_link, value: (treepath tuple, Row object)
249
243
        
250
244
        data = self.load_cache()
251
245
        self.fill_data(data)
303
297
                self.rows_info[tpath] = row
304
298
                if row.self_link:
305
299
                    if row.state == ROW_OK:
306
 
                        self.link_rows[row.self_link] = row
 
300
                        self.link_rows[row.self_link] = tpath, row
307
301
                    elif row.state == ROW_LINK:
308
302
                        row.state = ROW_LOADING
309
303
            id_dict.clear()
310
304
        else:
311
305
            self.root_row = Row(self_link='root')
312
 
        self.link_rows[self.root_row.self_link] = self.root_row
 
306
        self.link_rows[self.root_row.self_link] = (), self.root_row
313
307
 
314
308
        self.rows_info[()] = self.rows_info[None] = self.root_row
315
309
        self.root_row.value = self.lp_worker.launchpad
386
380
                assert row.self_link in self.link_rows, (row,)
387
381
            #FIXME:
388
382
            #if bool(row.self_link):
389
 
            #    link_row = self.link_rows[row.self_link]
 
383
            #    link_row = self.link_rows[row.self_link][1]
390
384
            #    if row.state == ROW_LINK:
391
385
            #        assert link_row != row and link_row.state != ROW_LOADING, (row, link_row)
392
386
        except AssertionError as e:
456
450
        row = self.rows_info[path]
457
451
        return row.get_attr_path()
458
452
        
459
 
    def get_value_from_path(self, path):
 
453
    def get_value_from_path(self, tpath):
460
454
        '''Returns the value of the value-column'''
461
 
        row = self.rows_info[path]
462
 
        return self.get_value_from_row(row, self.COL_VALUE)
 
455
        row = self.rows_info[tpath]
 
456
        return self.get_value_from_row(tpath, row, self.COL_VALUE)
463
457
        
464
 
    def get_status_text(self, path):
 
458
    def get_status_text(self, tpath):
465
459
        '''Returns the value of the status-column'''
466
 
        row = self.rows_info[path]
467
 
        return self.get_value_from_row(row, self.COL_ROW_STATUS)
 
460
        row = self.rows_info[tpath]
 
461
        return self.get_value_from_row(tpath, row, self.COL_ROW_STATUS)
468
462
        
469
463
    def eval_operation(self, tpath, operation, kwargs):
470
464
        '''Execute Operation'''
500
494
            row.error = str(e)
501
495
            row.state = ROW_ERROR
502
496
        else:
503
 
            self.finish_entry_row(row)
 
497
            self.finish_entry_row(tpath, row)
504
498
        return tpath,
505
499
        
506
500
    def reload_entry_result(self, tpath):
507
501
        self.lp_worker.check_worker(False)
508
502
        self.on_replace_row(tpath, True)
509
503
        
510
 
    def finish_entry_row(self, row):
 
504
    def finish_entry_row(self, tpath, row):
511
505
        self.lp_worker.check_worker(True)
512
506
        try:
513
507
            row.self_link = row.value.self_link
516
510
            row.state = ROW_ERROR
517
511
        else:
518
512
            if row.self_link not in self.link_rows:
519
 
                self.link_rows[row.self_link] = row
 
513
                self.link_rows[row.self_link] = tpath, row
520
514
            row.state = ROW_LOADING
521
515
 
522
516
    def get_row_value_main(self, priority, tpath, row):
569
563
            elif row.attrtype == 'C':
570
564
                pass
571
565
            elif row.attrtype == 'E':
572
 
                self.finish_entry_row(row)
 
566
                self.finish_entry_row(tpath, row)
573
567
            elif row.attrtype == 'O':
574
568
                row.state = ROW_OK
575
569
 
576
570
            if row.state == ROW_LINK:
577
571
                try:
578
 
                    str_value = self.link_rows[row.self_link].display_value
 
572
                    str_value = self.link_rows[row.self_link][1].display_value
579
573
                except KeyError:
580
574
                    pass
581
575
            row.long_value = row.value is not None and row.attrtype == 'A' and len(str_value) > 50
616
610
                else:
617
611
                    row.attrname = str(row.index - entry_offset)
618
612
                    row.value = value
619
 
                    self.finish_entry_row(row)
 
613
                    self.finish_entry_row(tpath, row)
620
614
                GLib.idle_add(self.on_replace_row, tpath, False)
621
615
                row = row.next
622
616
                tpath = tpath[:-1] + (tpath[-1]+1,)
640
634
            rows.append((row, tpath))
641
635
        for row, tpath in reversed(rows):
642
636
            row.delete()
643
 
            if row.self_link and self.link_rows.get(row.self_link, None) == row:
 
637
            if row.self_link and self.link_rows.get(row.self_link, ((),None))[1] == row:
644
638
                del self.link_rows[row.self_link]
645
639
            self.on_remove_row(tpath)
646
640
        parent.n_children = 0
741
735
        if parent.value is None:
742
736
            return
743
737
        try:
744
 
            link_row = self.link_rows[parent.self_link]
 
738
            link_tpath, link_row = self.link_rows[parent.self_link]
745
739
        except KeyError:
746
740
            return
747
741
        if parent != link_row:
748
 
            link_tpath = link_row.get_path()
749
742
            self.create_children(link_tpath, link_row)
750
743
            parent.state = ROW_LINK
751
744
            return
784
777
            row = self.create_row(row, parent_tpath, parent, index=i, attrname='(empty)', attrtype='E')
785
778
        self.get_collection_values_main(parent_tpath, parent)
786
779
 
787
 
    def create_operation_row(self, parent):
 
780
    def create_operation_row(self, parent_tpath, parent):
788
781
        self.lp_worker.check_worker(False)
789
 
        parent_tpath = parent.get_path()
790
782
        row = self.create_row(None, parent_tpath, parent, 0, '(empty)', ' ')
791
783
        parent.n_children = 1
792
784
 
819
811
                    self.get_collection_values_main(tpath, row)
820
812
        elif row.attrtype == 'O':
821
813
            if row.n_children == 0:
822
 
                self.create_operation_row(row)
 
814
                self.create_operation_row(tpath, row)
823
815
            self.get_row_value_main(row.priority(), tpath, row)
824
816
 
825
817
    def apply_rows(self, tpath, row, with_children=False):
840
832
                if row.attrtype in 'ECO':
841
833
                    self.treestore.append(titer, self.placeholder_data)
842
834
            for i in range(len(self.column_func)):
843
 
                self.treestore.set_value(titer, i, self.get_value_from_row(row, i))
 
835
                self.treestore.set_value(titer, i, self.get_value_from_row(tpath, row, i))
844
836
            self.emit('row-changed-end', tpath, titer)
845
837
                
846
 
    def get_value_from_row(self, rowref, column):
 
838
    def get_value_from_row(self, tpath, row, column):
847
839
        self.lp_worker.check_worker(False)
848
 
        return self.column_func[column](self, rowref)
 
840
        return self.column_func[column](self, tpath, row)
849
841
        
850
842