~ubuntu-branches/ubuntu/natty/software-center/natty-security

« back to all changes in this revision

Viewing changes to softwarecenter/view/widgets/mkit.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-03-07 20:40:10 UTC
  • Revision ID: james.westby@ubuntu.com-20110307204010-xykj0i9ped9y7uy0
Tags: 3.1.23.1
* softwarecenter/db/reviews.py:
  - fix crash when submitting new review

Show diffs side-by-side

added added

removed removed

Lines of Context:
728
728
        return
729
729
 
730
730
 
731
 
class FramedSectionAlt(gtk.VBox):
732
 
 
733
 
    def __init__(self, xpadding=SPACING_MED):
734
 
        gtk.VBox.__init__(self)
735
 
        self.set_redraw_on_allocate(False)
736
 
 
737
 
        self.header_alignment = gtk.Alignment(xscale=1.0, yscale=1.0)
738
 
        self.header = gtk.HBox()
739
 
        self.header_vbox = gtk.VBox()
740
 
        header_vb_align = gtk.Alignment(0, 0.5)
741
 
        header_vb_align.add(self.header_vbox)
742
 
        self.header.pack_start(header_vb_align, False)
743
 
 
744
 
        self.header_alignment.add(self.header)
745
 
        self.header_alignment.set_padding(SPACING_SMALL,
746
 
                                          SPACING_SMALL,
747
 
                                          xpadding,
748
 
                                          xpadding)
749
 
 
750
 
        self.body_alignment = gtk.Alignment(xscale=1.0, yscale=1.0)
751
 
        self.body = gtk.VBox()
752
 
        self.body_alignment.add(self.body)
753
 
        self.body_alignment.set_padding(SPACING_MED, 0, 0, 0)
754
 
 
755
 
        self.body.set_spacing(SPACING_MED)
756
 
 
757
 
        self.pack_start(self.header_alignment, False)
758
 
        self.pack_start(self.body_alignment)
759
 
 
760
 
        self.image = gtk.Image()
761
 
        self.title = EtchedLabel()
762
 
        self.summary = gtk.Label()
763
 
 
764
 
        self.title.set_alignment(0,0.5)
765
 
        self.summary.set_alignment(0,0.5)
766
 
 
767
 
        self.summary.set_line_wrap(True)
768
 
 
769
 
        self.header_vbox.pack_start(self.title, False, False)
770
 
        self.header_vbox.pack_start(self.summary, False)
771
 
        # Make sure the user can select and copy the title/summary
772
 
        #self.label.set_selectable(True)
773
 
        return
774
 
 
775
 
    def set_icon_from_name(self, icon_name, icon_size=gtk.ICON_SIZE_MENU):
776
 
        self.image.set_from_icon_name(icon_name, icon_size)
777
 
 
778
 
        if not self.image.parent:
779
 
            self.header.pack_start(self.image, False)
780
 
            self.header.reorder_child(self.image, 0)
781
 
            self.image.show()
782
 
        return
783
 
 
784
 
    def set_icon_from_pixbuf(self, pixbuf):
785
 
        self.image.set_from_pixbuf(pixbuf)
786
 
 
787
 
        if not self.image.parent:
788
 
            self.header.pack_start(self.image, False)
789
 
            self.header.reorder_child(self.image, 0)
790
 
            self.image.show()
791
 
        return
792
 
 
793
 
    def set_title(self, label='', markup=None):
794
 
        if markup:
795
 
            self.title.set_markup(markup)
796
 
        else:
797
 
            self.title.set_markup('<small>%s</small>' % label)
798
 
 
799
 
        # atk stuff
800
 
        acc = self.get_accessible()
801
 
        acc.set_role(atk.ROLE_SECTION)
802
 
        return
803
 
 
804
 
    def set_summary(self, label='', markup=None):
805
 
        if markup:
806
 
            self.summary.set_markup(markup)
807
 
        else:
808
 
            self.summary.set_markup('<small>%s</small>' % label)
809
 
 
810
 
        # atk stuff
811
 
        acc = self.get_accessible()
812
 
        acc.set_role(atk.ROLE_SECTION)
813
 
        return
814
 
 
815
 
    def set_xpadding(self, xpadding):
816
 
        self.header_alignment.set_padding(0, 0, xpadding, xpadding)
817
 
        self.body_alignment.set_padding(0, 0, xpadding, xpadding)
818
 
        self.footer_alignment.set_padding(0, 0, xpadding, xpadding)
819
 
        return
820
 
 
821
 
 
822
 
class FramedSection(gtk.VBox):
823
 
 
824
 
    def __init__(self, label_markup=None, xpadding=SPACING_MED):
825
 
        gtk.VBox.__init__(self)
826
 
        self.set_redraw_on_allocate(False)
827
 
 
828
 
        self.header_alignment = gtk.Alignment(xscale=1.0, yscale=1.0)
829
 
        self.header = gtk.HBox()
830
 
        self.header_alignment.add(self.header)
831
 
 
832
 
        self.header_alignment.set_padding(SPACING_SMALL,
833
 
                                          SPACING_SMALL,
834
 
                                          xpadding,
835
 
                                          xpadding)
