コード例 #1
0
ファイル: Tilo.py プロジェクト: solo2101/Tilo-Menu
	def __init__(self, applet):
		self.applet = applet
		self.applet.set_tooltip_text("Tilo")
		#print self.applet.get_size()
		#print self.applet.get_position()
		if self.applet.get_pos_type() == gtk.POS_TOP:
			backend.save_setting('orientation', 'top')
		else:
			backend.save_setting('orientation', 'bottom')
		#Get the default icon theme
		import Globals as Globals
		self.Globals = Globals
		self.theme = gtk.icon_theme_get_default()
		self.icons['stock_folder'] = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[0])
	        self.setup_context_menu()

		if Globals.Settings['Distributor_Logo']:
			import IconFactory as iconfactory
			self.iconfactory = iconfactory
			self.applet_button = self.iconfactory.GetSystemIcon('distributor-logo')
		else: self.applet_button = Globals.Applogo

		self.applet.icon.file(self.applet_button, size=awnlib.Icon.APPLET_SIZE)
		#Connect to signals
		self.applet.connect('button-press-event', self.button_press)
		self.applet.connect_size_changed(self.size_changed)
		#self.theme.connect('changed', self.icon_theme_changed)
		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
コード例 #2
0
	def __init__(self):
		self.tray = gtk.StatusIcon()

		#app = gnomeapplet.Applet()
		#g = GnoMenu(app,"")
		self.tray.connect("activate", self.ShowMenu)
		self.tray.connect("popup-menu", self.show_menu)
		self.menu = gtk.Menu()
		self.m = gtk.Menu()
		add_image_menuitem(self.menu, gtk.STOCK_PROPERTIES, _("Preferences"), self.properties)
		add_image_menuitem(self.menu, gtk.STOCK_ABOUT, _("About"), self.about_info)
		add_image_menuitem(self.menu, gtk.STOCK_EDIT, _("Edit Menus"), self.edit_menus)
		add_image_menuitem(self.menu, gtk.STOCK_QUIT, _("Quit"), self.end)

		self.tray.set_tooltip("GnoMenu")
		self.tray.set_visible(True)

		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		import Globals as Globals
		self.Globals = Globals
		if Globals.Settings['Distributor_Logo']:
			import IconFactory as iconfactory
			self.iconfactory = iconfactory
			self.applet_button = self.iconfactory.GetSystemIcon('distributor-logo')
		else: self.applet_button = self.Globals.Applogo
		pixbuf = gtk.gdk.pixbuf_new_from_file(self.applet_button)
		self.tray.set_from_pixbuf(pixbuf)
		self.show = False
		gtk.main()		
コード例 #3
0
ファイル: SundaraMenu.py プロジェクト: rizmut/SundaraOS
    def __init__(self, applet):
        self.applet = applet
        self.applet.set_tooltip_text("Sundara Menu")
        #print self.applet.get_size()
        #print self.applet.get_position()
        if self.applet.get_pos_type() == gtk.POS_TOP:
            backend.save_setting('orientation', 'top')
        else:
            backend.save_setting('orientation', 'bottom')
        #Get the default icon theme
        import Globals as Globals
        self.Globals = Globals
        self.theme = gtk.icon_theme_get_default()
        self.icons['stock_folder'] = gtk.gdk.pixbuf_new_from_file(
            Globals.StartButton[0])
        self.setup_context_menu()

        import IconFactory as iconfactory
        self.iconfactory = iconfactory
        self.applet_button = '/usr/share/avant-window-navigator/applets/SundaraMenu/logo.png'

        self.applet.icon.file(self.applet_button, size=awnlib.Icon.APPLET_SIZE)
        #Connect to signals
        self.applet.connect('button-press-event', self.button_press)
        self.applet.connect_size_changed(self.size_changed)
        #self.theme.connect('changed', self.icon_theme_changed)
        from Menu_Main import Main_Menu
        self.hwg = Main_Menu(self.HideMenu)
        #print self.hwg.window.window.is_visible()
        gobject.timeout_add(500, self.HideMenu)
        show_window = self.hwg.show_window

        def _show_window():
            if time.time() - Main_Menu.last_click > 2:
                return
            return show_window()

        self.hwg.show_window = _show_window
コード例 #4
0
ファイル: GnoMenu.py プロジェクト: jindongyang/gnomenu
	def map_event(self, widget, event):
		print 'map'
		if Globals.ShowTop == 1 and  Globals.Settings["Distributor_Logo"] == 0:
			#Create auxiliary window (CAIRO)
			from Panel_Top import PanelTopWindow
			self.aux = PanelTopWindow()
			self.aux.aux_window.connect("enter-notify-event", self.select_box)
			self.aux.aux_window.connect("leave-notify-event", self.deselect_box)
			self.aux.aux_window.connect("button-press-event",self.button_press)
		self.Redraw_graphics()
		self.Update_Panel_Top()
		if Globals.ShowTop == 1 and Globals.Settings["Distributor_Logo"] == 0:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		self.hwg = Main_Menu(self.HideMenu)
		self.hwg.connect('state-changed',self.button_changed)
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		Globals.SavedOriginState = self.x,self.y
コード例 #5
0
ファイル: TiloDo.py プロジェクト: solo2101/Tilo-Menu
	def __init__(self, applet):
		self.applet = applet
		self.applet.set_tooltip_text("Tilo")
		mateconf_app_key = '/apps/tilo'
		self.dokey = '/apps/mate-do/Docky/Utilities/DockPreferences'
		self.mateconf_client = mateconf.client_get_default()
		#print self.applet.get_size()
		#print self.applet.get_position()
		self.orient = self.mateconf_client.get_string(mateconf_app_key + '/Orientation')
		if self.orient == 'Top':
			self.mateconf_client.set_string(mateconf_app_key + '/orientation', 'top')
		else:
			self.mateconf_client.set_string(mateconf_app_key + '/orientation', 'bottom')
		proc = os.popen("""ps axo "%p,%a" | grep "Tilo.py" | grep -v grep|cut -d',' -f1""").read()
		procs = proc.split('\n')
		if len(procs) > 2:
			import wnck
			try:
				wnck.set_client_type(wnck.CLIENT_TYPE_PAGER)
			except AttributeError:
				print "Error: Failed to set libwnck client type, window " \
						"activation may not work"
			screen = wnck.screen_get_default()
			while gtk.events_pending():
				gtk.main_iteration()
			wins = screen.get_windows_stacked()
			
			for win in wins:
				name = win.get_name()
				if name == 'GnoMeny.py':
		
					if win and win.is_hidden():
						sys.exit(1)
					elif win and win.is_minimized():
						win.unminimize(1)
					elif win and win.is_active() == False:
						win.activate(1)
		#Get the default icon theme
		import Globals as Globals
		self.Globals = Globals
		#self.theme.connect('changed', self.icon_theme_changed)
		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		#print self.hwg.window.window.is_visible()
		self.ShowMenu()
コード例 #6
0
	def timeout_callback(self):

		if Globals.ShowTop == 1:
			#Create auxiliary window (CAIRO)
			from Panel_Top import PanelTopWindow
			self.aux = PanelTopWindow()
			self.aux.aux_window.connect("enter-notify-event", self.select_box)
			self.aux.aux_window.connect("leave-notify-event", self.deselect_box)
			self.aux.aux_window.connect("button-press-event",self.button_press)
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		self.hwg = Main_Menu(self.HideMenu)
		self.hwg.connect('state-changed',self.button_changed)
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		Globals.SavedOriginState = self.x,self.y

		###### Hotkey Menu Activation ########################################
		######################################################################

		return False
