# -*- coding: utf-8 -*- import os import urllib import customJava from gi.repository import Nautilus, GObject def get_translation(text): translations = {} translations["Java Runner"] = {} translations["Java Runner"]["es"] = "Seleccionar el Java" translations["Java Runner"]["qcv"] = "Selecciona el Java" lng = os.getenv("LANG") if text in translations: if "qcv" in lng or "ca_ES" in lng: return translations[text]["qcv"] if "es_" in lng or "es." in lng: return translations[text]["es"] return text #def get_translation _ = get_translation class JavaRunnerExtension(GObject.GObject, Nautilus.MenuProvider): def __init__(self): pass # self.client = gconf.client_get_default() def _run_java(self, javavm, file): filename = urllib.unquote(file.get_uri()[7:]) print('java-custom-runner --java "%s" "%s" &' % (javavm, filename)) os.system('java-custom-runner --java "%s" "%s" &' % (javavm, filename)) def menu_activate_cb(self, menu, javavm,file): self._run_java( javavm ,file) def menu_background_activate_cb(self, menu, file): self._run_java(file) def get_file_items(self, window, files): if len(files) != 1: return file = files[0] path_dir = "" line = str(file.get_parent_uri()) if line.startswith("file://"): path_dir = line[7:] path_to_file = path_dir + "/" + str(file.get_name()) aux_file = open(path_to_file) ext = os.path.splitext(path_to_file)[-1].lower() # TOP MENU AdvancedTopMenu = Nautilus.MenuItem(name='TopMenuItem::Advanced', label='Java Runner', tip='Advanced Menu', icon='java-custom-runner', ) AdvancedSubMenu = Nautilus.Menu() AdvancedTopMenu.set_submenu(AdvancedSubMenu) list_of_javas = customJava.CustomRunner.list_java_available() if ext == ".jar": for javavm in list_of_javas: etiq = _(javavm[0]) current_icon ="java-custom-runner" # Get the icon icons_list = {"open":{"1.5":"openjdk15","1.6":"openjdk16","1.7":"openjdk17","1.8":"openjdk18"},"oracle":{"-5-":"java15","-6-":"java16","-7-":"java17","-8-":"java18"}} for key,value in icons_list.items(): if key in etiq: for key1,value1 in value.items(): if key1 in etiq: current_icon = value1 print (current_icon) item = Nautilus.MenuItem(name='NautilusPython::run_java_runner-'+javavm[0], label=etiq, tip='%s %s' % (etiq, file.get_name()), icon=current_icon) item.connect('activate', self.menu_activate_cb, javavm[0],file) AdvancedSubMenu.append_item(item) return AdvancedTopMenu,