Example #1
0
	def submenushow(self,parent,name,ico,exe):
		favlist = backend.load_setting("favorites")
		#try:
		#add_image_menuitem(menu,ico, name, None,'1')
		#except:return
		self.sm =  gtk.Menu()
		
		add_menuitem(self.sm,name)
		add_menuitem(self.sm, "-")
		add_image_menuitem(self.sm, gtk.STOCK_DIALOG_AUTHENTICATION, _("Open as Administrator"), self.runasadmin,name, exe,ico,'1')
	
		if ('%s::%s::%s::1' %(name, exe, ico)) not in favlist:
			add_menuitem(self.sm, "-")
			add_image_menuitem(self.sm, gtk.STOCK_ADD, _("Add to Favorites"), self.addfav,name,exe, ico, '1')
	
		else:
			add_menuitem(self.sm, "-")
			add_image_menuitem(self.sm, gtk.STOCK_REMOVE, _("Remove from Favorites"), self.removefav,name, exe, ico, '1')

		add_menuitem(self.sm, "-")
		add_image_menuitem(self.sm, gtk.STOCK_HOME, _("Create Desktop Shortcut"), self.addshort,name, exe, ico, '1')
	
		add_menuitem(self.sm, "-")
		if ('%s.desktop' % name) in os.listdir(Globals.AutoStartDirectory):
			add_image_menuitem(self.sm, gtk.STOCK_REMOVE, _("Remove from System Startup"), self.remove_autostarter,name,  exe, ico, '1')
		else:
			add_image_menuitem(self.sm, gtk.STOCK_ADD, _("Add to System Startup"), self.create_autostarter,name, exe, ico, '1')
		self.sm.show_all()
		
		self.sm.popup(None, None, None, 0,0)
		gc.collect()
Example #2
0
 def panel_hide(self, *args):
     if self.aux != None:
         flag = backend.load_setting("flag")
         if flag == 0:
             self.Update_Panel_Top()
             gobject.timeout_add(180, self.aux.show_window)
         elif flag == 1:
             gobject.timeout_add(180, self.aux.hide_window)
Example #3
0
	def removefav(self,widget,event,name, execs,ico,typ):
		"""Remove from Favorites"""
		typ = str(typ)
		favlist = backend.load_setting("favorites")
		if '%s::%s::%s::%s' % (name, execs, ico, typ) in favlist:
			favlist.remove('%s::%s::%s::%s' % (name, execs, ico, typ))
			backend.save_setting("favorites",favlist)
			self.emit('changed')
			self.notifier.notify('%s %s' % (name, _('removed from favorites list')),Globals.name,Globals.Applogo,5000)
Example #4
0
	def addfav(self,widget,event,name, execs,ico,typ):
		"""Add to Favorites"""
		typ = str(typ)
		favlist = backend.load_setting("favorites")
		if '%s::%s::%s::%s' % (name, execs, ico, typ) not in favlist:
			favlist.append('%s::%s::%s::%s' % (name, execs, ico, typ))
			backend.save_setting("favorites",favlist)
		
			self.notifier.notify('%s %s' % (name, _('added to favorites list')),Globals.name,Globals.Applogo,5000)
Example #5
0
 def addfav(self, widget, event, name, execs, ico, typ):
     """Add to Favorites"""
     typ = str(typ)
     favlist = backend.load_setting("favorites")
     if "%s::%s::%s::%s" % (name, execs, ico, typ) not in favlist:
         favlist.append("%s::%s::%s::%s" % (name, execs, ico, typ))
         backend.save_setting("favorites", favlist)
         del self.menucache["<Favorites>"]
         self.notifier.notify("%s %s" % (name, _("added to favorites list")), Globals.name, Globals.Applogo, 5000)
	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()
Example #7
0
 def removefav(self, widget, event, name, execs, ico, typ):
     """Remove from Favorites"""
     typ = str(typ)
     favlist = backend.load_setting("favorites")
     if "%s::%s::%s::%s" % (name, execs, ico, typ) in favlist:
         favlist.remove("%s::%s::%s::%s" % (name, execs, ico, typ))
         backend.save_setting("favorites", favlist)
         del self.menucache["<Favorites>"]
         self.emit("changed")
         self.notifier.notify(
             "%s %s" % (name, _("removed from favorites list")), Globals.name, Globals.Applogo, 5000
         )
Example #8
0
	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
Example #9
0
 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)
Example #10
0
	def rightmenushow(self,i):
                favlist = backend.load_setting("favorites")

                self.sm =  gtk.Menu()

		if i == 0:
                	add_image_menuitem(self.sm, gtk.STOCK_OPEN, _("Open"),self.openhome)
		else:
                	add_image_menuitem(self.sm, gtk.STOCK_OPEN, _("Open"),self.opendir,i)

		#add_image_menuitem(self.sm, gtk.STOCK_OPEN,_("properties"))
		#add_menuitem(self.sm, "-")
		#self.Launcher.Launch(Globals.MenuButtonCommands[i])
		self.sm.show_all()                 
		self.sm.popup(None, None, None, 0,0)
		gc.collect()
Example #11
0
	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()
Example #12
0
    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:
                import utils

                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
Example #13
0
def ReloadSettings():

	def SetDefaultSettings():
		for x in DefaultSettings:
			backend.save_setting(x,DefaultSettings[x])
		FirstUse = True

	def GetSettings():
		print 'settings load'
		for x in DefaultSettings:
			Settings[x] = backend.load_setting(x)