コード例 #7
0
ファイル: GnoMenu.py プロジェクト: cs2c-jindongyang/GnoMenu
	def __init__(self,applet):
		self.applet = applet
		self.Button_state = 0 # 0 = No change  1 = Mouse over  2 = Depressed

		self.EBox = Gtk.EventBox()
		self.applet_icon = Gtk.Image()
		pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("/usr/share/gnomenu/Themes/Button/XP/start-here.png",-1,-1)
		self.applet_icon.set_from_pixbuf(pixbuf)
		self.applet_icon.show()
		self.EBox.add(self.applet_icon)
		self.applet.add(self.EBox)
		self.EBox.connect("button-press-event",self.press_box)
		self.EBox.connect("enter-notify-event", self.select_box)
		self.EBox.connect("leave-notify-event", self.deselect_box)
		self.applet.show_all()
		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		self.x,self.y = 0,10000
		self.time = 0
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
コード例 #8
0
ファイル: main.py プロジェクト: solo2101/Tilo-Menu
    def init(self):
        self.setHasConfigurationInterface(False)
	#self.setBackgroundHints(Plasma.Applet.TranslucentBackground)
        self.resize(125, 125)
        self.setAspectRatioMode(Plasma.Square)
       # self.theme = Plasma.Svg(self)
      #  self.theme.setImagePath("widgets/background")
      #  self.setBackgroundHints(Plasma.Applet.TranslucentBackground)
        self.layout = QGraphicsLinearLayout(self.applet)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
    #    self.icon = Plasma.IconWidget()
    #    self.layout.addItem(self.icon)
        self.icon = Plasma.IconWidget()
        self.layout.addItem(self.icon)
	self.connect(self.icon, SIGNAL("clicked()"), self.iconClicked)



	print self.package().path() + "contents/icons/logo.png"

	from Menu_Main import Main_Menu
	self.hwg = Main_Menu(self.HideMenu)
	import Globals as Globals
	self.Globals = Globals
	if Globals.Settings['Distributor_Logo']:
		import IconFactory as iconfactory
		self.iconfactory = iconfactory
	        self.icon.setIcon(KIcon('distributor-logo'))

	else:
		self.icon.setIcon(KIcon(self.package().path() + "contents/icons/logo.svg"))
        self.icon.update()


	self.show = False
	print self.popupPosition(QSize(Globals.MenuWidth,Globals.MenuHeight))
コード例 #9
0
ファイル: TiloDo.py プロジェクト: solo2101/Tilo-Menu
class Tilo ():
	icons = {}
	def __init__(self, applet):
		self.applet = applet
		self.applet.set_tooltip_text("Tilo")
		mateconf_app_key = '/apps/tilo'
		self.dokey = '/apps/mate-do/Docky/Utilities/DockPreferences'
		self.mateconf_client = mateconf.client_get_default()
		#print self.applet.get_size()
		#print self.applet.get_position()
		self.orient = self.mateconf_client.get_string(mateconf_app_key + '/Orientation')
		if self.orient == 'Top':
			self.mateconf_client.set_string(mateconf_app_key + '/orientation', 'top')
		else:
			self.mateconf_client.set_string(mateconf_app_key + '/orientation', 'bottom')
		proc = os.popen("""ps axo "%p,%a" | grep "Tilo.py" | grep -v grep|cut -d',' -f1""").read()
		procs = proc.split('\n')
		if len(procs) > 2:
			import wnck
			try:
				wnck.set_client_type(wnck.CLIENT_TYPE_PAGER)
			except AttributeError:
				print "Error: Failed to set libwnck client type, window " \
						"activation may not work"
			screen = wnck.screen_get_default()
			while gtk.events_pending():
				gtk.main_iteration()
			wins = screen.get_windows_stacked()
			
			for win in wins:
				name = win.get_name()
				if name == 'GnoMeny.py':
		
					if win and win.is_hidden():
						sys.exit(1)
					elif win and win.is_minimized():
						win.unminimize(1)
					elif win and win.is_active() == False:
						win.activate(1)
		#Get the default icon theme
		import Globals as Globals
		self.Globals = Globals
		#self.theme.connect('changed', self.icon_theme_changed)
		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		#print self.hwg.window.window.is_visible()
		self.ShowMenu()


	def size_changed(self):
		self.applet.icon.file(self.Globals.Applogo, size=awnlib.Icon.APPLET_SIZE)


	def button_press(self, widget, event):
		if event.button in (1, 2):
			if not self.hwg.window.window:
				self.ShowMenu()
			else:
				if not self.hwg.window.window.is_visible():
					self.ShowMenu()
				else: self.HideMenu()

		elif event.button == 3:
			self.HideMenu()
			self.show_menu(event)

	def ShowMenu(self):
		# Display the start menu!!!
		origin = self.applet.get_window().get_origin()
		
		self.hwg.Adjust_Window_Dimensions(origin[0] - (self.Globals.MenuWidth/2),origin[1]+self.applet.get_size())#self.applet.get_window().get_geometry()[3]/2 -10)
		self.hwg.show_window()

	def HideMenu(self):
		if self.hwg:
			if self.hwg.window.window:
				if self.hwg.window.window.is_visible()== True:
					self.hwg.hide_window()

	def show_menu(self,event):

		#Create the items for Preferences and About
		self.prefs = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
		self.about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
		self.edit = gtk.ImageMenuItem(gtk.STOCK_EDIT)
	
		#Connect the two items to functions when clicked
		self.prefs.connect("activate", self.properties)
		self.about.connect("activate", self.about_info)
		self.edit.connect("activate", self.edit_menus)

	
		#Now create the menu to put the items in and show it
		self.menu = self.applet.create_default_menu()
		self.menu.append(self.prefs)
		self.menu.append(self.about)
		self.menu.append(self.edit)
		self.menu.show_all()
		self.menu.popup(None, None, None, event.button, event.time)
		

	def properties(self,event=0,data=None):
		#os.spawnvp(os.P_WAIT,Globals.ProgramDirectory+"Tilo-Settings.py",[Globals.ProgramDirectory+"Tilo-Settings.py"])
		os.system("/bin/sh -c '"+self.Globals.ProgramDirectory+"Tilo-Settings.py' &")
		# Fixme, reload stuff properly
		self.Globals.ReloadSettings()
		
	def about_info(self,event=0,data=None):
		os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+self.Globals.appdirname+"/Tilo-Settings.py --about' &")

	def edit_menus(self,event=0, data=None):
		os.spawnvp(os.P_WAIT,"mozo",["mozo"])
コード例 #10
0
ファイル: GnoMenu.py プロジェクト: cs2c-jindongyang/GnoMenu
class GnoMenu(MatePanelApplet.Applet):

	def __init__(self,applet):
		self.applet = applet
		self.Button_state = 0 # 0 = No change  1 = Mouse over  2 = Depressed

		self.EBox = Gtk.EventBox()
		self.applet_icon = Gtk.Image()
		pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("/usr/share/gnomenu/Themes/Button/XP/start-here.png",-1,-1)
		self.applet_icon.set_from_pixbuf(pixbuf)
		self.applet_icon.show()
		self.EBox.add(self.applet_icon)
		self.applet.add(self.EBox)
		self.EBox.connect("button-press-event",self.press_box)
		self.EBox.connect("enter-notify-event", self.select_box)
		self.EBox.connect("leave-notify-event", self.deselect_box)
		self.applet.show_all()
		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		self.x,self.y = 0,10000
		self.time = 0
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)

	def press_box(self, widget,event):
		if (event.button == 1) and (self.time != event.time):
			if not self.hwg.window.window:
				self.ShowMenu()
				self.Button_state = 2
			else:
				if self.Button_state == 2:
					self.HideMenu()
					self.Button_state = 1
				else:
					self.ShowMenu()
					self.Button_state = 2
			self.Redraw_graphics()
		self.time = event.time

	def ShowMenu(self):
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		if self.hwg:
			self.hwg.show_window()
		

	def HideMenu(self):
		if self.hwg:
			if self.hwg.window.window:
				if self.hwg.window.window.is_visible()== True:
					self.hwg.hide_window()
		self.Button_state = 1
		self.Redraw_graphics()

	def release_box(self,widget,event):
		self.Button_state = 1
		self.Redraw_graphics()

	def select_box(self,widget,event):
		if self.Button_state == 0:
			self.Button_state = 1
			self.Redraw_graphics()

	def deselect_box(self,widget,event):
		if self.Button_state == 1:
			self.Button_state = 0
			self.Redraw_graphics()

	def Redraw_graphics (self):
		if self.Button_state == 0:
			self.applet_icon.set_from_file("/usr/share/gnomenu/Themes/Button/XP/start-here.png")
		if self.Button_state == 1:
			self.applet_icon.set_from_file("/usr/share/gnomenu/Themes/Button/XP/start-here-glow.png")
		if self.Button_state == 2:
			self.applet_icon.set_from_file("/usr/share/gnomenu/Themes/Button/XP/start-here-depressed.png")