836
 
 
837
 
        self.body_alignment = gtk.Alignment(xscale=1.0, yscale=1.0)
838
 
        self.body = gtk.VBox()
839
 
        self.body_alignment.add(self.body)
840
 
        self.body_alignment.set_padding(SPACING_MED, 0, 0, 0)
841
 
 
842
 
        self.footer_alignment = gtk.Alignment(xscale=1.0, yscale=1.0)
843
 
        self.footer = gtk.HBox()
844
 
        self.footer_alignment.add(self.footer)
845
 
        self.footer_alignment.set_padding(0, 0,
846
 
                                          xpadding,
847
 
                                          xpadding)
848
 
 
849
 
        self.body.set_spacing(SPACING_MED)
850
 
        self.footer.set_size_request(-1, 2*EM)
851
 
 
852
 
        self.pack_start(self.header_alignment, False)
853
 
        self.pack_start(self.body_alignment)
854
 
        self.pack_start(self.footer_alignment, False)
855
 
 
856
 
        self.image = gtk.Image()
857
 
        self.label = EtchedLabel()
858
 
        # Make sure the user can select and copy the title/summary
859
 
        #self.label.set_selectable(True)
860
 
        self.header.pack_start(self.label, False)
861
 
        if label_markup:
862
 
            self.set_label(label_markup)
863
 
        return
864
 
 
865
 
    def set_icon_from_name(self, icon_name, icon_size=gtk.ICON_SIZE_MENU):
866
 
        self.image.set_from_icon_name(icon_name, icon_size)
867
 
 
868
 
        if not self.image.parent:
869
 
            self.header.pack_start(self.image, False)
870
 
            self.header.reorder_child(self.image, 0)
871
 
            self.image.show()
872
 
        return
873
 
 
874
 
    def set_icon_from_pixbuf(self, pixbuf):
875
 
        self.image.set_from_pixbuf(pixbuf)
876
 
 
877
 
        if not self.image.parent:
878
 
            self.header.pack_start(self.image, False)
879
 
            self.header.reorder_child(self.image, 0)
880
 
            self.image.show()
881
 
        return
882
 
 
883
 
    def set_label(self, label='', markup=None):
884
 
        if markup:
885
 
            self.label.set_markup(markup)
886
 
        else:
887
 
            self.label.set_markup('<b>%s</b>' % label)
888
 
 
889
 
        # atk stuff
890
 
        acc = self.get_accessible()
891
 
        acc.set_name(self.label.get_text())
892
 
        acc.set_role(atk.ROLE_SECTION)
893
 
        return
894
 
 
895
 
    def set_xpadding(self, xpadding):
896
 
        self.header_alignment.set_padding(0, 0, xpadding, xpadding)
897
 
        self.body_alignment.set_padding(0, 0, xpadding, xpadding)
898
 
        self.footer_alignment.set_padding(0, 0, xpadding, xpadding)
899
 
        return
900
 
 
901
 
    def draw(self, cr, a, expose_area, draw_border=True):
902
 
#        if not_overlapping(a, expose_area): return
903
 
 
904
 
#        cr.save()
905
 
#        cr.translate(0.5, 0.5)
906
 
#        cr.rectangle(a)
907
 
#        cr.clip_preserve()
908
 
 
909
 
        #a = self.header_alignment.allocation
910
 
 
911
 
        # fill section white
912
 
        #cr.rectangle(a)
913
 
        #cr.set_source_rgb(*floats_from_gdkcolor_wit(self.style.base[self.state]))
914
 
        #cr.fill()
915
 
        #cr.save()
916
 
#        cr.set_line_width(1)
917
 
#        cr.set_source_rgb(*floats_from_gdkcolor(self.style.dark[self.state]))
918
 
#        cr.stroke()
919
 
        #cr.restore()
920
 
 
921
 
#        cr.restore()
922
 
        return
923
 
 
924
 
 
925
731
class LayoutView2(gtk.HBox):
926
732
 
927
733
    def __init__(self, xspacing=4, yspacing=6):
929
735
        self.set_homogeneous(True)
930
736
 
931
737
        self.min_col_width = 128
 
738
        self.n_columns = 0
932
739
        self.yspacing = yspacing
933
740
 
934
 
        self._prev_width = -1
 
741
        self._allocation = None
935
742
        self._non_col_children = []
936
743
 
937
744
        self.connect('size-allocate', self._on_allocate, yspacing)
938
 
#        self.connect('expose-event', self._on_expose_debug)
 
745
        #~ self.connect('expose-event', self._on_expose_debug)
939
746
        return
940
747
 
941
748
    def _on_allocate(self, widget, allocation, yspacing):
 
749
        if self._allocation == allocation: return True
 
750
        self._allocation = allocation
942
751
        w = allocation.width
943
 
 
944
 
        if self._prev_width == w: return True
945
 
        self._prev_width = w
946
 
 
947
752
        self.layout(w, yspacing, force=False)
948
753
        return True
949
754
 
977
782
        self._non_col_children = []
978
783
        return
979
784
 
 
785
    def set_widgets(self, widgets):
 