# Loads the main configuration and settings file to their respective values
	global orientation, panel_size, flip, MenuActions, MenuCommands, ImageDirectory, Actions, IconDirectory, MenuButtonDirectory, ThemeColor, ShowTop, FirstUse, Hibernate, StartMenuTemplate, ThemeColorCode,ThemeColorHtml, NegativeThemeColorCode, MenuWidth, MenuHeight, IconW, IconH, IconInX, IconInY, IconInW, IconInH, SearchX, SearchY, SearchW, SearchH, SearchIX, SearchIY, SearchInitialText,SearchTextColor, SearchBackground, SearchWidget, SearchWidgetPath, UserIconFrameOffsetX, UserIconFrameOffsetY, UserIconFrameOffsetH, UserIconFrameOffsetW, PG_buttonframe, PG_buttonframedimensions, MenuHasSearch, MenuHasIcon, MenuHasFade , OnlyShowFavs, OnlyShowRecentApps, CairoSearchTextColor, CairoSearchBackColor, CairoSearchBorderColor, CairoSearchRoundAngle, PG_iconsize,RI_numberofitems, MenuButtonCount, MenuButtonNames, MenuButtonMarkup, MenuButtonNameOffsetX, MenuButtonNameOffsetY, MenuButtonCommands, MenuButtonX,MenuButtonY, MenuButtonImage, MenuButtonImageBack, MenuButtonIcon, MenuButtonIconSel, MenuButtonIconX,MenuButtonIconY,MenuButtonIconSize,MenuButtonExecOnHover, MenuButtonSub,MenuButtonClose, MenuCairoIconButton, MenuLabelCount, MenuLabelNames, MenuLabelMarkup, MenuLabelX, MenuLabelY, MenuLabelCommands, MenuTabCount, MenuTabNames, MenuTabMarkup, MenuTabNameOffsetX, MenuTabNameOffsetY, MenuTabCommands,MenuTabX,MenuTabY,MenuTabImage, MenuTabIcon, MenuTabImageSel, MenuTabSub,MenuTabClose, MenuCairoIconTab, MenuCairoIcontabX, MenuCairoIcontabY,MenuCairoIcontabSize, MenuTabInvertTextColorSel, MenuImageCount, MenuImageNames, MenuImageX, MenuImageY, MenuImage, ButtonHasTop, ButtonLabelCount, ButtonBackground, ButtonTop, StartButton, StartButtonTop, ButtonHasBottom, ButtonLabelName, ButtonLabelMarkup, ButtonLabelX, ButtonLabelY, MenuButtonNameAlignment, MenuTabNameAlignment,MenuLabelNameAlignment, GtkColorCode

	menubar = gtk.MenuBar()
	try:
		GtkColorCode = menubar.rc_get_style().bg[gtk.STATE_NORMAL]
	except:
		GtkColorCode = menubar.get_style().bg[gtk.STATE_NORMAL]
	orientation = None
	panel_size = 30
	flip = None
	orientation = backend.load_setting("orientation")
	panel_size = backend.load_setting("size")
	if orientation == 'top':
		flip = False
	elif orientation == 'bottom':
		flip = None
	GetSettings()
	for x in DefaultSettings:
		if Settings[x] is None:
			#logging.debug('Error - 7')
			SetDefaultSettings()
			#logging.debug('Error - 8')
			FirstUse = True
			GetSettings()
			break
	MenuActions = []
	MenuCommands = []
	MenuActions.append('Search')
	MenuCommands.append(Settings['Search'])
	MenuActions.append('Network Config')
	MenuCommands.append(Settings['Network_Config'])
	MenuActions.append('Control Panel')
	MenuCommands.append(Settings['Control_Panel'])
	MenuActions.append('Package Manager')
	MenuCommands.append(Settings['Package_Manager'])
	MenuActions.append('Default Program')
	MenuCommands.append(Settings['Default_Program'])
	MenuActions.append('Printer')
	MenuCommands.append(Settings['Printer'])
	MenuActions.append('Help')
	MenuCommands.append(Settings['Help'])
	MenuActions.append('Power')
	MenuCommands.append(Settings['Power'])
	MenuActions.append('Shutdown')
	MenuCommands.append(Settings['Shutdown'])
	MenuActions.append('Lock')
	MenuCommands.append(Settings['Lock'])
	MenuActions.append('Suspend')
	MenuCommands.append(Settings['Suspend'])
	MenuActions.append('Hibernate')
	MenuCommands.append(Settings['Hibernate'])
	MenuActions.append('Run')
	MenuCommands.append(Settings['Run'])
	MenuActions.append('Logout')
	MenuCommands.append(Settings['Logout'])
	MenuActions.append('LogoutNow')
	MenuCommands.append(Settings['LogoutNow'])
	MenuActions.append('Restart')
	MenuCommands.append(Settings['Restart'])
	ThemeColor = 'white'
	ImageDirectory = "%s/share/%s/Themes/Menu/%s/" % (INSTALL_PREFIX, appdirname, Settings['Menu_Name'])
	IconDirectory =  "%s/share/%s/Themes/Icon/%s/" % (INSTALL_PREFIX, appdirname, Settings['Icon_Name'])
	MenuButtonDirectory = "%s/share/%s/Themes/Button/%s/" % (INSTALL_PREFIX, appdirname, Settings['Button_Name'])
	PG_iconsize = int(float(Settings['IconSize']))
	RI_numberofitems = int(float(Settings['ListSize']))
	try:
		XMLSettings = xml.dom.minidom.parse("%sthemedata.xml" % ImageDirectory)
	except:
		print "Error loading Menu theme, reverting to default"
		SetDefaultSettings()
		XMLSettings = xml.dom.minidom.parse("%sthemedata.xml" % ImageDirectory)
	XContent = XMLSettings.childNodes[0].getElementsByTagName("theme")
	# Identify correct theme style element
	Found = 0
	for node in XContent:
		if node.attributes["color"].value == ThemeColor or node.attributes["color"].value == "All":
			XBase = node
			ThemeColorHtml = node.attributes["colorvalue"].value
			ThemeColorCode = gtk.gdk.color_parse(ThemeColorHtml)
			color = ThemeColorCode
			color_r = 65535 - int(color.red)
			color_g = 65535 - int(color.green)
			color_b = 65535 - int(color.blue)
			NegativeThemeColorCode = gtk.gdk.Color(color_r,color_g,color_b,0)
			Found = 1
			break
	if Found==0:
		print "Error: Failed to find theme color: %s" % ThemeColor
		print "The available values are:"
		for node in XContent:
			print node.attributes["color"].value
		sys.exit()
		
	# Load Background Image
	SBase = XBase.getElementsByTagName("Background")
	StartMenuTemplate = SBase[0].attributes["Image"].value
	
	try:
		im = gtk.gdk.pixbuf_new_from_file('%s%s' % (ImageDirectory, StartMenuTemplate))
		MenuWidth = im.get_width()
		MenuHeight = im.get_height()
	except:
	# Load WindowDimensions
		SBase = XBase.getElementsByTagName("WindowDimensions")
		MenuWidth = int(SBase[0].attributes["Width"].value)
		MenuHeight = int(SBase[0].attributes["Height"].value)

	# Load WindowDimensions
	SBase = XBase.getElementsByTagName("IconSettings")
	try:
		UserIconFrameOffsetX = int(SBase[0].attributes["X"].value)
		UserIconFrameOffsetW = int(SBase[0].attributes["Width"].value)
		UserIconFrameOffsetH = int(SBase[0].attributes["Height"].value)
		if orientation == 'botton':
			UserIconFrameOffsetY = int(SBase[0].attributes["Y"].value)
	
		elif orientation == 'top':
	
			UserIconFrameOffsetY =  MenuHeight - int(SBase[0].attributes["Y"].value) - UserIconFrameOffsetH
		else:
			UserIconFrameOffsetY = int(SBase[0].attributes["Y"].value)
	
		IconW = int(SBase[0].attributes["Width"].value)
		IconH = int(SBase[0].attributes["Height"].value)
		IconInX = int(SBase[0].attributes["InsetX"].value)
		IconInY = int(SBase[0].attributes["InsetY"].value)
		IconInW = int(SBase[0].attributes["InsetWidth"].value)
		IconInH = int(SBase[0].attributes["InsetHeight"].value)
	except:pass
	# Load SearchBarSettings
	SBase = XBase.getElementsByTagName("SearchBarSettings")
	SearchWidget = SBase[0].attributes["Widget"].value
	if SearchWidget != "None":
		# Load universal values
		SearchX = int(SBase[0].attributes["X"].value)
		SearchW = int(SBase[0].attributes["Width"].value)
		SearchH = int(SBase[0].attributes["Height"].value)
		if orientation == 'bottom':
			SearchY = int(SBase[0].attributes["Y"].value)
		elif orientation == 'top':

			SearchY = MenuHeight -  int(SBase[0].attributes["Y"].value) - SearchH
		else:
			SearchY = int(SBase[0].attributes["Y"].value)
		# Load theme-only values
		if SearchWidget == "Custom":
			SearchIX = int(SBase[0].attributes["InsetX"].value) 
			SearchIY = int(SBase[0].attributes["InsetY"].value)
			SearchInitialText = SBase[0].attributes["InitialText"].value
			try:SearchTextColor = SBase[0].attributes["TextColor"].value
			except:SearchTextColor = "#000000"
				
			SearchBackground = SBase[0].attributes["Background"].value
			SearchWidgetPath = SBase[0].attributes["WidgetName"].value
		if SearchWidget == "Cairo":
			try:CairoSearchTextColor = SBase[0].attributes["TextColor"].value
			except:CairoSearchTextColor = "#000000"
			try:CairoSearchBackColor = SBase[0].attributes["BackColor"].value
			except:CairoSearchBackColor = "#FFFFFF"
			try:CairoSearchBorderColor = SBase[0].attributes["BorderColor"].value
			except:CairoSearchBorderColor = "#000000"				
			try:CairoSearchRoundAngle = int(SBase[0].attributes["RoundAngle"].value)
			except:CairoSearchRoundAngle = 0	

	# Load ProgramListSettings
	SBase = XBase.getElementsByTagName("ProgramListSettings")
	PG_buttonframedimensions = int(SBase[0].attributes["Width"].value),int(SBase[0].attributes["Height"].value)
	if orientation == 'botton':
		PG_buttonframe = int(SBase[0].attributes["X"].value),int(SBase[0].attributes["Y"].value)
	elif orientation == 'top':
		PG_buttonframe = int(SBase[0].attributes["X"].value),MenuHeight - int(SBase[0].attributes["Y"].value) - int(PG_buttonframedimensions[1])
	else:
		PG_buttonframe = int(SBase[0].attributes["X"].value),int(SBase[0].attributes["Y"].value)
	try:
		OnlyShowFavs = int(SBase[0].attributes["OnlyShowFavs"].value)
	except:
		OnlyShowFavs = 0

	try:
		OnlyShowRecentApps = int(SBase[0].attributes["OnlyShowRecentApps"].value)
	except:
		OnlyShowRecentApps = 0

	# Load Capabilities
	SBase = XBase.getElementsByTagName("Capabilities")
	MenuHasSearch = int(SBase[0].attributes["HasSearch"].value)
	MenuHasIcon = int(SBase[0].attributes["HasIcon"].value)
	MenuHasFade = int(SBase[0].attributes["HasFadeTransition"].value)

	#Load Menu Button List
	MenuButtons = XBase.getElementsByTagName("Button")
	MenuButtonCount = len(MenuButtons)	
	MenuButtonNames = []
	MenuButtonMarkup = []
	MenuButtonNameOffsetX = []
	MenuButtonNameOffsetY = []
	MenuButtonX = []
	MenuButtonY = []
	MenuButtonImage = []
	MenuButtonImageBack = []
	MenuButtonIcon = []
	MenuButtonIconX = []
	MenuButtonIconY = []
	MenuButtonIconSize = []
	MenuButtonIconSel = []
	MenuButtonExecOnHover = []
	MenuCairoIconButton = []
	MenuButtonSub = []
	MenuButtonCommands = []
	MenuButtonClose = []
	MenuButtonNameAlignment = []

	for node in MenuButtons:
		try:
			im = gtk.gdk.pixbuf_new_from_file(ImageDirectory + node.attributes["Image"].value)
		except:
			print 'Warning - Error loading theme, reverting to defaults'
			SetDefaultSettings()
		h = im.get_height()
		
		MenuButtonNames.append(node.attributes["Name"].value)
		MenuButtonMarkup.append(node.attributes["Markup"].value)
		MenuButtonNameOffsetX.append(int(node.attributes["TextX"].value))
		try:
			MenuButtonNameAlignment.append(int(node.attributes["TextAlignment"].value))
		except:
			MenuButtonNameAlignment.append(0)
		MenuButtonImage.append(node.attributes["Image"].value)    
		try:	    	
			MenuButtonImageBack.append(node.attributes["ImageBack"].value) 
		except: MenuButtonImageBack.append('')
		MenuButtonIcon.append(node.attributes["ButtonIcon"].value)    	    	
		MenuButtonIconSel.append(node.attributes["ButtonIconSel"].value)    	    	
		try:
			MenuButtonExecOnHover.append(int(node.attributes["ExecuteOnHover"].value))
		except: MenuButtonExecOnHover.append(0)	
		try:
			MenuCairoIconButton.append(node.attributes["Icon"].value)  
		except:
			MenuCairoIconButton.append("")  
		try:    	
			MenuButtonIconX.append(int(node.attributes["ButtonIconX"].value)) 
		except:
			MenuButtonIconX.append(0) 
		try:  
			MenuButtonIconY.append(int(node.attributes["ButtonIconY"].value)) 
		except:

			MenuButtonIconY.append(0) 
		try:
			MenuButtonIconSize.append(int(node.attributes["ButtonIconSize"].value)) 
		except:
			MenuButtonIconSize.append(0)    	    	
		MenuButtonX.append(int(node.attributes["ButtonX"].value))
		if orientation == 'botton':
			MenuButtonNameOffsetY.append(int(node.attributes["TextY"].value))
			MenuButtonY.append(int(node.attributes["ButtonY"].value))
		elif orientation == 'top':

			MenuButtonNameOffsetY.append(int(node.attributes["TextY"].value) )
			MenuButtonY.append(MenuHeight - int(node.attributes["ButtonY"].value) -h )
		else:
			MenuButtonNameOffsetY.append(int(node.attributes["TextY"].value))
			MenuButtonY.append(int(node.attributes["ButtonY"].value))

		MenuButtonCommands.append(node.attributes["Command"].value)
		MenuButtonSub.append(int(node.attributes["SubMenu"].value))
		MenuButtonClose.append(int(node.attributes["CloseMenu"].value))

	#Load Menu Label List

	MenuLabels = XBase.getElementsByTagName("Label")
	MenuLabelCount = len(MenuLabels)
	MenuLabelNames = []
	MenuLabelMarkup = []
	MenuLabelCommands = []
	MenuLabelX = []
	MenuLabelY = []
	MenuLabelNameAlignment = []
	for node in MenuLabels:
		MenuLabelNames.append(node.attributes["Name"].value)
		MenuLabelMarkup.append(node.attributes["Markup"].value)	
		MenuLabelX.append(int(node.attributes["LabelX"].value))
		try:
			MenuLabelNameAlignment.append(int(node.attributes["TextAlignment"].value))
		except:
			MenuLabelNameAlignment.append(0)
		if orientation == 'botton':
			MenuLabelY.append(int(node.attributes["LabelY"].value))
		elif orientation == 'top':
			MenuLabelY.append(MenuHeight - int(node.attributes["LabelY"].value))
		else:
			MenuLabelY.append(int(node.attributes["LabelY"].value))
		if SecurityCheck(node.attributes["Command"].value) != '':
			MenuLabelCommands.append(node.attributes["Command"].value)
		else:
			MenuLabelCommands.append('')
	#Load Menu Tab List
	MenuTabs = XBase.getElementsByTagName("Tab")
	MenuTabCount = len(MenuTabs)
	MenuTabNames = []
	MenuTabMarkup = []
	MenuTabNameOffsetX = []
	MenuTabNameOffsetY = []
	MenuTabX = []
	MenuTabY = []
	MenuTabImage = []
	MenuTabIcon = []
	MenuTabImageSel = []
	MenuCairoIconTab = []
	MenuCairoIcontabX = []
	MenuCairoIcontabY = []
	MenuCairoIcontabSize = []
	MenuTabInvertTextColorSel = []
	MenuTabSub = []
	MenuTabCommands = []
	MenuTabClose = []
	MenuTabNameAlignment = []
	for node in MenuTabs:

		try:
			im = gtk.gdk.pixbuf_new_from_file(ImageDirectory + node.attributes["Image"].value)
			h = im.get_height()
		except:
			im = gtk.gdk.pixbuf_new_from_file(ImageDirectory + node.attributes["ImageSel"].value)
			h = im.get_height()		
		MenuTabNames.append(node.attributes["Name"].value)
		MenuTabMarkup.append(node.attributes["Markup"].value)
		MenuTabNameOffsetX.append(int(node.attributes["TextX"].value))
		try:
			MenuTabNameAlignment.append(int(node.attributes["TextAlignment"].value))
		except:
			MenuTabNameAlignment.append(0)
		MenuTabImage.append(node.attributes["Image"].value)    	    	
		MenuTabImageSel.append(node.attributes["ImageSel"].value)    	    	
		MenuTabIcon.append(node.attributes["TabIcon"].value)    	    	
		try:
			MenuCairoIconTab.append(node.attributes["Icon"].value)  
		except:
			MenuCairoIconTab.append("")    	
		try:    	
			MenuCairoIcontabX.append(int(node.attributes["TabIconX"].value)) 
		except:
			try:
				MenuCairoIcontabX.append(int(node.attributes["IconX"].value)) 
				print 'WARNING - IconX is deprecated , use TabIconX instead'
			except:
				MenuCairoIcontabX.append(0) 
		try:
			MenuCairoIcontabY.append(int(node.attributes["TabIconY"].value)) 
		except:
			try:
				MenuCairoIcontabY.append(int(node.attributes["IconY"].value)) 
				print 'WARNING - IconY is deprecated , use TabIconY instead'
			except:
				MenuCairoIcontabY.append(0) 

		try:
			MenuCairoIcontabSize.append(int(node.attributes["TabIconSize"].value)) 
		except:
			try:
				MenuCairoIcontabSize.append(int(node.attributes["IconSize"].value)) 
				print 'WARNING - IconSize is deprecated , use TabIconSize instead'
			except:
				MenuCairoIcontabSize.append(0)

		try:
			MenuTabInvertTextColorSel.append(int(node.attributes["InvertTextColorOnSel"].value)) 
		except:
			MenuTabInvertTextColorSel.append(1)
		MenuTabX.append(int(node.attributes["TabX"].value))
		if orientation == 'botton':
			MenuTabNameOffsetY.append(int(node.attributes["TextY"].value))
			MenuTabY.append(int(node.attributes["TabY"].value))
		elif orientation == 'top':

			MenuTabNameOffsetY.append(int(node.attributes["TextY"].value) )
			MenuTabY.append(MenuHeight - int(node.attributes["TabY"].value) -h )
		else:
			MenuTabNameOffsetY.append(int(node.attributes["TextY"].value))
			MenuTabY.append(int(node.attributes["TabY"].value))

		MenuTabCommands.append(node.attributes["Command"].value)
		MenuTabSub.append(int(node.attributes["SubMenu"].value))
		MenuTabClose.append(int(node.attributes["CloseMenu"].value))

	#Load menu images

	MenuImages = XBase.getElementsByTagName("Image")
	MenuImageCount = len(MenuImages)
	MenuImageNames = []
	MenuImageX = []
	MenuImageY = []
	MenuImage = []
	for node in MenuImages:

		im = gtk.gdk.pixbuf_new_from_file(ImageDirectory + node.attributes["Image"].value)
		h = im.get_height()
		
		MenuImageNames.append(node.attributes["Name"].value)
		MenuImage.append(node.attributes["Image"].value)    	    	
		MenuImageX.append(int(node.attributes["ImageX"].value))
		if orientation == 'botton':
			MenuImageY.append(int(node.attributes["ImageY"].value))
		elif orientation == 'top':
			MenuImageY.append(MenuHeight - int(node.attributes["ImageY"].value) -h )
		else:
			MenuImageY.append(int(node.attributes["ImageY"].value))

	# Menu button

	try:
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	except:
		print "Error loading Menu button theme, reverting to default"
		SetDefaultSettings()
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	XBase = XMLSettings.getElementsByTagName("theme")

	ButtonHasTop = int(XBase[0].attributes["Top"].value)
	ShowTop = ButtonHasTop

	try:
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	except:
		SetDefaultSettings()
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	XBase = XMLSettings.childNodes[0].childNodes[1]
	
	
	ButtonBackground = XMLSettings.getElementsByTagName("Background")
	for node in ButtonBackground:
		StartButton = (MenuButtonDirectory+str(node.attributes["Image"].value),
		        	MenuButtonDirectory+str(node.attributes["ImageHover"].value),
	               		MenuButtonDirectory+str(node.attributes["ImagePressed"].value))

	if not ButtonBackground:
		StartButton = (MenuButtonDirectory+"start-here.png",
			MenuButtonDirectory+"start-here-glow.png",
        		MenuButtonDirectory+"start-here-depressed.png")

	ButtonTop = XMLSettings.getElementsByTagName("Top")
	for node in ButtonTop:
		StartButtonTop = (MenuButtonDirectory+str(node.attributes["Image"].value),
	       	       MenuButtonDirectory+str(node.attributes["ImageHover"].value),
        	       MenuButtonDirectory+str(node.attributes["ImagePressed"].value))

	if not ButtonTop:
		StartButtonTop = (MenuButtonDirectory+"start-here-top.png",
                     MenuButtonDirectory+"start-here-top-glow.png",
                     MenuButtonDirectory+"start-here-top-depressed.png")

	ButtonLabels = XMLSettings.getElementsByTagName("Label")
	ButtonLabelCount = len(ButtonLabels)
	ButtonLabelName = ""
	ButtonLabelMarkup = ""
	ButtonLabelX = 0
	ButtonLabelY = 0
	if ButtonLabelCount != []:
		for node in ButtonLabels:
		
			ButtonLabelName= (node.attributes["Name"].value)
			ButtonLabelMarkup = (node.attributes["MarkupNormal"].value)	
			ButtonLabelX = (int(node.attributes["LabelX"].value)) + 30
			ButtonLabelY = (int(node.attributes["LabelY"].value))