コード例 #11
0
ファイル: SundaraMenu.py プロジェクト: rizmut/SundaraOS
class SundaraMenu():
    icons = {}

    def __init__(self, applet):
        self.applet = applet
        self.applet.set_tooltip_text("Sundara Menu")
        #print self.applet.get_size()
        #print self.applet.get_position()
        if self.applet.get_pos_type() == gtk.POS_TOP:
            backend.save_setting('orientation', 'top')
        else:
            backend.save_setting('orientation', 'bottom')
        #Get the default icon theme
        import Globals as Globals
        self.Globals = Globals
        self.theme = gtk.icon_theme_get_default()
        self.icons['stock_folder'] = gtk.gdk.pixbuf_new_from_file(
            Globals.StartButton[0])
        self.setup_context_menu()

        import IconFactory as iconfactory
        self.iconfactory = iconfactory
        self.applet_button = '/usr/share/avant-window-navigator/applets/SundaraMenu/logo.png'

        self.applet.icon.file(self.applet_button, size=awnlib.Icon.APPLET_SIZE)
        #Connect to signals
        self.applet.connect('button-press-event', self.button_press)
        self.applet.connect_size_changed(self.size_changed)
        #self.theme.connect('changed', self.icon_theme_changed)
        from Menu_Main import Main_Menu
        self.hwg = Main_Menu(self.HideMenu)
        #print self.hwg.window.window.is_visible()
        gobject.timeout_add(500, self.HideMenu)
        show_window = self.hwg.show_window

        def _show_window():
            if time.time() - Main_Menu.last_click > 2:
                return
            return show_window()

        self.hwg.show_window = _show_window

    def size_changed(self):
        self.applet.icon.file(self.applet_button, size=awnlib.Icon.APPLET_SIZE)

    def button_press(self, widget, event):
        if event.type == gtk.gdk.BUTTON_PRESS and event.button in (1, 2):
            if not self.hwg.window.window:
                Main_Menu.last_click = time.time()
                self.ShowMenu()
            else:
                if not self.hwg.window.window.is_visible():
                    Main_Menu.last_click = time.time()
                    self.ShowMenu()
                else:
                    self.HideMenu()

        elif event.button == 3:
            self.HideMenu()

    def ShowMenu(self):
        # Display the start menu!!!
        origin = self.applet.get_window().get_origin()

        self.hwg.Adjust_Window_Dimensions(
            origin[0] - (self.Globals.MenuWidth / 2),
            origin[1] + self.applet.get_size()
        )  #self.applet.get_window().get_geometry()[3]/2 -10)
        self.hwg.show_window()

    def HideMenu(self):
        if self.hwg:
            if self.hwg.window.window:
                if self.hwg.window.window.is_visible() == True:
                    self.hwg.hide_window()

    def setup_context_menu(self):

        #Create the items for Preferences and About
        self.prefs = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
        self.about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
        self.edit = gtk.ImageMenuItem(gtk.STOCK_EDIT)

        #Connect the two items to functions when clicked
        self.prefs.connect("activate", self.properties)
        self.about.connect("activate", self.about_info)
        self.edit.connect("activate", self.edit_menus)

        #Now create the menu to put the items in and show it
        self.menu = self.applet.dialog.menu
        self.menu.append(self.prefs)
        self.menu.append(self.about)
        self.menu.append(self.edit)
        self.menu.show_all()


#		self.menu.popup(None, None, None, event.button, event.time)

    def properties(self, event=0, data=None):
        #os.spawnvp(os.P_WAIT,Globals.ProgramDirectory+"SundaraMenu-Settings.py",[Globals.ProgramDirectory+"SundaraMenu-Settings.py"])
        os.system("/bin/sh -c '" + self.Globals.ProgramDirectory +
                  "SundaraMenu-Settings.py' &")
        # Fixme, reload stuff properly
        self.Globals.ReloadSettings()

    def about_info(self, event=0, data=None):
        os.system("/bin/sh -c " + INSTALL_PREFIX + "'/lib/" +
                  self.Globals.appdirname +
                  "/SundaraMenu-Settings.py --about' &")

    def edit_menus(self, event=0, data=None):
        os.spawnvp(os.P_WAIT, "zorin-menu-editor", ["zorin-menu-editor"])
コード例 #12
0
	def __init__(self,applet,iid):
		""" We have to use gconf properties for the applet since standard funcs for getting position, size, orientation dont really work"""
		self.applet = applet
		self.applet.set_name("GnoMenu")
		self.remove_applet_border()
		self.timeout_interval = 200
		self.panel_size = 24
		self.Button_state = 0 # 0 = No change  1 = Mouse over  2 = Depressed
		self.tooltip_text = "Consolidated menu for the Gnome desktop"
		self.hwg = None
		self.gconf_client = gconf.client_get_default()
		self.gconfkey = self.applet.get_preferences_key()
		self.get_panel_properties()
		self.store_settings()
		print self.size

		######Create all the necessary get widgets in the panel##############
		#####################################################################
		self.Main_icon_box = gtk.Fixed()
		self.ev_box = gtk.EventBox()
		self.Main_icon_box.put(self.ev_box,0,0)
		self.applet.add(self.Main_icon_box)
		self.ev_box.set_border_width(0)
		self.ev_box.set_visible_window(0)
		self.Main_icon_box.set_border_width(0)
		self.image_icon = gtk.Image()
		self.ev_box.add(self.image_icon)				
		im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])
		w = im.get_width()
		h = im.get_height()
		self.scale = float(self.size)/float(h)
		self.w = w*self.scale
		self.h = self.size
		if Globals.ButtonLabelCount == 1:
			self.set_button_label()

		pixmap = im.scale_simple(int(self.w),int(self.h),gtk.gdk.INTERP_HYPER)
		im = None
		if Globals.flip == False and Globals.ButtonHasTop == 1:
			pixmap = pixmap.flip(Globals.flip)

		self.image_icon.set_from_pixbuf(pixmap)

		
		
		self.applet.set_background_widget(self.applet)
		self.applet.connect("destroy",self.cleanup)
	        self.applet.connect("destroy-event",self.cleanup)
	        self.applet.connect("delete-event",self.cleanup)
	        self.applet.connect("change-orient",self.change_orientation)
      		self.applet.connect("size-allocate", self.size_allocate_event)
		self.ev_box.connect("button-press-event",self.button_press)
		self.ev_box.connect("enter-notify-event", self.select_box)
		self.ev_box.connect("leave-notify-event", self.deselect_box)




		#####Show welcome screen on first run Launch the welcome screen#######
		######################################################################

		if Globals.FirstUse:
			os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+Globals.appdirname+"/GnoMenu-Settings.py --welcome' &")


		self.old_origin = None
		self.oldsize = 0
		self.x,self.y = 0,0
		self.oldx,self.oldy = 0,0
		self.aux = None
		self.applet.show_all()
		#self.callback = gobject.timeout_add(1000,self.timeout_callback)
		self.ev_box.set_size_request(-1,self.size)
		self.Main_icon_box.set_size_request(-1,self.size )
		self.image_icon.set_size_request(-1,self.size)

		if Globals.ShowTop == 1:
			#Create auxiliary window (CAIRO)
			from Panel_Top import PanelTopWindow
			self.aux = PanelTopWindow()
			self.aux.aux_window.connect("enter-notify-event", self.select_box)
			self.aux.aux_window.connect("leave-notify-event", self.deselect_box)
			self.aux.aux_window.connect("button-press-event",self.button_press)
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		self.hwg = Main_Menu(self.HideMenu)
		self.hwg.connect('state-changed',self.button_changed)
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		Globals.SavedOriginState = self.x,self.y
コード例 #13
0
ファイル: main.py プロジェクト: solo2101/Tilo-Menu
class Tilo(plasmascript.Applet):
    def __init__(self,parent,args=None):
        plasmascript.Applet.__init__(self,parent)
	self.parent = parent
 
    def init(self):
        self.setHasConfigurationInterface(False)
	#self.setBackgroundHints(Plasma.Applet.TranslucentBackground)
        self.resize(125, 125)
        self.setAspectRatioMode(Plasma.Square)
       # self.theme = Plasma.Svg(self)
      #  self.theme.setImagePath("widgets/background")
      #  self.setBackgroundHints(Plasma.Applet.TranslucentBackground)
        self.layout = QGraphicsLinearLayout(self.applet)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
    #    self.icon = Plasma.IconWidget()
    #    self.layout.addItem(self.icon)
        self.icon = Plasma.IconWidget()
        self.layout.addItem(self.icon)
	self.connect(self.icon, SIGNAL("clicked()"), self.iconClicked)



	print self.package().path() + "contents/icons/logo.png"

	from Menu_Main import Main_Menu
	self.hwg = Main_Menu(self.HideMenu)
	import Globals as Globals
	self.Globals = Globals
	if Globals.Settings['Distributor_Logo']:
		import IconFactory as iconfactory
		self.iconfactory = iconfactory
	        self.icon.setIcon(KIcon('distributor-logo'))

	else:
		self.icon.setIcon(KIcon(self.package().path() + "contents/icons/logo.svg"))
        self.icon.update()


	self.show = False
	print self.popupPosition(QSize(Globals.MenuWidth,Globals.MenuHeight))


    def contextualActions(self):
	newActions = []

	loop1 = QAction("", self.applet)
	loop1.setSeparator(True)

	EditMenus = QAction(KIcon(""), "Edit Menus" , self.applet )
	self.connect(EditMenus, SIGNAL("triggered()"), self.edit_menus )
	EditMenus.setIconVisibleInMenu(False)

	Properties = QAction(KIcon(""), "Properties" , self.applet )
	self.connect(Properties, SIGNAL("triggered()"), self.properties)
	Properties.setIconVisibleInMenu(False)

	About = QAction(KIcon(""), "About" , self.applet )
	self.connect(About, SIGNAL("triggered()"), self.about_info )
	About.setIconVisibleInMenu(False)


	newActions.append(loop1)
	newActions.append(EditMenus)
	newActions.append(Properties)
	newActions.append(About)


        return newActions

    def edit_menus(self):
	os.system(self.Globals.Settings['MenuEditor'] + ' &')
		#ConstructMainMenu()

    def about_info(self):
	os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+self.Globals.appdirname+"/Tilo-Settings.py --about' &")

    def properties(self):

	#os.spawnvp(os.P_WAIT,Globals.ProgramDirectory+"Tilo-Settings.py",[Globals.ProgramDirectory+"Tilo-Settings.py"])
	os.system("/bin/sh -c '"+self.Globals.ProgramDirectory+"Tilo-Settings.py' &")
	# Fixme, reload stuff properly


    def iconClicked(self):
	print 'clicked'
	self.ShowMenu()


    def ShowMenu(self):
	if self.show == False:

		#rootwin = self.hwg.window.get_screen().get_root_window()
		#x, y, mods = rootwin.get_pointer()
		x = self.popupPosition(QSize(self.Globals.MenuWidth,self.Globals.MenuHeight)).x()
		y = self.popupPosition(QSize(self.Globals.MenuWidth,self.Globals.MenuHeight)).y()
		screen = QDesktopWidget().screenGeometry()
		if self.hwg:
			if not self.hwg.window.window:
				print y + (self.Globals.MenuHeight/2) , screen.height()/2
				if y + (self.Globals.MenuHeight/2) < screen.height()/2:
					backend.save_setting('orientation', 'top')
				else:
					backend.save_setting('orientation', 'bottom')				
		self.hwg.Adjust_Window_Dimensions(x,y)
		self.hwg.show_window()
		self.show = True
	else:
		self.HideMenu()

    def HideMenu(self):
	self.show = False
	if self.hwg:
		if self.hwg.window.window:
			if self.hwg.window.window.is_visible()== True:
				self.hwg.hide_window()

 
    def paintInterface(self, painter, option, rect):
	pass
