789
838
self.entry.set_text(self.liststore[selection.get_selected()[1]][3])
790
839
self.entry.grab_focus()
792
#Applet show/hide methods - copied from MiMenu (and edited)
793
#When a button is pressed
794
def button_press(self, widget, event):
795
if event.button in (1, 2):
841
def unmount(self, num):
842
li = self.monitor.get_volumes()
843
li.extend(self.monitor.get_mounts())
846
if isinstance(li[num], gio.Volume):
847
if li[num].get_mount():
848
#If the volume can eject
849
if li[num].get_mount().can_eject():
850
li[num].get_mount().eject(self.ejected_or_unmounted)
853
#If the volume can unmount
854
if li[num].get_mount().can_unmount():
855
li[num].get_mount().unmount(self.ejected_or_unmounted)
860
#If the mount can eject
861
if li[num].can_eject():
862
li[num].eject(self.ejected_or_unmounted)
865
#If the mount can unmount
866
elif li[num].can_unmount():
867
li[num].unmount(self.ejected_or_unmounted)
872
def icon_clicked(self, widget):
873
event = gtk.get_current_event()
876
if self.client.get_int(group, 'mode') == 0:
796
877
if self.dialog.flags() & gtk.VISIBLE:
797
878
self.dialog.hide()
800
881
self.dialog_config(event.button)
802
elif event.button == 3:
804
self.show_menu(event)
885
self.dialog_config(event.button)
887
def show_context_menu(self, widget, event):
889
self.show_menu(event)
891
def show_docklet(self, window_id):
892
self.docklet_visible = True
893
docklet = awn.Applet(self.get_canonical_name(), self.props.uid, self.props.panel_id)
894
docklet.props.quit_on_delete = False
895
self.docklet = docklet
897
def invalidate_docklet(widget, applet):
898
applet.docklet_visible = False
899
applet.docklet = None
900
applet.docklet_play_pause = None
901
docklet.connect("destroy", invalidate_docklet, self)
903
docklet_position = docklet.get_pos_type()
905
top_box.set_orientation_from_pos_type(docklet_position)
907
align = awn.Alignment(docklet)
909
box.set_orientation_from_pos_type(docklet_position)
912
align.set(0.5, 0.5, 1.0, 1.0)
913
top_box.pack_start(align)
915
self.docklet_box = awn.IconBox(docklet)
917
self.update_docklet(False)
919
top_box.pack_start(self.docklet_box, True, True)
922
gtk.Plug.__init__(docklet, long(window_id))
924
self.update_docklet()
926
def update_docklet(self, show_all=True):
928
box = self.docklet_box
933
for icon in box.get_children():
934
if icon == self.icon:
939
for place in self.places_data:
941
icon.set_from_pixbuf(self.load_pixbuf(place[0], self.get_size()))
942
icon.set_tooltip_text(place[1])
943
icon.connect('clicked', self.docklet_icon_clicked, place[3])
944
icon.connect('context-menu-popup', self.docklet_icon_menu, place)
946
box.set_child_packing(icon, False, True, 0, gtk.PACK_START)
948
if gio and place[3] in self.droppable_places:
949
icon.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION, \
950
[("text/uri-list", 0, 0)], gtk.gdk.ACTION_MOVE)
951
icon.connect('drag-data-received', self.docklet_drag_data_received, place[3])
952
icon.connect('drag-motion', self.docklet_drag_motion)
953
icon.connect('drag-leave', self.docklet_drag_leave)
955
if show_all and self.mode == 1:
956
self.docklet.show_all()
958
elif show_all and self.mode == 2:
959
self.icon_box.show_all()
961
def docklet_drag_data_received(self, w, context, x, y, data, info, time, path):
962
if data and data.format == 8:
963
context.finish(True, False, time)
965
if path in self.droppable_places:
966
dropped_paths = data.data.split('\n')
969
for dropped_path in dropped_paths:
970
if len(dropped_path) >= 8:
971
if dropped_path[:8] == 'file:///':
972
dropped_path = dropped_path.strip()
974
dropped_path = urllib.unquote(dropped_path)
976
from_file = gio.File(dropped_path)
978
to_file = gio.File(path + '/' + from_file.get_basename())
980
#Make sure we're not just moving the file to the same directory
981
if not from_file.equal(to_file):
982
if from_file.move(to_file):
986
config_fb = self.client.get_string(group, 'fb')
987
open_dir = path.replace(' ', '\ ')
988
os.system('%s %s &' % (config_fb, open_dir))
993
def docklet_drag_motion(self, icon, context, x, y, time):
994
icon.get_effects().start(awn.EFFECT_LAUNCHING)
995
icon.get_tooltip().update_position()
996
icon.get_tooltip().show()
1000
def docklet_drag_leave(self, icon, context, time):
1001
icon.get_effects().stop(awn.EFFECT_LAUNCHING)
1002
icon.get_tooltip().hide()
1006
def docklet_icon_clicked(self, icon, uri):
1007
self.launch_fb(None, uri)
1010
self.docklet.destroy()
1012
def docklet_icon_menu(self, icon, event, place):
1013
menu = self.create_default_menu()
1015
#If the place is ejectable
1017
eject = awn.image_menu_item_new_with_label(_("Eject"))
1018
image = gtk.image_new_from_icon_name('media-eject', gtk.ICON_SIZE_MENU)
1019
eject.set_image(image)
1022
eject.connect('activate', self.docklet_menu_eject, place[4])
1024
prefs = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
1025
prefs.connect('activate', self.open_prefs)
1028
about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
1029
about.connect("activate", self.open_about)
1033
menu.popup(None, None, None, event.button, event.time)
1035
def docklet_menu_eject(self, menu, num):
806
1038
#The user changed the icon theme
807
1039
def icon_theme_changed(self, icon_theme):
808
for key in self.icons.keys():
1040
for d in self.icons.values():
1041
for key in d.keys():
812
1045
self.do_gio_places()
814
1047
#Reload the stock folder icon
815
self.icons['stock_folder'] = self.theme.load_icon('stock_folder', 24, 24)
1048
self.icons[24]['stock_folder'] = self.theme.load_icon('stock_folder', 24, 0)
818
1050
def dialog_config(self, button):
819
if button not in (1, 2):
821
self.curr_button = button
1053
action = self.client.get_int(group, 'lmb')
1054
path = os.path.expanduser(self.client.get_string(group, 'lmb_path'))
1058
action = self.client.get_int(group, 'mmb')
1059
path = os.path.expanduser(self.client.get_string(group, 'mmb_path'))
1067
mode = self.client.get_int(group, 'mode')
823
1069
#Get whether to focus the entry when displaying the dialog or not
824
1070
config_focus = self.client.get_int(group, 'focus_entry')
826
if button == 1: #Left mouse button
827
#Get the value for the left mouse button to automatically open.
828
#Create and default to 1 the entry if it doesn't exist
829
#Also get the default directory or default to ~
830
config_lmb = self.client.get_int(group, 'lmb')
831
config_lmb_path = self.client.get_string(group, 'lmb_path')
832
config_lmb_path = os.path.expanduser(config_lmb_path)
834
elif button == 2: #Middle mouse button
835
#Get the value for the middle mouse button to automatically open.
836
#Create and default to 2 the entry if it doesn't exist
837
#Also get the default directory or default to ~
838
config_mmb = self.client.get_int(group, 'mmb')
839
config_mmb_path = self.client.get_string(group, 'mmb_path')
840
config_mmb_path = os.path.expanduser(config_mmb_path)
842
#Left mouse button - either popup with correct path or launch correct path OR do nothing
845
self.entry.set_text(config_lmb_path)
850
if config_focus == 2:
851
self.entry.grab_focus()
852
self.entry.set_position(-1)
854
self.dialog.show_all()
856
elif config_lmb == 2:
857
self.launch_fb(None, config_lmb_path)
859
#Right mouse button - either popup with correct path or launch correct path OR do nothing
862
self.entry.set_text(config_mmb_path)
867
if config_focus == 2:
868
self.entry.grab_focus()
869
self.entry.set_position(-1)
871
self.dialog.show_all()
873
elif config_mmb == 2:
874
self.launch_fb(None, config_mmb_path)
1072
#Show dialog/docklet
1076
#Occasionally this happens; don't do two docklets at once
1077
if not self.docklet_visible:
1078
win = self.docklet_request(0, True, True)
1080
self.show_docklet(win)
1084
self.entry.set_text(path)
1086
if config_focus == 2:
1087
self.entry.grab_focus()
1088
self.entry.set_position(-1)
1090
self.dialog.show_all()
1094
self.launch_fb(None, path)
1096
def update_mode(self, *args):
1097
self.mode = self.client.get_int(group, 'mode')
1101
if 'docklet' in dir(self) and self.docklet is not None:
1102
self.docklet.destroy()
1105
self.docklet_visible = False
1107
for icon in self.icon_box.get_children():
1108
if icon == self.icon:
1109
self.icon_box.remove(icon)
1113
self.icon_box.add(self.icon)
1117
self.docklet_visible = True
1118
self.update_docklet()
876
1120
#If the user hits the enter key on the main part OR the number pad
877
1121
def detect_enter(self, a, event):