Example #14
0
def ReloadSettings():

	def SetDefaultSettings():
		for x in DefaultSettings:
			backend.save_setting(x,DefaultSettings[x])
		FirstUse = True

	def GetSettings():
		print 'settings load'
		for x in DefaultSettings:
			Settings[x] = backend.load_setting(x)

        # Loads the main configuration and settings file to their respective values
	global orientation, panel_size, flip, MenuActions, MenuCommands, ImageDirectory, Actions, IconDirectory, MenuButtonDirectory, ThemeColor, ShowTop, FirstUse, StartMenuTemplate, ThemeColorCode,ThemeColorHtml, NegativeThemeColorCode, MenuWidth, MenuHeight, IconW, IconH, IconInX, IconInY, IconInW, IconInH, SearchWidget, SearchWidgetPath, PG_tabframe, PG_tabframedimensions, PG_buttonframe, PG_buttonframedimensions, MenuHasSearch, MenuHasIcon, MenuHasFade, MenuHasTab, CairoSearchTextColor, CairoSearchBackColor, CairoSearchBorderColor, CairoSearchRoundAngle, PG_iconsize,RI_numberofitems, MenuButtonCount, MenuButtonNames, MenuButtonMarkup, MenuButtonNameOffsetX, MenuButtonNameOffsetY, MenuButtonCommands, MenuButtonX,MenuButtonY, MenuButtonImage, MenuButtonImageBack, ButtonBackImage, ButtonBackIconX, ButtonBackIconY, ButtonBackNameX, ButtonBackNameY, TabBackImage, TabBackIconX, TabBackIconY, TabBackNameX, TabBackNameY, MenuButtonIcon, MenuButtonIconSel, MenuButtonIconX,MenuButtonIconY,MenuButtonIconSize, MenuButtonSub, MenuButtonClose, MenuCairoIconButton, ButtonHasTop, ButtonBackground, ButtonTop, StartButton, StartButtonTop, ButtonHasBottom, MenuButtonNameAlignment, GtkColorCode
        global SearchX, SearchY, SearchW, SearchH, SearchIX, SearchIY, SearchInitialText, SearchTextColor, SearchBackground, SearchBgSize
        global SearchPic, SearchPicX, SearchPicY, SearchPicW, SearchPicH
        global lowresolution, width_ratio, height_ratio, tab_back_size, MFontSize, button_back_size, UserMenuHeight
        global App_fgcolor, App_bgcolor, PG_fgcolor, PG_bgcolor, CategoryCommands
        global MenuButtonW, MenuButtonH
        
        lowresolution = False

	menubar = gtk.MenuBar()
	try:
		GtkColorCode = menubar.rc_get_style().bg[gtk.STATE_NORMAL]
	except:
		GtkColorCode = menubar.get_style().bg[gtk.STATE_NORMAL]
	orientation = None
	panel_size = 30
	flip = None
	orientation = backend.load_setting("orientation")
	panel_size = backend.load_setting("size")
	if orientation == 'top':
		flip = False
	elif orientation == 'bottom':
		flip = None
	GetSettings()
	for x in DefaultSettings:
		if Settings[x] is None:
			SetDefaultSettings()
			FirstUse = True
			GetSettings()
			break
	MenuActions = []
	MenuCommands = []
        CategoryCommands = {'Control Panel':Settings['Control_Panel'], 'Y Center':Settings['Y_Center']}

	MenuActions.append('Power')
	MenuCommands.append(Settings['Power'])
	MenuActions.append('Logout')
	MenuCommands.append(Settings['Logout'])
	ThemeColor = 'white'
	ImageDirectory = "%s/share/%s/Themes/Menu/%s/" % (INSTALL_PREFIX, appdirname, Settings['Menu_Name'])
	IconDirectory =  "%s/share/%s/Themes/Icon/%s/" % (INSTALL_PREFIX, appdirname, Settings['Icon_Name'])
	MenuButtonDirectory = "%s/share/%s/Themes/Button/%s/" % (INSTALL_PREFIX, appdirname, Settings['Button_Name'])
	PG_iconsize = int(float(Settings['IconSize']))
	RI_numberofitems = int(float(Settings['ListSize']))

        PG_tabframe = []
        PG_buttonframe = []
	PG_tabframedimensions = []
        PG_buttonframedimensions = []

        # Menu Themes
	try:
		XMLSettings = xml.dom.minidom.parse("%sthemedata.xml" % ImageDirectory)
	except:
		print "Error loading Menu theme, reverting to default"
		SetDefaultSettings()
		XMLSettings = xml.dom.minidom.parse("%sthemedata.xml" % ImageDirectory)
	XContent = XMLSettings.childNodes[0].getElementsByTagName("theme")
	# Identify correct theme style element
	Found = 0
	for node in XContent:
		if node.attributes["color"].value == ThemeColor or node.attributes["color"].value == "All":
			XBase = node
			ThemeColorHtml = node.attributes["colorvalue"].value
			ThemeColorCode = gtk.gdk.color_parse(ThemeColorHtml)
			color = ThemeColorCode
			color_r = 65535 - int(color.red)
			color_g = 65535 - int(color.green)
			color_b = 65535 - int(color.blue)
			NegativeThemeColorCode = gtk.gdk.Color(color_r,color_g,color_b,0)
			Found = 1
			break
	if Found==0:
		print "Error: Failed to find theme color: %s" % ThemeColor
		print "The available values are:"
		for node in XContent:
			print node.attributes["color"].value
		sys.exit()
	
	
	# Load WindowDimensions
	SBase = XBase.getElementsByTagName("WindowDimensions")
	MenuWidth = int(SBase[0].attributes["Width"].value)
	MenuHeight = int(SBase[0].attributes["Height"].value)

	try:
		UserMenuHeight = int(backend.load_setting("MenuHeight"))
	except:
		UserMenuHeight = 575

        if UserMenuHeight > 1000:
            UserMenuHeight = 1000
        elif UserMenuHeight < 350:
            UserMenuHeight = 350

	# Load WindowDimensions end
        
        # Load TabBackground Image
        try:
                SBase = XBase.getElementsByTagName("TabBackground")
                TabBackImage = SBase[0].attributes["Image"].value
                TabBackIconX = int(SBase[0].attributes["TabIconX"].value)
                TabBackIconY = int(SBase[0].attributes["TabIconY"].value)
                TabBackNameX = int(SBase[0].attributes["TextX"].value)
                TabBackNameY = int(SBase[0].attributes["TextY"].value)
        
                # Load ButtonBackground Image
                SBase = XBase.getElementsByTagName("ButtonBackground")
                ButtonBackImage = SBase[0].attributes["Image"].value
                ButtonBackIconX = int(SBase[0].attributes["ButtonIconX"].value)
                ButtonBackIconY = int(SBase[0].attributes["ButtonIconY"].value)
                ButtonBackNameX = int(SBase[0].attributes["TextX"].value)
                ButtonBackNameY = int(SBase[0].attributes["TextY"].value)
        except:pass
        
	# Load SearchBarSettings
	SBase = XBase.getElementsByTagName("SearchBarSettings")
	SearchWidget = SBase[0].attributes["Widget"].value
	if SearchWidget != "None":
		# Load universal values
		SearchX = int(SBase[0].attributes["X"].value)
		SearchW = int(SBase[0].attributes["Width"].value)
		SearchH = int(SBase[0].attributes["Height"].value)
		if orientation == 'bottom':
			SearchY = int(SBase[0].attributes["Y"].value)
		elif orientation == 'top':
			SearchY = MenuHeight -  int(SBase[0].attributes["Y"].value) - SearchH
		else:
			SearchY = int(SBase[0].attributes["Y"].value)
		# Load theme-only values
		if SearchWidget == "Gtk":
                        SearchBackground = SBase[0].attributes["Background"].value
			SearchW = int(SBase[0].attributes["Width"].value)
                        SearchH = int(SBase[0].attributes["Height"].value)

        #load search picture settings
        SBase = XBase.getElementsByTagName("SearchPicSettings")
        try:
            SearchPic = SBase[0].attributes["Image"].value
            SearchPicX = int(SBase[0].attributes["X"].value)
            SearchPicY = int(SBase[0].attributes["Y"].value)
            SearchPicW = int(SBase[0].attributes["Width"].value)
            SearchPicH = int(SBase[0].attributes["Height"].value)
        except:
            print "SearchPicSettings is not correct"

        # Load ProGramTabSettings
        try:
                SBase = XBase.getElementsByTagName("ProgramTabSettings")
                PG_tabframedimensions.append(int(SBase[0].attributes["Width"].value))
                PG_tabframedimensions.append(int(SBase[0].attributes["Height"].value))
                PG_tabframe.append(int(SBase[0].attributes["X"].value))
                PG_tabframe.append(int(SBase[0].attributes["Y"].value))
                PG_fgcolor = SBase[0].attributes["Foreground"].value
                PG_bgcolor = SBase[0].attributes["Background"].value
        except:pass

	# Load ProgramListSettings
	SBase = XBase.getElementsByTagName("ProgramListSettings")
	PG_buttonframedimensions.append(int(SBase[0].attributes["Width"].value))
        PG_buttonframedimensions.append(int(SBase[0].attributes["Height"].value))
	App_fgcolor = SBase[0].attributes["Foreground"].value
        App_bgcolor = SBase[0].attributes["Background"].value
        if orientation == 'botton':
		PG_buttonframe.append(int(SBase[0].attributes["X"].value))
                PG_buttonframe.append(int(SBase[0].attributes["Y"].value))
	elif orientation == 'top':
		PG_buttonframe.append(int(SBase[0].attributes["X"].value))
                PG_buttonframe.append(MenuHeight - int(SBase[0].attributes["Y"].value) - int(PG_buttonframedimensions[1]))
	else:
		PG_buttonframe.append(int(SBase[0].attributes["X"].value))
                PG_buttonframe.append(int(SBase[0].attributes["Y"].value))
	
	# Load Capabilities
	SBase = XBase.getElementsByTagName("Capabilities")
	MenuHasSearch = int(SBase[0].attributes["HasSearch"].value)
	MenuHasIcon = int(SBase[0].attributes["HasIcon"].value)
        try:
                MenuHasTab = int(SBase[0].attributes["HasTab"].value)
        except:
                MenuHasTab = 0

	#Load Menu Button List
	MenuButtons = XBase.getElementsByTagName("Button")
	MenuButtonCount = len(MenuButtons)	
	MenuButtonNames = []
	MenuButtonMarkup = []
	MenuButtonNameOffsetX = []
	MenuButtonNameOffsetY = []
	MenuButtonX = []
	MenuButtonY = []
        MenuButtonW = []
        MenuButtonH = []
	MenuButtonImage = []
	MenuButtonImageBack = []
	MenuButtonIcon = []
	MenuButtonIconX = []
	MenuButtonIconY = []
	MenuButtonIconSize = []
	MenuButtonIconSel = []
	MenuCairoIconButton = []
	MenuButtonSub = []
	MenuButtonCommands = []
	MenuButtonClose = []
	MenuButtonNameAlignment = []

	for node in MenuButtons:
		try:
			im = gtk.gdk.pixbuf_new_from_file(ImageDirectory + node.attributes["Image"].value)
		except:
			print 'Warning - Error loading theme, reverting to defaults'
			SetDefaultSettings()
		h = im.get_height()
		
		MenuButtonNames.append(node.attributes["Name"].value)
		MenuButtonMarkup.append(node.attributes["Markup"].value)
		MenuButtonNameOffsetX.append(int(node.attributes["TextX"].value))
		try:
			MenuButtonNameAlignment.append(int(node.attributes["TextAlignment"].value))
		except:
			MenuButtonNameAlignment.append(0)
		MenuButtonImage.append(node.attributes["Image"].value)    
		try:	    	
			MenuButtonImageBack.append(node.attributes["ImageBack"].value) 
		except: MenuButtonImageBack.append('')
		MenuButtonIcon.append(node.attributes["ButtonIcon"].value)    	    	
		MenuButtonIconSel.append(node.attributes["ButtonIconSel"].value)    	    	
		
		try:
			MenuCairoIconButton.append(node.attributes["Icon"].value)  
		except:
			MenuCairoIconButton.append("")  
		try:    	
			MenuButtonIconX.append(int(node.attributes["ButtonIconX"].value)) 
		except:
			MenuButtonIconX.append(0) 
		try:  
			MenuButtonIconY.append(int(node.attributes["ButtonIconY"].value)) 
		except:
			MenuButtonIconY.append(0) 
		try:
			MenuButtonIconSize.append(int(node.attributes["ButtonIconSize"].value)) 
		except:
			MenuButtonIconSize.append(0)
                try:
                        MenuButtonW.append(int(node.attributes["ButtonW"].value))
                except:
                        MenuButtonW.append(83)
                try:
                        MenuButtonH.append(int(node.attributes["ButtonH"].value))
                except:
                        MenuButtonH.append(28)
                        
		MenuButtonX.append(int(node.attributes["ButtonX"].value))
		if orientation == 'botton':
			MenuButtonNameOffsetY.append(int(node.attributes["TextY"].value))
			MenuButtonY.append(int(node.attributes["ButtonY"].value))
		elif orientation == 'top':
			MenuButtonNameOffsetY.append(int(node.attributes["TextY"].value) )
			MenuButtonY.append(MenuHeight - int(node.attributes["ButtonY"].value) -h )
		else:
			MenuButtonNameOffsetY.append(int(node.attributes["TextY"].value))
			MenuButtonY.append(int(node.attributes["ButtonY"].value))

		MenuButtonCommands.append(node.attributes["Command"].value)
		MenuButtonSub.append(int(node.attributes["SubMenu"].value))
		MenuButtonClose.append(int(node.attributes["CloseMenu"].value))

        #Button Themes
	try:
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	except:
		print "Error loading Menu button theme, reverting to default"
		SetDefaultSettings()
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	XBase = XMLSettings.getElementsByTagName("theme")

	ButtonHasTop = int(XBase[0].attributes["Top"].value)
	ShowTop = ButtonHasTop

	try:
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	except:
		SetDefaultSettings()
		XMLSettings = xml.dom.minidom.parse(MenuButtonDirectory+"themedata.xml")
	XBase = XMLSettings.childNodes[0].childNodes[1]
	
	
	ButtonBackground = XMLSettings.getElementsByTagName("Background")
    
	for node in ButtonBackground:
		StartButton = (MenuButtonDirectory+str(node.attributes["Image"].value),
		        	MenuButtonDirectory+str(node.attributes["ImageHover"].value),
	               		MenuButtonDirectory+str(node.attributes["ImagePressed"].value))

	if not ButtonBackground:
		StartButton = (MenuButtonDirectory+"start-here.png",
			MenuButtonDirectory+"start-here-glow.png",
        		MenuButtonDirectory+"start-here-depressed.png")

	ButtonTop = XMLSettings.getElementsByTagName("Top")
        
	for node in ButtonTop:
		StartButtonTop = (MenuButtonDirectory+str(node.attributes["Image"].value),
	       	       MenuButtonDirectory+str(node.attributes["ImageHover"].value),
        	       MenuButtonDirectory+str(node.attributes["ImagePressed"].value))

	if not ButtonTop:
		StartButtonTop = (MenuButtonDirectory+"start-here-top.png",
                     MenuButtonDirectory+"start-here-top-glow.png",
                     MenuButtonDirectory+"start-here-top-depressed.png")

        # ----------------------------------------------------------------

        # Category tab's background m_tab.png
        tab_back_size = []
        try:
            sel = gtk.gdk.pixbuf_get_file_info( ImageDirectory + TabBackImage )
            tab_back_size.append(sel[1])
            tab_back_size.append(sel[2])
            sel = None
        except:
            tab_back_size.append(137)
            tab_back_size.append(30)
            
        # App list button background size
        button_back_size = []
        try:
            sel = gtk.gdk.pixbuf_get_file_info(ImageDirectory + ButtonBackImage)
            button_back_size.append(sel[1])
            button_back_size.append(sel[2])
            del sel
        except:
            button_back_size.append(191)
            button_back_size.append(30)

        # SearchBar background
        if MenuHasSearch:
            SearchBgSize = []
            try:
                sel = gtk.gdk.pixbuf_get_file_info(ImageDirectory + SearchBackground)
                SearchBgSize.append(sel[1])
                SearchBgSize.append(sel[2])
                del sel
            except:
                SearchBgSize.append(191)
                SearchBgSize.append(25)


        # iconsize 32 | 24
        if PG_iconsize > 28:
            PG_iconsize = 32
            button_back_size[1] += 8
        else:
            PG_iconsize = 24


        # if encounter the low/high resolution monitor, scaling the menu size --------
        width_ratio = 1
        height_ratio = 1
        MFontSize = 'medium'
        orig_menu_width  = MenuWidth
        orig_menu_height = MenuHeight

        if UserMenuHeight != orig_menu_height:
            MenuHeight = UserMenuHeight
            if MenuHeight < 614: # 纵向分辨率768 的 4 / 5
                lowresolution = True
                if MenuHeight <  500:
                    MFontSize = 'small'
      
        else:
            return

        # ------------------scale processing  -----------------------------------------

        height_ratio = MenuHeight * 1.0 / orig_menu_height # 参照菜单,控件缩小比率

        # Category list
        PG_tabframe[1] = int(PG_tabframe[1] * height_ratio)
        PG_tabframedimensions[1] = int(PG_tabframedimensions[1] * height_ratio)

        # Program list
        PG_buttonframe[1] = int(PG_buttonframe[1] * height_ratio)
        PG_buttonframedimensions[1] = int(PG_buttonframedimensions[1] * height_ratio)


        # Search Bar
        SearchY = int( SearchY * height_ratio)

        # Search Picture
        SearchPicY = int( SearchPicY * height_ratio)

	# Menu Button
	for i in range(0, MenuButtonCount): 
	    MenuButtonY[i] = int(MenuButtonY[i] * height_ratio)
	
        # ---------------------低分辨率时--------------------------

        if lowresolution:
            MenuWidth    = int(MenuHeight * orig_menu_width / orig_menu_height) # 保持选单宽高比例
            width_ratio  = MenuWidth * 1.0 / orig_menu_width # 换成浮点数
            # category_scr size and  position
            # PG_tabframe[0] = int(PG_tabframe[0] * width_ratio)
            PG_tabframedimensions[0] = int(PG_tabframedimensions[0] * width_ratio)
	    TabBackIconX = int(TabBackIconX * width_ratio)
	    TabBackIconY = int(TabBackIconY * height_ratio)
	    TabBackNameX = int(TabBackNameX * width_ratio)
	    TabBackNameY = int(TabBackNameY * height_ratio)

	    tab_back_size[0] = int(tab_back_size[0] * width_ratio)
	    tab_back_size[1] = int(tab_back_size[1] * height_ratio)

            PG_iconsize = int(PG_iconsize * width_ratio) # PG_iconsize 菜单条目图标,与程序列表共用

            # app_scr size and position
            PG_buttonframedimensions[0] = int(PG_buttonframedimensions[0] * width_ratio)
            PG_buttonframe[0] = int(PG_buttonframe[0] * width_ratio)

	    ButtonBackIconX = int(ButtonBackIconX * width_ratio)
	    ButtonBackIconY = int(ButtonBackIconY * height_ratio)
	    ButtonBackNameX = int(ButtonBackNameX * width_ratio)
	    ButtonBackNameY = int(ButtonBackNameY * height_ratio)

	    button_back_size[0] = int(button_back_size[0] * width_ratio)
	    button_back_size[1] = int(button_back_size[1] * height_ratio)

	    # search bar position
            SearchW = int( SearchW * width_ratio )
            SearchH = int( SearchH * height_ratio )
            SearchBgSize[0] = int(SearchBgSize[0] * width_ratio)
            SearchBgSize[1] = int(SearchBgSize[1] * height_ratio)
            SearchX = int( SearchX * width_ratio)

            # search picture position
            SearchPicW = int( SearchPicW * width_ratio )
            SearchPicH = int( SearchPicH * height_ratio )
            SearchPicX = int( SearchPicX * width_ratio)
	    # Menu Button

            for i in range(0, MenuButtonCount):
                MenuButtonX[i] = int(MenuButtonX[i] * width_ratio)
                MenuButtonW[i] = int(MenuButtonW[i] * width_ratio)
                MenuButtonH[i] = int(MenuButtonH[i] * height_ratio)
		MenuButtonNameOffsetX[i] = int(MenuButtonNameOffsetX[i] * width_ratio)
		MenuButtonNameOffsetY[i] = int(MenuButtonNameOffsetY[i] * height_ratio)
		MenuButtonIconX[i] = int(MenuButtonIconX[i] * width_ratio)
		MenuButtonIconY[i] = int(MenuButtonIconY[i] * height_ratio)
		MenuButtonIconSize[i] = int(MenuButtonIconSize[i] * width_ratio) # 因为其宽高相等, 以宽比率换算,可能会变形