コード例 #14
0
class GnoMenu():


	def __init__(self):
		self.tray = gtk.StatusIcon()

		#app = gnomeapplet.Applet()
		#g = GnoMenu(app,"")
		self.tray.connect("activate", self.ShowMenu)
		self.tray.connect("popup-menu", self.show_menu)
		self.menu = gtk.Menu()
		self.m = gtk.Menu()
		add_image_menuitem(self.menu, gtk.STOCK_PROPERTIES, _("Preferences"), self.properties)
		add_image_menuitem(self.menu, gtk.STOCK_ABOUT, _("About"), self.about_info)
		add_image_menuitem(self.menu, gtk.STOCK_EDIT, _("Edit Menus"), self.edit_menus)
		add_image_menuitem(self.menu, gtk.STOCK_QUIT, _("Quit"), self.end)

		self.tray.set_tooltip("GnoMenu")
		self.tray.set_visible(True)

		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		import Globals as Globals
		self.Globals = Globals
		if Globals.Settings['Distributor_Logo']:
			import IconFactory as iconfactory
			self.iconfactory = iconfactory
			self.applet_button = self.iconfactory.GetSystemIcon('distributor-logo')
		else: self.applet_button = self.Globals.Applogo
		pixbuf = gtk.gdk.pixbuf_new_from_file(self.applet_button)
		self.tray.set_from_pixbuf(pixbuf)
		self.show = False
		gtk.main()		
		#app.reparent(main_window)


	def end(self,widget,event=None):
		self.hwg.destroy()
		gtk.main_quit()

	def edit_menus(self,event, data=None):
		os.system(self.Globals.Settings['MenuEditor'] + ' &')
		#ConstructMainMenu()

	def show_menu(self, status_icon, button, activate_time):
		self.menu.popup(None, None, None, button,  activate_time)
		self.menu.show_all()

	def about_info(self,event,data=None):

		os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+self.Globals.appdirname+"/GnoMenu-Settings.py --about' &")

	def properties(self,event,data=None):

		#os.spawnvp(os.P_WAIT,Globals.ProgramDirectory+"GnoMenu-Settings.py",[Globals.ProgramDirectory+"GnoMenu-Settings.py"])
		os.system("/bin/sh -c '"+self.Globals.ProgramDirectory+"GnoMenu-Settings.py' &")
		# Fixme, reload stuff properly

	def ShowMenu(self,widget):
		if self.show == False:


			#rootwin = self.hwg.window.get_screen().get_root_window()
			#x, y, mods = rootwin.get_pointer()
			x,y,z = gtk.status_icon_position_menu(self.m, self.tray)
			if self.hwg:
				if not self.hwg.window.window:
					if y < gtk.gdk.screen_height()/2:
						backend.save_setting('orientation', 'top')
					else:
						backend.save_setting('orientation', 'bottom')				
			self.hwg.Adjust_Window_Dimensions(x,y)
			self.hwg.show_window()
			self.show = True
		else:
			self.HideMenu()

	def HideMenu(self):
		self.show = False
		if self.hwg:
			if self.hwg.window.window:
				if self.hwg.window.window.is_visible()== True:
					self.hwg.hide_window()
