~raude/awn-extras/awn-extras-remi

« back to all changes in this revision

Viewing changes to awn-applets/awn-extras-applets/src/stacks/stacks_gui_curved.py

  • Committer: moonbeam
  • Date: 2007-12-13 20:02:45 UTC
  • Revision ID: rcryderman@gmail.com-20071213200245-wvc71fghtazuzg5a
stacks
        -patch submitted by Silentstorm to fix an issue caused by the previous commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
from stacks_launcher import LaunchManager
113
113
from stacks_icons import IconFactory
114
114
from stacks_vfs import VfsUri
115
 
from stacks_glade import GladeWindow
 
115
 
116
116
 
117
117
APP="Stacks"
118
118
DIR="locale"
126
126
#constants
127
127
stack_item_x = 1
128
128
 
129
 
def _to_full_path(path):
130
 
    head, tail = os.path.split(__file__)
131
 
    return os.path.join(head, path)
132
 
 
133
129
"""
134
130
Main Applet class
135
131
"""
145
141
    
146
142
    tooltips_enabled = True
147
143
    
148
 
 
 
144
    max_text_length = 200
149
145
    base_angle_interval = 0.85
150
146
    currentwidth = 10
151
147
    currentheight = 10
182
178
    context_menu_visible = False
183
179
    tooltip_visible = False
184
180
    just_dragged = False
185
 
    gconf_client = None
186
181
 
187
182
    signal_ids = []
188
183
 
223
218
                self.errorwindow.show_all()
224
219
                
225
220
                return None
 
221
        
 
222
        
226
223
 
227
 
        self.applet = applet
228
 
        
229
 
        curved_config = get_curved_gui_config(
230
 
                self.applet.gconf_client,
231
 
                self.applet.gconf_path,
232
 
                self.applet.uid)
233
 
        self.curved_config = curved_config
234
224
                
235
225
        # connect to events
 
226
        self.applet = applet
236
227
        self.signal_ids.append(applet.connect("stacks-gui-hide", self._stacks_gui_hide_cb))
237
228
        self.signal_ids.append(applet.connect("stacks-gui-show", self._stacks_gui_show_cb))
238
229
        self.signal_ids.append(applet.connect("stacks-gui-toggle", self._stacks_gui_toggle_cb))
240
231
        self.signal_ids.append(applet.connect("stacks-config-changed", self._stacks_config_changed_cb))
241
232
        self.signal_ids.append(applet.connect("stacks-item-removed", self._item_removed_cb))
242
233
        self.signal_ids.append(applet.connect("stacks-item-created", self._item_created_cb))
243
 
        self.signal_ids.append(applet.connect("stacks-gui-config", self.show_config))
244
 
        
245
 
        
246
234
 
247
235
        # Init the window
248
236
        gtk.Window.__init__(self)
525
513
 
526
514
    def _destroy_cb(self, widget):
527
515
        for id in self.signal_ids: self.applet.disconnect(id)
528
 
 
529
516
        
530
 
    def show_config(self, widget):
531
 
        curved_cfg = CurvedStacksConfig(self.applet)
532
 
 
533
517
 
534
518
    def _stacks_gui_hide_cb(self, widget, event = None):
535
519
        if self.context_menu_visible: return
549
533
 
550
534
    def _stacks_config_changed_cb(self, widget, config):
551
535
        self.config = config
552
 
        curved_config = get_curved_gui_config(
553
 
                self.applet.gconf_client,
554
 
                self.applet.gconf_path,
555
 
                self.applet.uid)
556
 
        self.curved_config = curved_config
557
536
 
558
537
    def _item_created_cb(self, widget, store, iter, angle = 0, direction = "LEFT",id = 0):
559
538
        if store:
626
605
        
627
606
        icon_size = self.config['icon_size']
628
607
        if self.direction == "RIGHT":
629
 
                x = ax + aw/2  - self.text_distance - self.curved_config['label_length'] - icon_size / 2;
 
608
                x = ax + aw/2  - self.text_distance - self.max_text_length - icon_size / 2;
630
609
        else:
631
610
                x = ax + aw/2  - icon_size / 2 - self.maxx - icon_size / 4;
632
611
        y = ay - h + 50
735
714
        
736
715
 
737
716
  
738
 
        self.width = int(round( self.text_distance + self.curved_config['label_length'] + icon_size + self.maxx + icon_size / 4))
 
717
        self.width = int(round( self.text_distance + self.max_text_length + icon_size + self.maxx + icon_size / 4))
739
718
        
740
719
        self.right_arrow_enabled = False
741
720
        self.left_arrow_enabled = False
826
805
                
827
806
        if self.right_arrow_enabled:
828
807
                if self.direction == "RIGHT":
829
 
                        self.right_arrow_position = self.drawArrow ( context, self.text_distance + self.curved_config['label_length'] + icon_size *3 / 4, self.height - icon_size / 2, icon_size / 4, "RIGHT", self.right_arrow_active)
 