Example #15
0
    def ConstructMenu(self):
        """Construct the menu"""
        # aaa = time.clock()
        self.menustring = str(self.Menu)
        if self.menustring in self.menucache:
            self.L_Names, self.L_Icons, self.L_Icons_menu, self.L_Types, self.L_Paths, self.L_Execs = self.menucache[
                self.menustring
            ]
            return

        self.L_Names = []
        self.L_Icons = []
        self.L_Types = []
        self.L_Paths = []
        self.L_Execs = []
        self.L_Icons_menu = []
        self.searchresults = 0

        # ==============================================================
        # XDG PROGRAMS MENU
        # ==============================================================
        if isinstance(self.Menu, self.menuparser.MenuInstance):

            if Globals.Settings["Shownetandemail"] == 1:
                if self.BaseMenu == self.menuparser.CacheApplications:
                    self.AddInternetButtons()
                    # if self.BaseMenu ==self.menuparser.CacheSettings or self.BaseMenu ==self.menuparser.CacheApplications:
            for entry in self.menuparser.GetMenuEntries(self.Menu):
                if isinstance(entry, self.menuparser.MenuInstance):
                    name, icon, path, comment = self.menuparser.GetDirProps(entry)  # Folder
                    self.addtomenu(name, icon, 0, path, "")
                    if Globals.Settings["Show_Tips"]:
                        self.ItemComments[name] = comment
                elif isinstance(entry, self.menuparser.EntryInstance):  # Application
                    name, icon, execute, comment = self.menuparser.GetEntryProps(entry)
                    self.addtomenu(name, icon, 1, "", execute)
                    if Globals.Settings["Show_Tips"]:
                        self.ItemComments[name] = comment
            if self.Menu == self.menuparser.CacheApplications and int(Globals.Settings["Disable_PS"]) == 0:
                self.AddPlacesButton()
                self.AddSystemButton()

                # ==============================================================
                # AUXILIARY FUNCTIONS MENU
                # ==============================================================
        elif self.Menu == "<AuxiliaryFunctions>":

            self.addtomenu(_("About Me"), "user-info", 5, "", "mate-about-me")
            self.addtomenu(_("Appearance"), "mate-settings-theme", 5, "", "mate-appearance-properties")
            self.addtomenu(_("Menu editor"), "mozo", 6, "", "mozo")
            self.addtomenu(_("Screensaver"), "preferences-desktop-screensaver", 5, "", "mate-screensaver-preferences")
            self.addtomenu(_("System Monitor"), "utilities-system-monitor", 5, "", "mate-system-monitor")
            self.addtomenu(
                _("Tilo settings utility"),
                "%slogo.png" % Globals.GraphicsDirectory,
                7,
                "",
                "%sTilo-Settings.py" % Globals.ProgramDirectory,
            )
            # ==============================================================
            # FAVORITES ITEMS MENU
            # ==============================================================
        elif self.Menu == "<Favorites>":
            client = []
            x = backend.load_setting("favorites")
            if x != None:
                client = x
            try:
                client.sort(key=str.upper)
            except:
                pass

            for elem in client:
                try:
                    name, exe, ico, typ = elem.split("::")
                    self.addtomenu(name, ico, int(typ), "", exe)
                except:
                    backend.save_setting("favorites", [])

            if client == []:
                self.addtomenu(
                    _("No favorites\nUse the mouse right button\nto add or remove favorites"),
                    gtk.STOCK_MISSING_IMAGE,
                    9,
                    "",
                    "",
                )
                # ==============================================================
                # WEB BOOKMARKS MENU
                # ==============================================================
        elif self.Menu == "<WebBookmarks>":

            try:
                if self.webbookmarker is None:
                    self.webbookmarker = bookmarks.BookmarksMenu().getBookmarks()
                for item in map(list, self.webbookmarker):
                    self.addtomenu(item[0], item[3], 3, item[1], item[1])
            except:
                print "Error reading web bookmarks"

            # ==============================================================
            # SHUTDOWN MENU
            # ==============================================================
        elif self.Menu == "<Shutdown>":
            self.addtomenu(_("Shutdown"), "gtk-quit", 1, "", Globals.Settings["Shutdown"])
            self.addtomenu(_("Reboot"), "mate-session-reboot", 1, "", Globals.Settings["Restart"])
            self.addtomenu(_("Suspend"), "mate-session-suspend", 1, "", Globals.Settings["Suspend"])
            self.addtomenu(_("Hibernate"), "mate-session-hibernate", 1, "", Globals.Settings["Hibernate"])
            self.addtomenu(_("Logout"), "mate-session-logout", 1, "", Globals.Settings["LogoutNow"])
            self.addtomenu(_("Lock Screen"), "system-lock-screen", 1, "", Globals.Settings["Lock"])
            # ==============================================================
            # RECENT ITEMS MENU
            # ==============================================================
        elif self.Menu == "<RecentItems>":

            # self.recent_manager.set_limit(Globals.RI_numberofitems)
            if self.recents_changed or self.recents is None:
                self.recent = self.recent_manager.get_items()
                self.recents_changed = False
                self.recent.sort(self.recentSortCriterium)
            x = 0
            for item in self.recent:
                name = item.get_short_name()
                self.L_Names.append(name)
                self.L_Icons.append(self.IconFactory.getthumb(item))
                self.L_Icons_menu.append(name)
                self.L_Types.append(3)
                self.L_Paths.append("")
                self.L_Execs.append(item.get_uri())
                # self.addtomenu(item.get_short_name(),self.IconFactory.getthumb(item),3,"",item.get_uri())
                x = x + 1
                if x == Globals.RI_numberofitems:
                    break
            self.addtomenu(_("Clear recent documents"), gtk.STOCK_CLEAR, 10, "", "")
            self.sorted_list = []

            # ==============================================================
            # RECENT APPS MENU
            # ==============================================================
        elif self.Menu == "<RecentApps>":

            # self.recent_manager.set_limit(Globals.RI_numberofitems)
            if self.recents_changed or self.recents is None:
                self.recent = self.recent_manager.get_items()
                self.recents_changed = False
                self.recent.sort(self.recentSortCriterium)
            x = 0
            for item in self.recent:
                if isgio:
                    mime = item.get_mime_type()
                    app = gio.app_info_get_default_for_type(mime, 0)
                    if app:
                        if app.get_name() not in self.L_Names:
                            self.addtomenu(
                                app.get_name(), self.IconFactory.getgicon(app.get_icon()), 1, "", app.get_executable()
                            )
                            x = x + 1
                            if x == Globals.RI_numberofitems:
                                break
                else:
                    app = item.last_application()
                    appinfo = item.get_application_info(app)
                    # print appinfo[0].split(' ')[0]
                    if app not in self.L_Names:
                        self.addtomenu(app, appinfo[0].split(" ")[0], 1, "", appinfo[0].split(" ")[0])
                        x = x + 1
                        if x == Globals.RI_numberofitems:
                            break
            self.sorted_list = []

            # ==============================================================
            # RECENT BOOKMARKS / PLACES MENU
            # ==============================================================
        elif self.Menu == "<Bookmarks>":

            self.addtomenu(_("File System"), "drive-harddisk", 3, "/", "/")
            if isgio:
                self.drives = self.monitor.get_connected_drives()
                for drive in self.drives:
                    if drive.has_media():
                        self.mounts = drive.get_volumes()
                        for mount in self.mounts:
                            ico = mount.get_icon()
                            a = self.IconFactory.getgicon(ico)
                            self.L_Names.append(mount.get_name())
                            self.L_Icons.append(self.IconFactory.geticonfile(a))
                            self.L_Icons_menu.append(a)
                            self.L_Types.append(3)
                            self.L_Paths.append("")
                            try:
                                self.L_Execs.append(str(mount.get_mount().get_root().get_uri()).replace("file://", ""))
                            except:
                                self.L_Execs.append("")

            self.addtomenu(_("Home Folder"), "user-home", 3, "", Globals.HomeDirectory)
            self.addtomenu(_("Computer"), "computer", 3, "", "computer:///")
            self.addtomenu(_("Network"), "network", 3, "", "network:///")
            self.addtomenu(_("Trash"), "user-trash", 3, "", "trash:///")
            if os.path.isfile("%s/.gtk-bookmarks" % Globals.HomeDirectory):
                f = open("%s/.gtk-bookmarks" % Globals.HomeDirectory, "r")
                data = f.readlines(600)
                f.close()
                f = None
                for i in data:
                    self.bm = str(i).replace("\n", "")
                    if self.bm.find(" ") != -1:
                        self.folder = urllib.url2pathname(self.bm[: self.bm.find(" ")])
                        self.name = urllib.url2pathname(self.bm[self.bm.find(" ") + 1 :])
                    else:
                        self.folder = self.bm
                        self.name = urllib.url2pathname(str(self.bm).split("/").pop())
                    try:
                        if isgio:
                            Gfile = gio.File(self.folder)
                            tuble = [Gfile, Gfile.query_info("standard::*"), []]
                            ico = tuble[1].get_icon()
                            self.addtomenu(self.name, self.IconFactory.getgicon(ico), 3, "", self.folder)
                        else:
                            self.addtomenu(self.name, "folder", 3, "", self.folder)
                    except:
                        pass

        else:
            # ==============================================================
            # XDG PROGRAMS MENU (SEARCH)
            # ==============================================================
            # self.searchresults = 0
            for i in [self.menuparser.CacheApplications, self.menuparser.CacheSettings]:
                for entry in self.menuparser.GetMenuEntries(i):

                    if isinstance(entry, self.menuparser.MenuInstance):  # Folder
                        name, icon, path, comment = self.menuparser.GetDirProps(entry)  # Folder

                        if self.menuparser.has_matemenu:
                            self.SearchMenu(path)
                        else:
                            self.SearchMenu(i.getMenu(entry.getPath(True)))

                    elif isinstance(entry, self.menuparser.EntryInstance):  # Application
                        name, icon, execute, comment = self.menuparser.GetEntryProps(entry)
                        if name.upper().count(self.Menu) != 0 or execute.upper().count(self.Menu) != 0:
                            self.addtomenu(name, icon, 1, "", execute)
                            self.searchresults = self.searchresults + 1

            if self.searchresults == 0:
                self.addtomenu("<separator>", "", 8, "", "")
                self.addtomenu(_("No items matched your search criteria"), "", 9, "", "")
            else:
                self.addtomenu
                self.addtomenu("<separator>", "", 8, "", "")
                self.addtomenu(_("Found %s results to your search") % str(self.searchresults), "", 9, "", "")
                # Add back button so long as it isn't the base XDG menu
        if isinstance(self.Menu, self.menuparser.MenuInstance):
            if self.Menu != self.menuparser.CacheApplications:
                self.AddBackButton()
        else:
            if Globals.MenuTabCount == 0:
                if Globals.OnlyShowFavs == False and Globals.OnlyShowRecentApps == False:
                    self.AddBackButton()
                else:
                    if self.Menu != "<Favorites>" and self.Menu != "<RecentApps>":
                        self.AddBackButton()
                        # gc.collect()

                        # print time.clock() -aaa
        self.menucache[self.menustring] = (
            self.L_Names,
            self.L_Icons,
            self.L_Icons_menu,
            self.L_Types,
            self.L_Paths,
            self.L_Execs,
        )