コード例 #15
0
ファイル: Tilo.py プロジェクト: solo2101/Tilo-Menu
class Tilo ():
	icons = {}
	def __init__(self, applet):
		self.applet = applet
		self.applet.set_tooltip_text("Tilo")
		#print self.applet.get_size()
		#print self.applet.get_position()
		if self.applet.get_pos_type() == gtk.POS_TOP:
			backend.save_setting('orientation', 'top')
		else:
			backend.save_setting('orientation', 'bottom')
		#Get the default icon theme
		import Globals as Globals
		self.Globals = Globals
		self.theme = gtk.icon_theme_get_default()
		self.icons['stock_folder'] = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[0])
	        self.setup_context_menu()

		if Globals.Settings['Distributor_Logo']:
			import IconFactory as iconfactory
			self.iconfactory = iconfactory
			self.applet_button = self.iconfactory.GetSystemIcon('distributor-logo')
		else: self.applet_button = Globals.Applogo

		self.applet.icon.file(self.applet_button, size=awnlib.Icon.APPLET_SIZE)
		#Connect to signals
		self.applet.connect('button-press-event', self.button_press)
		self.applet.connect_size_changed(self.size_changed)
		#self.theme.connect('changed', self.icon_theme_changed)
		from Menu_Main import Main_Menu
		self.hwg = Main_Menu(self.HideMenu)
		#print self.hwg.window.window.is_visible()

	def size_changed(self):
		self.applet.icon.file(self.applet_button, size=awnlib.Icon.APPLET_SIZE)


	def button_press(self, widget, event):
		if event.button in (1, 2):
			if not self.hwg.window.window:
				self.ShowMenu()
			else:
				if not self.hwg.window.window.is_visible():
					self.ShowMenu()
				else: self.HideMenu()

		elif event.button == 3:
			self.HideMenu()


	def ShowMenu(self):
		# Display the start menu!!!
		origin = self.applet.get_window().get_origin()
		
		self.hwg.Adjust_Window_Dimensions(origin[0] - (self.Globals.MenuWidth/2),origin[1]+self.applet.get_size())#self.applet.get_window().get_geometry()[3]/2 -10)
		self.hwg.show_window()

	def HideMenu(self):
		if self.hwg:
			if self.hwg.window.window:
				if self.hwg.window.window.is_visible()== True:
					self.hwg.hide_window()

	def setup_context_menu(self):

		#Create the items for Preferences and About
		self.prefs = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
		self.about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
		self.edit = gtk.ImageMenuItem(gtk.STOCK_EDIT)
	
		#Connect the two items to functions when clicked
		self.prefs.connect("activate", self.properties)
		self.about.connect("activate", self.about_info)
		self.edit.connect("activate", self.edit_menus)

	
		#Now create the menu to put the items in and show it
		self.menu = self.applet.dialog.menu
		self.menu.append(self.prefs)
		self.menu.append(self.about)
		self.menu.append(self.edit)
		self.menu.show_all()
#		self.menu.popup(None, None, None, event.button, event.time)
		

	def properties(self,event=0,data=None):
		#os.spawnvp(os.P_WAIT,Globals.ProgramDirectory+"Tilo-Settings.py",[Globals.ProgramDirectory+"Tilo-Settings.py"])
		os.system("/bin/sh -c '"+self.Globals.ProgramDirectory+"Tilo-Settings.py' &")
		# Fixme, reload stuff properly
		self.Globals.ReloadSettings()
		
	def about_info(self,event=0,data=None):
		os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+self.Globals.appdirname+"/Tilo-Settings.py --about' &")

	def edit_menus(self,event=0, data=None):
		os.spawnvp(os.P_WAIT,"mozo",["mozo"])