808
                        self.right_arrow_position = self.drawArrow ( context, self.text_distance + self.max_text_length + icon_size *3 / 4, self.height - icon_size / 2, icon_size / 4, "RIGHT", self.right_arrow_active)
830
809
                else:
831
810
                        self.right_arrow_position = self.drawArrow ( context,  self.maxx + icon_size , self.height - icon_size / 2, icon_size / 4, "RIGHT", self.right_arrow_active)
832
811
        if self.left_arrow_enabled:
833
812
                if self.direction == "RIGHT":
834
 
                        self.left_arrow_position = self.drawArrow ( context, self.text_distance + self.curved_config['label_length'] + icon_size / 4, self.height - icon_size / 2, icon_size / 4, "LEFT", self.left_arrow_active)
 
813
                        self.left_arrow_position = self.drawArrow ( context, self.text_distance + self.max_text_length + icon_size / 4, self.height - icon_size / 2, icon_size / 4, "LEFT", self.left_arrow_active)
835
814
                else:
836
815
                        self.left_arrow_position = self.drawArrow ( context, self.maxx + icon_size / 2, self.height - icon_size / 2, icon_size / 4, "LEFT", self.left_arrow_active)
837
816
                
852
831
 
853
832
        
854
833
        if self.direction == "RIGHT":
855
 
                icon_x = si.x + self.text_distance + self.curved_config['label_length']
 
834
                icon_x = si.x + self.text_distance + self.max_text_length
856
835
                label_x = 0
857
836
                angle = si.angle
858
837
        else:
930
909
                y_adjust = 0
931
910
                if iw < icon_size: x_adjust = (icon_size - iw) / 2
932
911
                if ih < icon_size: y_adjust = (icon_size - ih) / 2
933
 
                
 
912
 
934
913
                context.set_source_pixbuf(icon,x+x_adjust,y+y_adjust)
935
914
                context.fill()
936
915
                context.paint()
968
947
                
969
948
                pango_layout.set_font_description(pango.FontDescription("sans 10"))
970
949
                
971
 
                #fontmap = pangocairo.cairo_font_map_get_default()
972
 
                
973
 
                #font.set_size(10)
974
 
                #pango_layout.set_font_description(pango.FontDescription("10"))
975
 
                
976
950
                y = y -7 # compensating for lable height of 16
977
951
 
978
952
                if selected:
981
955
                        context.set_source_rgba (0,0,0,0.65)
982
956
                
983
957
                label_width = 10
984
 
                labletext, label_width = self.get_text_width(pango_layout, labletext,self.curved_config['label_length'])
 
958
                labletext, label_width = self.get_text_width(pango_layout, labletext,self.max_text_length)
985
959
                label_width = label_width + 10
986
960
                
987
961
                if self.direction == "RIGHT":
1122
1096
                self.icon_y = 0
1123
1097
 
1124
1098
 
1125
 
class CurvedStacksConfig(GladeWindow):
1126
 
    glade_file = _to_full_path('curved_stacks_preferences.glade')
1127
 
    backend_type = BACKEND_TYPE_INVALID
1128
 
    applet = None
1129
 
 
1130
 
    backend = None
1131
 
    config = None
1132
 
 
1133
 
    def __init__(self, applet):
1134
 
        GladeWindow.__init__(self)
1135
 
        self.applet = applet
1136
 
        
1137
 
        config = get_curved_gui_config(
1138
 
                self.applet.gconf_client,
1139
 
                self.applet.gconf_path,
1140
 
                self.applet.uid)
1141
 
        self.config = config
1142
 
 
1143
 
 
1144
 
        #set label length
1145
 
        self.widgets['label_length_box'].set_value(config['label_length'])
1146
 
    
1147
 
    def on_cancel_button_clicked(self, *args):
1148
 
        self.destroy()
1149
 
 
1150
 
    def on_ok_button_clicked(self, *args):
1151
 
        #save configuration to gconf
1152
 
        label_length = self.widgets['label_length_box'].get_value()
1153
 
        if int(label_length) > 0:
1154
 
            self.applet.gconf_client.set_int(
1155
 
                    self.applet.gconf_path + "/curved_gui/label_length", int(label_length) )
1156
 
        self.destroy()
1157
 
        
1158
 
def get_curved_gui_config(gconf_client, gconf_path, uid):
1159
 
    # store config in dict
1160
 
    config = {}
1161
 
    # try to get backend from gconf
1162
 
 
1163
 
    # get dimension
1164
 
    _config_label_length = gconf_client.get_int(gconf_path + "/curved_gui/label_length")
1165
 
    if _config_label_length <= 0:
1166
 
        _config_label_length = 200
1167
 
    config['label_length'] = _config_label_length
1168
 
 
1169
 
        
1170
 
    
1171
 
    
1172
 
    return config