Example #16
0
	def GetSettings():
		print 'settings load'
		for x in DefaultSettings:
			Settings[x] = backend.load_setting(x)
Example #17
0
    def ButtonClick(self, index, event=0):
        """Callback when buttons are clicked"""
        # 0 Subfolder
        # 1 Application
        # 2 places, settings, back.
        # 3,4 Recents
        self.etype = self.L_Types[index]
        if event == 0:
            event_button = 1
        else:
            if event.type == gtk.gdk.KEY_PRESS:
                event_button = 1
            elif event.type == gtk.gdk.BUTTON_PRESS:
                event_button = event.button
            elif event.type == gtk.gdk.BUTTON_RELEASE:
                event_button = event.button
        if event_button == 1:
            if self.etype == 0:  # Subfolder
                self.PrevMenu.append(self.Menu)
                if self.menuparser.has_matemenu:
                    self.Menu = self.L_Paths[index]
                else:
                    self.Menu = self.BaseMenu.getMenu(self.L_Paths[index])
                self.ConstructMenu()
            elif self.etype == 1 or self.etype == 3 or self.etype == 4:  # Application
                self.Launcher.Launch(self.L_Execs[index], self.etype)
                self.Restart("previous")
                return 1
            elif self.etype == 2:  # Menu special buttons places, settings, back.
                if self.L_Names[index] == _("Back"):
                    try:
                        self.Menu = self.PrevMenu.pop()
                    except:
                        self.Menu = self.BaseMenu = self.menuparser.CacheApplications
                    if self.Menu == self.menuparser.CacheApplications:
                        self.BaseMenu = self.Menu
                    self.ConstructMenu()
                elif self.L_Names[index] == _("System"):
                    self.PrevMenu.append(self.Menu)
                    self.Restart("settings")
                elif self.L_Names[index] == _("Places"):
                    self.PrevMenu.append(self.Menu)
                    self.Restart("places")
            elif self.etype == 5 or self.etype == 6:  # Items in the menu have changed
                self.Launcher.Launch(self.L_Execs[index], self.etype)
            elif self.etype == 7:  # Properties of the menu have changed
                self.Launcher.Launch(self.L_Execs[index], self.etype)
                Globals.ReloadSettings()
            elif self.etype == 10:  # Clear Recent
                self.recent_manager.purge_items()
                self.Restart("previous")
        elif event_button == 3:
            self.m = gtk.Menu()
            name = self.L_Names[index]
            favlist = backend.load_setting("favorites")
            try:
                thismenu = add_image_menuitem(self.m, self.L_Icons_menu[index], name, self.dummy, "1")
            except:
                return
            if zg and self.allgio is not None:
                self.recent_files = None
                self.most_used_files = None
                for z in self.allgio:
                    if z.get_name() == name:
                        desk = z.get_id()
                        self.recent_files = zg.get_recent_for_app(desk, Globals.RI_numberofitems)
                        self.most_used_files = zg.get_most_used_for_app(desk, Globals.RI_numberofitems)
                        break
                if self.recent_files or self.most_used_files:
                    self.menuitem = add_menuitem(self.m, "-")
                for files, menu_name in (
                    (self.recent_files, _("Recently Used")),
                    (self.most_used_files, _("Most Used")),
                ):
                    if files:
                        self.submenu = gtk.Menu()
                        menu_item = gtk.MenuItem(menu_name)
                        menu_item.set_submenu(self.submenu)
                        self.m.append(menu_item)
                        menu_item.show()
                        for ev in files:
                            for subject in ev.get_subjects():
                                label = subject.text or subject.uri
                                submenu_item = gtk.MenuItem(label, use_underline=False)
                                self.submenu.append(submenu_item)
                                # "activate" doesn't seem to work on sub menus
                                # so "button-press-event" is used instead.
                                submenu_item.connect("button-press-event", self.launch_item, subject.uri)
                                submenu_item.show()
            if self.etype != 0 and name != _("Back"):
                if self.etype != 3:
                    self.menuitem = add_menuitem(self.m, "-")
                    self.menuitem = add_image_menuitem(
                        self.m,
                        gtk.STOCK_DIALOG_AUTHENTICATION,
                        _("Open as Administrator"),
                        self.runasadmin,
                        name,
                        self.L_Execs[index],
                        self.L_Icons_menu[index],
                        self.L_Types[index],
                    )
                else:

                    def searchfolder(folder, me):
                        dirs = os.listdir(folder)
                        dirs.sort(key=str.upper)
                        for item in dirs:
                            if not item.startswith("."):
                                if os.path.isdir(os.path.abspath(folder) + "/" + item):
                                    add_image_menuitem(
                                        me,
                                        gtk.STOCK_DIRECTORY,
                                        item,
                                        self.launch_item,
                                        '"' + os.path.abspath(folder.replace("file://", "")) + "/" + item + '"',
                                    )
                                else:
                                    submenu_item = gtk.MenuItem(item, use_underline=False)
                                    me.append(submenu_item)
                                    # "activate" doesn't seem to work on sub menus
                                    # so "button-press-event" is used instead.
                                    submenu_item.connect(
                                        "button-press-event",
                                        self.launch_item,
                                        '"' + os.path.abspath(folder) + "/" + item + '"',
                                    )
                                    submenu_item.show()

                    f = os.path.abspath(urllib.url2pathname(self.L_Execs[index]).replace("file://", ""))
                    if os.path.exists(f):
                        if os.path.isdir(f):
                            self.submenu = gtk.Menu()
                            thismenu.set_submenu(self.submenu)

                            searchfolder(f, self.submenu)
                        elif os.path.isfile(f):
                            if isgio:
                                add_menuitem(self.m, "-")
                                self.openwith = add_image_menuitem(self.m, gtk.STOCK_OPEN, _("Open with"))
                                Gfile = gio.File(f)
                                tuble = [Gfile, Gfile.query_info("standard::*"), []]
                                name = tuble[1].get_name()
                                # ff =  gio.file_parse_name(f)
                                apps = gio.app_info_get_all_for_type(tuble[1].get_content_type())
                                self.submenu = gtk.Menu()
                                self.openwith.set_submenu(self.submenu)
                                for app in apps:
                                    self.menuitem = add_menuitem(
                                        self.submenu,
                                        app.get_name(),
                                        self.custom_launch,
                                        "'" + f + "'",
                                        app.get_executable(),
                                    )

                    if name == _("Trash"):
                        self.menuitem = add_menuitem(self.m, "-")
                        self.menuitem = add_image_menuitem(self.m, gtk.STOCK_CLEAR, _("Empty Trash"), self.emptytrash)
                if (
                    "%s::%s::%s::%s" % (name, self.L_Execs[index], self.L_Icons_menu[index], str(self.L_Types[index]))
                    not in favlist
                ):
                    self.menuitem = add_menuitem(self.m, "-")
                    self.menuitem = add_image_menuitem(
                        self.m,
                        gtk.STOCK_ADD,
                        _("Add to Favorites"),
                        self.addfav,
                        name,
                        self.L_Execs[index],
                        self.L_Icons_menu[index],
                        self.L_Types[index],
                    )
                else:
                    self.menuitem = add_menuitem(self.m, "-")
                    self.menuitem = add_image_menuitem(
                        self.m,
                        gtk.STOCK_REMOVE,
                        _("Remove from Favorites"),
                        self.removefav,
                        name,
                        self.L_Execs[index],
                        self.L_Icons_menu[index],
                        self.L_Types[index],
                    )
                self.menuitem = add_menuitem(self.m, "-")
                self.menuitem = add_image_menuitem(
                    self.m,
                    gtk.STOCK_HOME,
                    _("Create Desktop Shortcut"),
                    self.addshort,
                    name,
                    self.L_Execs[index],
                    self.L_Icons_menu[index],
                    self.L_Types[index],
                )
                self.menuitem = add_menuitem(self.m, "-")
                if ("%s.desktop" % name) in os.listdir(Globals.AutoStartDirectory):
                    self.menuitem = add_image_menuitem(
                        self.m,
                        gtk.STOCK_REMOVE,
                        _("Remove from System Startup"),
                        self.remove_autostarter,
                        name,
                        self.L_Execs[index],
                        self.L_Icons_menu[index],
                        self.L_Types[index],
                    )
                else:
                    self.menuitem = add_image_menuitem(
                        self.m,
                        gtk.STOCK_ADD,
                        _("Add to System Startup"),
                        self.create_autostarter,
                        name,
                        self.L_Execs[index],
                        self.L_Icons_menu[index],
                        self.L_Types[index],
                    )
            self.m.show_all()
            self.m.popup(None, None, None, event.button, event.time)
            self.submenu = None
            self.menuitem = None
            gc.collect()