コード例 #16
0
ファイル: GnoMenu.py プロジェクト: jindongyang/gnomenu
class GnoMenu(gnomeapplet.Applet):

	def __init__(self,applet,iid):
		self.panel_size = 24
		self.Button_state = 0 # 0 = No change  1 = Mouse over  2 = Depressed
		self.applet = applet
		self.applet.set_name(Globals.name)
		self.remove_applet_border()
		self.panel_id = None
		self.hwg = None
		orient = None
		try:
			orient = self.applet.get_orient()
		except:pass

		self.orientation = None
		if orient == 1:
			self.orientation = 'top'
		else:
			self.orientation = 'bottom'

		self.gconf_client = gconf.client_get_default()
		self.gconfkey = self.applet.get_preferences_key()
		if self.orientation == 'top':
			Globals.flip = False
		elif self.orientation == 'bottom':
			Globals.flip = None
		else : self.size = 30
		self.size = self.get_panel_size()
		self.store_settings()
		self.Fixed = gtk.Fixed()
		self.EBox = gtk.EventBox()
		self.EBox.set_tooltip_text(Globals.name)
		self.Fixed.put(self.EBox,0,0)
		self.applet.add(self.Fixed)
		self.EBox.set_border_width(0)
		self.EBox.set_visible_window(0)
		self.Fixed.set_border_width(0)
		self.size = self.get_panel_size()
		self.Image = gtk.Image()
		if Globals.Settings["Distributor_Logo"] == 1:
			im = gtk.gdk.pixbuf_new_from_file_at_size(Globals.distro_logo,self.size,self.size)
			if self.Button_state == 1:
				im.saturate_and_pixelate(im, 1.5, False)
			elif self.Button_state == 2:
				im.saturate_and_pixelate(im, 0.0, False)
			pixmap = im

		else:			
			im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])

		w = im.get_width()
		h = im.get_height()
		self.scale = float(self.size)/float(h)
		if Globals.ButtonLabelCount == 1 and Globals.Settings["Distributor_Logo"] == 0:
			self.set_button_label()

		pixmap = im.scale_simple(int(w*self.scale),int(self.size),gtk.gdk.INTERP_HYPER)
		im = None
		if Globals.flip == False and Globals.ButtonHasTop == 1:
			pixmap = pixmap.flip(Globals.flip)

		self.Image.set_from_pixbuf(pixmap)
		self.EBox.add(self.Image)
		self.applet.set_background_widget(self.applet)
		self.applet.set_events(gtk.gdk.ALL_EVENTS_MASK)
		self.applet.connect("destroy",self.cleanup)
	        self.applet.connect("destroy-event",self.cleanup)
	        self.applet.connect("delete-event",self.cleanup)
	        self.applet.connect("change-orient",self.change_orientation)
      		self.applet.connect("size-allocate", self.size_allocate_event)
      		self.applet.connect("map-event", self.map_event)
		self.EBox.connect("button-press-event",self.button_press)
		self.EBox.connect("enter-notify-event", self.select_box)
		self.EBox.connect("leave-notify-event", self.deselect_box)
		self.old_origin = None
		self.oldsize = 0
		self.x,self.y = 0,0
		self.oldx,self.oldy = 0,0
		self.aux = None
		self.applet.show_all()
		self.applet.realize()
		self.EBox.realize()
		#self.callback = gobject.timeout_add(1000,self.timeout_callback)
		self.EBox.set_size_request(-1,self.size)
		self.Fixed.set_size_request(-1,self.size )
		self.Image.set_size_request(-1,self.size)



	def store_settings(self):
		"""Stores orientation in settings"""
		if self.orientation != backend.load_setting("orientation"):
			if self.orientation is None:
				backend.save_setting('orientation', 'bottom')
				backend.save_setting('size', self.size)
			else:
				utils.show_message(_('Menu needs to restart , restart now?'))
				backend.save_setting('orientation', self.orientation)
				backend.save_setting('size', self.size)
				sys.exit()
		try:
			backend.save_setting('orientation', self.orientation)
			backend.save_setting('size', self.size)
		except:pass


	def get_panel_size(self):
		if self.gconfkey != None:
			self.gconfkey = str(self.gconfkey).replace('/prefs','')
			self.panel_id = self.gconf_client.get_string(self.gconfkey + "/toplevel_id")			

		if self.panel_id != None:				
			self.size = int(self.gconf_client.get_int("/apps/panel/toplevels/" + self.panel_id + "/size"))
			self.gconf_client.add_dir("/apps/panel/toplevels/" + self.panel_id + "/size",gconf.CLIENT_PRELOAD_NONE)
			self.gconf_client.notify_add("/apps/panel/toplevels/" + self.panel_id + "/size", self.update_panel_size) 
			return int(self.size)
		else: 

			try:
				self.size= self.applet.get_size()
			except:
				self.size = 30
			return self.size


	def set_button_label(self):
		self.Label = gtk.Label()
		self.txt = Globals.ButtonLabelMarkup
		try:
			self.txt = self.txt.replace(Globals.ButtonLabelName,_(Globals.ButtonLabelName))
		except:pass
		self.Fixed.put(self.Label,int(self.scale*Globals.ButtonLabelX),int(self.scale*Globals.ButtonLabelY))
		self.set_button_label_size()

	def set_button_label_size(self):
		if Globals.Settings["Distributor_Logo"] == 0:
			im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])
			w = im.get_width()
			h = im.get_height()
			im = None
			self.txt = Globals.ButtonLabelMarkup
			try:
				self.txt = self.txt.replace(Globals.ButtonLabelName,_(Globals.ButtonLabelName))
			except:pass
			self.scale = float(self.size)/float(h)
			self.Fixed.move(self.Label,int(self.scale*Globals.ButtonLabelX),int(self.scale*Globals.ButtonLabelY))
			self.Label.set_size_request(-1,self.size)
			self.txt_font = self.txt[self.txt.find("font_desc='")+11:]
			self.txt_size = int(self.txt_font[:self.txt_font.find("'")].split(' ').pop())
			self.txt_all = self.txt_font.replace(str(self.txt_size),str(int(self.txt_size*self.scale)))
			self.txt = self.txt.replace(self.txt_font,self.txt_all)
			self.Label.set_markup(self.txt)	

	def remove_applet_border(self):
      		gtk.rc_parse_string ("""
	               style \"GnoMenu-style\"
	               {
	                 GtkWidget::focus-line-width = 0
	                 GtkWidget::focus-padding = 0
	               }
	               widget \"*.GnoMenu\" style \"GnoMenu-style\"
	               """)

	def change_orientation(self,arg1,data):
		orient = self.applet.get_orient()
		self.orientation = None
		if orient == 1:
			self.orientation = 'top'
		else:
			self.orientation = 'bottom'
		if self.orientation != backend.load_setting("orientation"):
			if self.orientation is None:
				backend.save_setting('orientation', 'bottom')
				backend.save_setting('size', self.size)
			else:
				utils.show_message(_('Menu needs to restart , restart now?'))
				backend.save_setting('orientation', self.orientation)
				backend.save_setting('size', self.size)
				sys.exit()

	def map_event(self, widget, event):
		print 'map'
		if Globals.ShowTop == 1 and  Globals.Settings["Distributor_Logo"] == 0:
			#Create auxiliary window (CAIRO)
			from Panel_Top import PanelTopWindow
			self.aux = PanelTopWindow()
			self.aux.aux_window.connect("enter-notify-event", self.select_box)
			self.aux.aux_window.connect("leave-notify-event", self.deselect_box)
			self.aux.aux_window.connect("button-press-event",self.button_press)
		self.Redraw_graphics()
		self.Update_Panel_Top()
		if Globals.ShowTop == 1 and Globals.Settings["Distributor_Logo"] == 0:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		self.hwg = Main_Menu(self.HideMenu)
		self.hwg.connect('state-changed',self.button_changed)
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		Globals.SavedOriginState = self.x,self.y

	def size_allocate_event(self, widget, allocation):
		if widget.window:		
			self.x, self.y = widget.window.get_origin()
			self.update_panel_position()
		else:
			self.x, self.y = 0,0		
		return True

	def update_panel_position(self):
		if self.x != self.oldx and self.hwg != None:
			print 'position changed'
			self.Redraw_graphics()
			self.Update_Panel_Top()
			if Globals.ShowTop == 1 and self.aux != None and Globals.Settings["Distributor_Logo"] == 0:
				self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
			#self.hwg = Main_Menu(self.HideMenu)
			self.hwg.Adjust_Window_Dimensions(self.x,self.y)
			Globals.SavedOriginState = self.x,self.y
			self.oldx= self.x
			if Globals.ButtonLabelCount == 1:
				self.set_button_label_size()

	def update_panel_size(self,client, connection_id, entry, args):
		if entry.get_key() == "/apps/panel/toplevels/%s/size" % self.panel_id:
			try:
				self.size = entry.get_value().get_int()
			except:self.size = 30
		if self.size != self.oldsize and self.hwg :
			print 'size changed'
			self.Redraw_graphics()
			self.Update_Panel_Top()
			if Globals.ShowTop == 1 and self.aux != None and Globals.Settings["Distributor_Logo"] == 0:
				self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
			#self.hwg = Main_Menu(self.HideMenu)
			self.hwg.Adjust_Window_Dimensions(self.x,self.y)
			Globals.SavedOriginState = self.x,self.y
			self.oldsize= self.size
			if Globals.ButtonLabelCount == 1:
				self.set_button_label_size()
					
		return True

	def auxdestroyed(self):	
		#Respawn point for the aux window if it has been Alt-F4ed
		if Globals.ShowTop == 1:
			#Used in this instance for providing delay for window to be created
			self.aux = PanelTopWindow()
			#self.aux.Create(self, 0)	 #Create the orb top
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
				

	def button_press(self,widget,event):
		if event.button == 1:
			# Remove this next line when orb top repositioning on widget move is fixed
			if Globals.ShowTop == 1:
				pass
				#self.window_moved(self.aux)
			if not self.hwg.window.window:
				self.hwg.Adjust_Window_Dimensions(self.x,self.y)
				self.ShowMenu()
				self.Button_state = 2
			else:
				if self.Button_state == 2:
					self.HideMenu()
					self.Button_state = 1

				else:
					self.hwg.Adjust_Window_Dimensions(self.x,self.y)
					self.ShowMenu()
					self.Button_state = 2

	
			self.Redraw_graphics()
			#self.Update_Panel_Top()
		elif event.button == 3:
			self.create_menu()
					
	def create_menu(self):

		self.propxml="""
		<popup name="button3">
		<menuitem name="About Item" verb="About" stockid="gtk-about"/>
		</popup>
		"""
		self.verbs = [ ( "About", self.about_info ) ]
		self.applet.setup_menu(self.propxml,self.verbs,None)
			

	def edit_menus(self,event, data=None):
		os.spawnvp(os.P_WAIT,Globals.Settings['MenuEditor'],[Globals.Settings['MenuEditor']])
		#ConstructMainMenu()

	def about_info(self,event,data=None):

		os.system("/bin/sh -c '%s/lib/%s/GnoMenu-Settings.py --about' &" %( INSTALL_PREFIX, Globals.appdirname))

	def properties(self,event,data=None):

		os.system("/bin/sh -c '%sGnoMenu-Settings.py' &" % Globals.ProgramDirectory)
		# Fixme, reload stuff properly
		Globals.ReloadSettings()
		
	def select_box(self,widget,event):
		if self.Button_state == 0:
			self.Button_state = 1
		self.Redraw_graphics()
		
	def deselect_box(self,widget,event):
		if self.Button_state == 1:
			self.Button_state = 0
		self.Redraw_graphics()
		
	def button_changed(self,event,button,button1):
		self.Button_state = button
		self.Redraw_graphics()
		self.Update_Panel_Top()
		if Globals.ShowTop == 1 and Globals.Settings["Distributor_Logo"] == 0:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		print button

		
	def cleanup(self,event):
		print "cleanup"

		self.hwg.destroy()
		if Globals.ShowTop == 1:
			Globals.ShowTop = 0
			self.aux.destroy()
		#gtk.main_quit()
		del self.applet
	
	def ShowMenu(self):
		# Display the start menu!!!
		origin = self.applet.window.get_origin()
		try:
			if origin != Globals.SavedOriginState:
				self.hwg.Adjust_Window_Dimensions(origin[0],origin[1])
		except:pass
		if self.hwg:
			self.hwg.show_window()
		try:
			self.aux.aux_window.window.set_transient_for(self.hwg.window)
			self.hwg.window.window.set_transient_for(self.applet.window)
		except:pass

	def HideMenu(self):
		if self.hwg:
			if self.hwg.window.window:
				if self.hwg.window.window.is_visible()== True:
					self.hwg.hide_window()

		self.Button_state = 0
		self.Redraw_graphics()

	def Redraw_graphics (self):
		self.Fixed.set_size_request(-1,self.size)
		self.EBox.set_size_request(-1,self.size)
		self.Image.set_size_request(-1,self.EBox.allocation.height)
		if Globals.Settings["Distributor_Logo"] == 1:
			im = gtk.gdk.pixbuf_new_from_file_at_size(Globals.distro_logo,self.size,self.size)
			if self.Button_state == 1:
				im.saturate_and_pixelate(im, 1.5, False)
			elif self.Button_state == 2:
				im.saturate_and_pixelate(im, 0.0, False)
			pixmap = im

		else:
			im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])
			w = im.get_width()
			h = im.get_height()
			self.scale = float(self.size)/float(h)
			pixmap = im.scale_simple(int(w*self.scale),self.size,gtk.gdk.INTERP_HYPER)

		if Globals.flip == False and Globals.ButtonHasTop == 1:
			pixmap = pixmap.flip(Globals.flip)
			
		self.Image.set_from_pixbuf(pixmap)
		if Globals.ShowTop == 1 and self.aux != None and Globals.Settings["Distributor_Logo"] == 0:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		im = None
		pixmap = None

	def Update_Panel_Top(self,widget=None, event=None):

		if Globals.ShowTop == 1 and self.aux != None and Globals.Settings["Distributor_Logo"] == 0:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
			self.applet.queue_draw()
			self.aux.aux_window.window.set_transient_for(self.applet.window)
			if self.scale:
				self.aux.set_scale(self.scale)
			StartButtonTopHeight = self.aux.get_height()
			print "Reorientating Orb top!! (Don't let this happen too often!!)"
			Window_x =  self.x
			if self.orientation == 'top':
				Window_y =  0 + self.size
			else:
				Window_y =  Globals.screenheight - self.size - StartButtonTopHeight
			# Calculate midpoint of screen
			self.screenmidpty = int(Globals.screenheight / 2)
			# Work out orientation of panel 
			self.aux.move(Window_x,Window_y)