786
        self.clear()
 
787
        for w in widgets:
 
788
            self._non_col_children.append(w)
 
789
        
 
790
        gobject.idle_add(self.layout, self.allocation.width, self.yspacing)
 
791
        return
 
792
 
980
793
    def layout(self, width, yspacing, force=True):
981
 
 
982
 
        old_n_cols = len(self.get_children())
983
794
        n_cols = max(1, width / (self.min_col_width + self.get_spacing()))
984
 
 
985
795
        n_cols = min(len(self._non_col_children), n_cols)
986
796
 
987
 
        if old_n_cols == n_cols and not force: return True
 
797
        if self.n_columns == n_cols and not force:
 
798
            return True
988
799
 
989
800
        for i, col in enumerate(self.get_children()):
990
801
            for child in col.get_children():
991
802
                col.remove(child)
992
803
 
993
804
            if i >= n_cols:
 
805
                self.remove(col)
994
806
                col.destroy()
995
807
 
996
 
        if n_cols > old_n_cols:
997
 
            for i in range(old_n_cols, n_cols):
 
808
        if n_cols > self.n_columns:
 
809
            for i in range(self.n_columns, n_cols):
998
810
                col = gtk.VBox(spacing=yspacing)
999
811
                self.pack_start(col)
1000
812
 
1003
815
            cols[i%n_cols].pack_start(child, False)
1004
816
 
1005
817
        self.show_all()
1006
 
        return
1007
 
 
1008
 
 
1009
 
class LayoutView(FramedSection):
1010
 
 
1011
 
    def __init__(self):
1012
 
        FramedSection.__init__(self)
1013
 
        self.set_redraw_on_allocate(False)
1014
 
 
1015
 
        self.column_hbox = gtk.HBox(spacing=SPACING_SMALL)
1016
 
        self.column_hbox.set_homogeneous(True)
1017
 
        self.body.pack_start(self.column_hbox)
1018
 
 
1019
 
        self.n_columns = 0
1020
 
        self.widget_list = []
1021
 
        self.theme = get_mkit_theme()
1022
 
        return
1023
 
 
1024
 
    def append(self, widget):
1025
 
        self.widget_list.append(widget)
1026
 
        return
1027
 
 
1028
 
    def set_width(self, width):
1029
 
        self.body.set_size_request(width, -1)
1030
 
 
1031
 
        # find widest button/widget
1032
 
        widgets = self.widget_list
1033
 
        widest_w = 0
1034
 
        for btn in widgets:
1035
 
            widest_w = max(widest_w, btn.calc_width())
1036
 
 
1037
 
        # determine number of columns to display
1038
 
#        width -= 100    # fudge number
1039
 
        n_columns = width / widest_w
1040
 
        n_columns = (width - n_columns*self.column_hbox.get_spacing()) / widest_w
1041
 
 
1042
 
        if n_columns > len(widgets):
1043
 
            n_columns = len(widgets)
1044
 
        if n_columns <= 0:
1045
 
            n_columns = 1
1046
 
 
1047
 
        if n_columns == self.n_columns: return
1048
 
        self.clear_columns()
1049
 
 
1050
 
        # pack columns into widget
1051
 
        for i in range(n_columns):
1052
 
            self.column_hbox.pack_start(gtk.VBox(spacing=SPACING_LARGE))
1053
 
 
1054
 
        # pack buttons into appropriate columns
1055
 
        i = 0
1056
 
        columns = self.column_hbox.get_children()
1057
 
        for btn in widgets:
1058
 
            columns[i].pack_start(btn, False)
1059
 
            if i < n_columns-1:
1060
 
                i += 1
1061
 
            else:
1062
 
                i = 0
1063
 
 
1064
 
        self.show_all()
1065
 
        self.n_columns = n_columns
1066
 
        return
1067
 
 
1068
 
    def clear_all(self):
1069
 
        # destroy all columns and column-children
1070
 
        self.widget_list = []
1071
 
        self.n_columns = 0
1072
 
        for col in self.column_hbox.get_children():
1073
 
            for child in col.get_children():
1074
 
                child.destroy()
1075
 
            col.destroy()
1076
 
        return
1077
 
 
1078
 
    def clear_columns(self):
1079
 
        # remove columns, but do not destroy column-children
1080
 
        for col in self.column_hbox.get_children():
1081
 
            for btn in col.get_children():
1082
 
                col.remove(btn)
1083
 
            col.destroy()
1084
 
        return
1085
 
 
1086
 
    def draw(self, cr, a, expose_area):
1087
 
        if not_overlapping(a, expose_area): return
1088
 
 
1089
 
#        cr.save()
1090
 
#        FramedSection.draw(self, cr, a, expose_area)
1091
 
 
1092
 
        for btn in self.widget_list:
1093
 
            a = btn.allocation
1094
 
            if a.width == 1 or a.height == 1: break
1095
 
 
1096
 
            btn.draw(cr, a, expose_area)
1097
 
 
1098
 
#        cr.restore()
 
818
        self.n_columns = n_cols
1099
819
        return
1100
820
 
1101
821