コード例 #17
0
ファイル: Tilo_rewrite.py プロジェクト: solo2101/Tilo-Menu
class Tilo(mateapplet.Applet):
	global Button_state
	def __init__(self,applet,iid):
		""" We have to use mateconf properties for the applet since standard funcs for getting position, size, orientation dont really work"""
		self.applet = applet
		self.applet.set_name("Tilo")
		self.remove_applet_border()
		self.timeout_interval = 200
		self.panel_size = 24
		self.Button_state = 0 # 0 = No change  1 = Mouse over  2 = Depressed
		self.tooltip_text = "Consolidated menu for the Mate desktop"
		self.hwg = None
		self.mateconf_client = mateconf.client_get_default()
		self.mateconfkey = self.applet.get_preferences_key()
		self.get_panel_properties()
		self.store_settings()
		print self.size

		######Create all the necessary get widgets in the panel##############
		#####################################################################
		self.Main_icon_box = gtk.Fixed()
		self.ev_box = gtk.EventBox()
		self.Main_icon_box.put(self.ev_box,0,0)
		self.applet.add(self.Main_icon_box)
		self.ev_box.set_border_width(0)
		self.ev_box.set_visible_window(0)
		self.Main_icon_box.set_border_width(0)
		self.image_icon = gtk.Image()
		self.ev_box.add(self.image_icon)				
		im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])
		w = im.get_width()
		h = im.get_height()
		self.scale = float(self.size)/float(h)
		self.w = w*self.scale
		self.h = self.size
		if Globals.ButtonLabelCount == 1:
			self.set_button_label()

		pixmap = im.scale_simple(int(self.w),int(self.h),gtk.gdk.INTERP_HYPER)
		im = None
		if Globals.flip == False and Globals.ButtonHasTop == 1:
			pixmap = pixmap.flip(Globals.flip)

		self.image_icon.set_from_pixbuf(pixmap)

		
		
		self.applet.set_background_widget(self.applet)
		self.applet.connect("destroy",self.cleanup)
	        self.applet.connect("destroy-event",self.cleanup)
	        self.applet.connect("delete-event",self.cleanup)
	        self.applet.connect("change-orient",self.change_orientation)
      		self.applet.connect("size-allocate", self.size_allocate_event)
		self.ev_box.connect("button-press-event",self.button_press)
		self.ev_box.connect("enter-notify-event", self.select_box)
		self.ev_box.connect("leave-notify-event", self.deselect_box)




		#####Show welcome screen on first run Launch the welcome screen#######
		######################################################################

		if Globals.FirstUse:
			os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+Globals.appdirname+"/Tilo-Settings.py --welcome' &")


		self.old_origin = None
		self.oldsize = 0
		self.x,self.y = 0,0
		self.oldx,self.oldy = 0,0
		self.aux = None
		self.applet.show_all()
		#self.callback = gobject.timeout_add(1000,self.timeout_callback)
		self.ev_box.set_size_request(-1,self.size)
		self.Main_icon_box.set_size_request(-1,self.size )
		self.image_icon.set_size_request(-1,self.size)

		if Globals.ShowTop == 1:
			#Create auxiliary window (CAIRO)
			from Panel_Top import PanelTopWindow
			self.aux = PanelTopWindow()
			self.aux.aux_window.connect("enter-notify-event", self.select_box)
			self.aux.aux_window.connect("leave-notify-event", self.deselect_box)
			self.aux.aux_window.connect("button-press-event",self.button_press)
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		self.hwg = Main_Menu(self.HideMenu)
		self.hwg.connect('state-changed',self.button_changed)
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		Globals.SavedOriginState = self.x,self.y


	def get_panel_properties(self):
		if self.mateconfkey != None:
			self.mateconfkey = str(self.mateconfkey).replace('/prefs','')
			self.panel_id = self.mateconf_client.get_string(self.mateconfkey + "/toplevel_id")
			self.size = int(self.mateconf_client.get_int("/apps/panel/toplevels/" + self.panel_id + "/size"))
			self.x = self.mateconf_client.get_int(self.mateconfkey + "/position")
			try:
				orient = self.applet.get_orient()
			except:
				orient = 0
			if orient == 1:
				self.orientation = 'top'
			else:
				self.orientation = 'bottom'
			if self.orientation == 'top':
				self.y = gtk.gdk.screen_height() - self.size
			else:
				self.y = self.size
			self.mateconf_client.add_dir("/apps/panel/toplevels/" + self.panel_id + "/size",mateconf.CLIENT_PRELOAD_NONE)
			self.mateconf_client.notify_add("/apps/panel/toplevels/" + self.panel_id + "/size", self.update_panel_size) 
		else:
			self.size = 30
			self.orientation = 'bottom'
			self.x = 0
			self.y = 0

	def store_settings(self):
		"""Stores orientation in settings"""
		if self.orientation != backend.load_setting("orientation"):
			if self.orientation == None:
				backend.save_setting('orientation', 'bottom')
				backend.save_setting('size', self.size)
			else:
				utils.show_message(_('Menu needs to restart , restart now?'))
				backend.save_setting('orientation', self.orientation)
				backend.save_setting('size', self.size)
				sys.exit()
		try:
			backend.save_setting('orientation', self.orientation)
			backend.save_setting('size', self.size)
		except:pass


	def get_panel_size(self):
		if self.mateconfkey != None:
			self.mateconfkey = str(self.mateconfkey).replace('/prefs','')
			self.panel_id = self.mateconf_client.get_string(self.mateconfkey + "/toplevel_id")			

		if self.panel_id != None:				
			self.size = int(self.mateconf_client.get_int("/apps/panel/toplevels/" + self.panel_id + "/size"))
			self.mateconf_client.add_dir("/apps/panel/toplevels/" + self.panel_id + "/size",mateconf.CLIENT_PRELOAD_NONE)
			self.mateconf_client.notify_add("/apps/panel/toplevels/" + self.panel_id + "/size", self.update_panel_size) 
			return int(self.size)
		else: 

			try:
				self.size= self.applet.get_size()
			except:
				self.size = 30
			return self.size


	def set_button_label(self):
		self.Label = gtk.Label()
		self.txt = Globals.ButtonLabelMarkup
		try:
			self.txt = self.txt.replace(Globals.ButtonLabelName,_(Globals.ButtonLabelName))
		except:pass
		self.Main_icon_box.put(self.Label,int(self.scale*Globals.ButtonLabelX),int(self.scale*Globals.ButtonLabelY))
		self.set_button_label_size()

	def set_button_label_size(self):
		im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])
		w = im.get_width()
		h = im.get_height()
		im = None
		self.txt = Globals.ButtonLabelMarkup
		try:
			self.txt = self.txt.replace(Globals.ButtonLabelName,_(Globals.ButtonLabelName))
		except:pass
		self.scale = float(self.size)/float(h)
		self.Main_icon_box.move(self.Label,int(self.scale*Globals.ButtonLabelX),int(self.scale*Globals.ButtonLabelY))
		self.Label.set_size_request(-1,self.size)
		self.txt_font = self.txt[self.txt.find("font_desc='")+11:]
		self.txt_size = int(self.txt_font[:self.txt_font.find("'")].split(' ').pop())
		self.txt_all = self.txt_font.replace(str(self.txt_size),str(int(self.txt_size*self.scale)))
		self.txt = self.txt.replace(self.txt_font,self.txt_all)
		self.Label.set_markup(self.txt)	

	def remove_applet_border(self):
      		gtk.rc_parse_string ("""
	               style \"Tilo-style\"
	               {
	                 GtkWidget::focus-line-width = 0
	                 GtkWidget::focus-padding = 0
	               }
	               widget \"*.Tilo\" style \"Tilo-style\"
	               """)



	def change_orientation(self,arg1,data):
		self.get_panel_properties()
		if self.orientation != backend.load_setting("orientation"):
			if self.orientation == None:
				backend.save_setting('orientation', 'bottom')
				backend.save_setting('size', self.size)
			else:
				utils.show_message(_('Menu needs to restart , restart now?'))
				backend.save_setting('orientation', self.orientation)
				backend.save_setting('size', self.size)
				sys.exit()
		

	def size_allocate_event(self, widget, allocation):
		if self.size != widget.allocation.height:
			if widget.allocation.height < 128: #weird bug giant button sometimes
				self.size = widget.allocation.height
				self.Redraw_graphics()
				self.Update_Panel_Top()
		if widget.window:		
			self.x, self.y = widget.window.get_origin()
			self.update_panel_position()
		else:
			self.x, self.y = 0,0		
		return True



	def update_panel_position(self):
		if self.x != self.oldx and self.hwg != None:
			print 'position changed'
			self.Redraw_graphics()
			self.Update_Panel_Top()
			if Globals.ShowTop == 1 and self.aux != None:
				self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
			#self.hwg = Main_Menu(self.HideMenu)
			self.hwg.Adjust_Window_Dimensions(self.x,self.y)
			Globals.SavedOriginState = self.x,self.y
			self.oldx= self.x
			if Globals.ButtonLabelCount == 1:
				self.set_button_label_size()

	
	def update_panel_size(self,client, connection_id, entry, args):
		
		
		
		if entry.get_key() == "/apps/panel/toplevels/" + self.panel_id + "/size":
			self.get_panel_properties()
		if self.size != self.oldsize and self.hwg :
			print 'size changed'
			self.Redraw_graphics()
			self.Update_Panel_Top()
			if Globals.ShowTop == 1 and self.aux != None:
				self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
			#self.hwg = Main_Menu(self.HideMenu)
			self.hwg.Adjust_Window_Dimensions(self.x,self.y)
			Globals.SavedOriginState = self.x,self.y
			self.oldsize= self.size
			if Globals.ButtonLabelCount == 1:
				self.set_button_label_size()
					
		return True

	def auxdestroyed(self):	
		#Respawn point for the aux window if it has been Alt-F4ed
		if Globals.ShowTop == 1:
			#Used in this instance for providing delay for window to be created
			self.aux = PanelTopWindow()
			#self.aux.Create(self, 0)	 #Create the orb top
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
				

	def button_press(self,widget,event):
	
		if event.button == 1:
			# Remove this next line when orb top repositioning on widget move is fixed
			if Globals.ShowTop == 1:
				pass
				#self.window_moved(self.aux)
			if self.Button_state == 2:
				self.HideMenu()
				self.Button_state = 1
			else:
				self.Button_state = 2
				self.Redraw_graphics()
				self.hwg.Adjust_Window_Dimensions(self.x,self.y)
				self.ShowMenu()
				
			self.Redraw_graphics()
			#self.Update_Panel_Top()
		elif event.button == 3:
			self.create_menu()
			
			
	def create_menu(self):

		self.propxml="""
		<popup name="button3">
		<menuitem name="Preferences" verb="Props" stockid="gtk-properties"/>
		<menuitem name="About Item" verb="About" stockid="gtk-about"/>
		<menuitem name="Edit Menus" verb="Edit" stockid="gtk-edit"/>
		</popup>
		"""
		self.verbs = [ ( "Props", self.properties ),
					   ( "About", self.about_info ),
					   ( "Edit", self.edit_menus) ]
		self.applet.setup_menu(self.propxml,self.verbs,None)
			

	def edit_menus(self,event, data=None):
		os.spawnvp(os.P_WAIT,Globals.Settings['MenuEditor'],[Globals.Settings['MenuEditor']])
		#ConstructMainMenu()

	def about_info(self,event,data=None):

		os.system("/bin/sh -c " + INSTALL_PREFIX +"'/lib/"+Globals.appdirname+"/Tilo-Settings.py --about' &")

	def properties(self,event,data=None):

		#os.spawnvp(os.P_WAIT,Globals.ProgramDirectory+"Tilo-Settings.py",[Globals.ProgramDirectory+"Tilo-Settings.py"])
		os.system("/bin/sh -c '"+Globals.ProgramDirectory+"Tilo-Settings.py' &")
		# Fixme, reload stuff properly
		Globals.ReloadSettings()
		
	def select_box(self,widget,event):
		if self.Button_state == 0:
			self.Button_state = 1
		self.Redraw_graphics()
		
	def deselect_box(self,widget,event):
		if self.Button_state == 1:
			self.Button_state = 0
		self.Redraw_graphics()
		

	def timeout_callback(self):

		if Globals.ShowTop == 1:
			#Create auxiliary window (CAIRO)
			from Panel_Top import PanelTopWindow
			self.aux = PanelTopWindow()
			self.aux.aux_window.connect("enter-notify-event", self.select_box)
			self.aux.aux_window.connect("leave-notify-event", self.deselect_box)
			self.aux.aux_window.connect("button-press-event",self.button_press)
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		self.hwg = Main_Menu(self.HideMenu)
		self.hwg.connect('state-changed',self.button_changed)
		self.hwg.Adjust_Window_Dimensions(self.x,self.y)
		Globals.SavedOriginState = self.x,self.y

		###### Hotkey Menu Activation ########################################
		######################################################################

		return False


	def button_changed(self,event,button,button1):
		self.Button_state = button
		self.Redraw_graphics()
		self.Update_Panel_Top()
		if Globals.ShowTop == 1:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		print button

		
	def cleanup(self,event):
		print "cleanup"

		self.hwg.destroy()
		if Globals.ShowTop == 1:
			Globals.ShowTop = 0
			self.aux.destroy()
		#os.system('rm ' +Globals.HomeDirectory + "/.menuiconcache.xml")
		#gtk.main_quit()
		del self.applet
	


	def ShowMenu(self):
		# Display the start menu!!!
		origin = self.applet.window.get_origin()
		try:
			if origin != Globals.SavedOriginState:
				self.hwg.Adjust_Window_Dimensions(origin[0],origin[1])
		except:pass
		while not hasattr(self,'hwg'):
			gtk.main_iteration()
		if self.hwg:
			self.hwg.show_window()

		#self.hwg.grab_focus()
	
	def HideMenu(self):
		if self.hwg:
			if self.hwg.window.window:
				if self.hwg.window.window.is_visible()== True:
					self.hwg.hide_window()

		self.Button_state = 0
		self.Redraw_graphics()

	def Redraw_graphics (self):
		self.Main_icon_box.set_size_request(-1,self.size)
		self.ev_box.set_size_request(-1,self.size)
		self.image_icon.set_size_request(-1,self.ev_box.allocation.height)
		im = gtk.gdk.pixbuf_new_from_file(Globals.StartButton[self.Button_state])
		w = im.get_width()
		h = im.get_height()
		self.scale = float(self.size)/float(h)

		pixmap = im.scale_simple(int(w*self.scale),self.size,gtk.gdk.INTERP_HYPER)
		if Globals.flip == False and Globals.ButtonHasTop == 1:
			pixmap = pixmap.flip(Globals.flip)
			
		self.image_icon.set_from_pixbuf(pixmap)
		if Globals.ShowTop == 1 and self.aux != None:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
		im = None
		pixmap = None

	def Update_Panel_Top(self,widget=None, event=None):

		if Globals.ShowTop == 1 and self.aux != None:
			self.aux.updateimage(Globals.StartButtonTop[self.Button_state ])
			self.applet.queue_draw()
			self.aux.aux_window.window.set_transient_for(self.applet.window)
			if self.scale:
				self.aux.set_scale(self.scale)
			StartButtonTopHeight = self.aux.get_height()
			print "Reorientating Orb top!! (Don't let this happen too often!!)"
			Window_x =  self.x
			if self.orientation == 'top':
				Window_y =  0 + self.size
			else:
				Window_y =  Globals.screenheight - self.size - StartButtonTopHeight
			# Calculate midpoint of screen
			self.screenmidpty = int(Globals.screenheight / 2)
			# Work out orientation of panel 
			self.aux.move(Window_x,Window_y)
			self.old_size = self.size