コード例 #1
0
    def __init__(self, parent, **options):
        super(QconfigView, self).__init__(parent, **options)

        self.pack(fill=tk.BOTH, expand=tk.TRUE)

        self._notebook = ttk.Notebook(self)
        self._notebook.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.TRUE)

        preferences = Preferences()
        self._mainpage = MainPage(self._notebook, preferences)
        self._proxiespage = ProxiesPage(self._notebook, preferences)
        self._notebook.add(self._mainpage, text='Main')
        self._notebook.add(self._proxiespage, text='Proxies')
        self._notebook.bind('<<NotebookTabChanged>>', self._tab_changed)

        frame = ttk.Frame(self)
        frame.pack(side=tk.BOTTOM, fill=tk.X, expand=tk.TRUE)

        ttk.Label(frame, text="Path:", borderwidth=0,
                  anchor=tk.E).grid(row=0, column=0, padx=6, sticky='nsew')
        ttk.Label(frame,
                  text=preferences.get_qconfig_path(''),
                  borderwidth=0,
                  anchor=tk.W).grid(row=0, column=1, sticky='nsw')

        self.initial_focus = self._mainpage.initial_focus
        self.update_idletasks()
        self._notebook.configure(height=self._mainpage.winfo_reqheight())
コード例 #2
0
ファイル: _preferencesdialog.py プロジェクト: kifumi/aqua
 def apply(self):
     try:
         level_name = self._levelCombo.get()
         levels = [key for key, value in PreferencesDialog._LOG_LEVELS.items() if value == level_name]
         loglevel = levels[0]
     
         preferences = Preferences()
         self._qconfigview.apply(preferences)
         self._packagesPage.apply(preferences)
         preferences.save()
         
         logging_config = build_logging_config(loglevel)
         
         preferences = Preferences()
         preferences.set_logging_config(logging_config)
         preferences.save()
         
         set_logging_config(logging_config)
     
         uipreferences = UIPreferences()
         populate = self._populateDefaults.get()
         uipreferences.set_populate_defaults(False if populate == 0 else True)
         uipreferences.save()
     
         self._controller.get_available_backends()
     except Exception as e:
         self.controller.outputview.write_line(str(e))
コード例 #3
0
 def _set_preferences_logging(self):
     from qiskit_aqua.preferences import Preferences
     from qiskit_aqua._logging import set_logging_config
     preferences = Preferences()
     config = preferences.get_logging_config()
     if config is not None:
         set_logging_config(config)
コード例 #4
0
ファイル: command_line.py プロジェクト: simhan/aqua
def main_algorithm():
    try:
        from qiskit_aqua._logging import get_logging_level, build_logging_config, set_logging_config
        from qiskit_aqua.preferences import Preferences
        from qiskit_aqua import run_algorithm
        from qiskit_aqua.utils import convert_json_to_dict
        parser = argparse.ArgumentParser(description='Qiskit Aqua Command Line Tool')
        parser.add_argument('input',
                            metavar='input',
                            help='Algorithm JSON input file')
        parser.add_argument('-jo',
                            metavar='output',
                            help='Algorithm JSON output file name',
                            required=False)

        args = parser.parse_args()

        # update logging setting with latest external packages
        preferences = Preferences()
        logging_level = logging.INFO
        if preferences.get_logging_config() is not None:
            set_logging_config(preferences.get_logging_config())
            logging_level = get_logging_level()

        preferences.set_logging_config(build_logging_config(logging_level))
        preferences.save()

        set_logging_config(preferences.get_logging_config())

        params = None
        with open(args.input) as json_file:
            params = json.load(json_file)

        ret = run_algorithm(params, None, True)

        if args.jo is not None:
            with open(args.jo, 'w') as f:
                print('{}'.format(ret), file=f)
        else:
            convert_json_to_dict(ret)
            print('\n\n--------------------------------- R E S U L T ------------------------------------\n')
            if isinstance(ret, dict):
                for k, v in ret.items():
                    print("'{}': {}".format(k, v))
            else:
                print(ret)
    finally:
        global _ROOT
        if _ROOT is not None:
            _ROOT.destroy()
            _ROOT = None
コード例 #5
0
def discover_preferences_pluggables():
    """
    Discovers the pluggable modules on the directory and subdirectories of the preferences package
    and attempts to register them. Pluggable modules should subclass Pluggable Base classes.
    """
    preferences = Preferences()
    packages = preferences.get_packages([])
    for package in packages:
        try:
            mod = importlib.import_module(package)
            if mod is not None:
                _discover_local_pluggables(os.path.dirname(mod.__file__),
                                           mod.__name__,
                                           names_to_exclude=['__main__'],
                                           folders_to_exclude=['__pycache__'])
            else:
                # Ignore package that could not be initialized.
                logger.debug('Failed to import package {}'.format(package))
        except Exception as e:
            # Ignore package that could not be initialized.
            logger.debug(
                'Failed to load package {} error {}'.format(package, str(e)))
コード例 #6
0
    def __init__(self, parent, **options):
        super(CredentialsView, self).__init__(parent, **options)

        self.pack(fill=tk.BOTH, expand=tk.TRUE)

        self._notebook = ttk.Notebook(self)
        self._notebook.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.TRUE)

        preferences = Preferences()
        self._mainpage = MainPage(self._notebook, preferences)
        self._proxiespage = ProxiesPage(self._notebook, preferences)
        self._notebook.add(self._mainpage, text='Main')
        self._notebook.add(self._proxiespage, text='Proxies')
        self._notebook.bind('<<NotebookTabChanged>>', self._tab_changed)

        self.initial_focus = self._mainpage.initial_focus
        self.update_idletasks()
        self._notebook.configure(height=self._proxiespage.winfo_reqheight())
コード例 #7
0
ファイル: command_line.py プロジェクト: xiaoyaolanyun/aqua
def main():
    if sys.platform == 'darwin':
        from Foundation import NSBundle
        bundle = NSBundle.mainBundle()
        if bundle:
            info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
            info['CFBundleName'] = 'Qiskit Aqua'
    
    root = tk.Tk()
    root.withdraw()
    root.update_idletasks()
    
    preferences = UIPreferences()
    geometry = preferences.get_run_geometry()
    if geometry is None:
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        w = int(ws / 1.3)
        h = int(hs / 1.3)
        x = int(ws/2 - w/2)
        y = int(hs/2 - h/2)
        geometry = '{}x{}+{}+{}'.format(w,h,x,y)
        preferences.set_run_geometry(geometry)
        preferences.save()
    
    root.geometry(geometry)
    
    # update logging setting with latest external packages
    preferences = Preferences()
    logging_level = logging.INFO
    if preferences.get_logging_config() is not None:
        set_logging_config(preferences.get_logging_config())
        logging_level = get_logging_level()
        
    preferences.set_logging_config(build_logging_config(logging_level))
    preferences.save()
    
    set_logging_config(preferences.get_logging_config())
    
    MainView(root)
    root.after(0, root.deiconify)
    root.mainloop()
コード例 #8
0
def main():
    parser = argparse.ArgumentParser(description='Qiskit Aqua Command Line Tool')
    parser.add_argument('input', 
                        metavar='input', 
                        help='Algorithm JSON input file')
    parser.add_argument('-jo', 
                        metavar='output', 
                        help='Algorithm JSON output file name',
                        required=False)
    
    args = parser.parse_args()
    
    preferences = Preferences()
    if preferences.get_logging_config() is None:
        logging_config = build_logging_config(['qiskit_aqua'], logging.INFO)
        preferences.set_logging_config(logging_config)
        preferences.save()
    
    set_logger_config(preferences.get_logging_config())
    
    params = None
    with open(args.input) as json_file:
        params = json.load(json_file)
    
    ret = run_algorithm(params, None, True)
    
    if args.jo is not None:
        with open(args.jo, 'w') as f:
            print('{}'.format(ret), file=f)
    else:
        convert_json_to_dict(ret)
        print('\n\n--------------------------------- R E S U L T ------------------------------------\n')
        if isinstance(ret,dict):
            for k, v in ret.items():
                print("'{}': {}".format(k, v))
        else:
            print(ret)
コード例 #9
0
def main():
    if sys.platform == 'darwin':
        from Foundation import NSBundle
        bundle = NSBundle.mainBundle()
        if bundle:
            info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
            info['CFBundleName'] = 'Qiskit Aqua'
    
    root = tk.Tk()
    root.withdraw()
    root.update_idletasks()
    
    preferences = UIPreferences()
    geometry = preferences.get_browser_geometry()
    if geometry is None:
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        w = int(ws / 1.2)
        h = int(hs / 1.3)
        x = int(ws/2 - w/2)
        y = int(hs/2 - h/2)
        geometry = '{}x{}+{}+{}'.format(w,h,x,y)
        preferences.set_browser_geometry(geometry)
        preferences.save()
    
    root.geometry(geometry)
      
    preferences = Preferences()
    if preferences.get_logging_config() is None:
        logging_config = build_logging_config(['qiskit_aqua'],logging.INFO)
        preferences.set_logging_config(logging_config)
        preferences.save()
    
    set_logger_config(preferences.get_logging_config())
         
    MainView(root)
    root.after(0, root.deiconify)
    root.mainloop()
コード例 #10
0
ファイル: _mainview.py プロジェクト: xiaoyaolanyun/aqua
    def _create_pane(self):
        label_font = font.nametofont('TkHeadingFont').copy()
        label_font.configure(size=12, weight='bold')
        ttk.Style().configure('TLabel', borderwidth=1, relief='solid')
        style = ttk.Style()
        style.configure('Title.TLabel',
                        borderwidth=0,
                        anchor=tk.CENTER)
        label = ttk.Label(self,
                          style='Title.TLabel',
                          padding=(5, 5, 5, 5),
                          textvariable=self._controller._title)
        label['font'] = label_font
        label.pack(side=tk.TOP, expand=tk.NO, fill=tk.X)
        main_pane = ttk.PanedWindow(self, orient=tk.VERTICAL)
        main_pane.pack(expand=tk.YES, fill=tk.BOTH)
        top_pane = ttk.PanedWindow(main_pane, orient=tk.HORIZONTAL)
        top_pane.pack(expand=tk.YES, fill=tk.BOTH)
        main_pane.add(top_pane)

        self._controller._sectionsView = SectionsView(
            self._controller, top_pane)
        self._controller._sectionsView.pack(expand=tk.YES, fill=tk.BOTH)
        top_pane.add(self._controller._sectionsView, weight=1)

        main_container = tk.Frame(top_pane)
        main_container.pack(expand=tk.YES, fill=tk.BOTH)
        style = ttk.Style()
        style.configure('PropViewTitle.TLabel',
                        borderwidth=1,
                        relief=tk.RIDGE,
                        anchor=tk.CENTER)
        label = ttk.Label(main_container,
                          style='PropViewTitle.TLabel',
                          padding=(5, 5, 5, 5),
                          textvariable=self._controller._sectionView_title)
        label['font'] = label_font

        label.pack(side=tk.TOP, expand=tk.NO, fill=tk.X)
        container = tk.Frame(main_container)
        container.pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.BOTH)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self._controller._emptyView = EmptyView(container)
        self._controller._emptyView.grid(row=0, column=0, sticky='nsew')

        self._controller._textView = SectionTextView(
            self._controller, container)
        self._controller._textView.grid(row=0, column=0, sticky='nsew')

        self._controller._propertiesView = SectionPropertiesView(
            self._controller, container)
        self._controller._propertiesView.grid(row=0, column=0, sticky='nsew')
        self._controller._emptyView.tkraise()
        top_pane.add(main_container, weight=1)

        self._controller._outputView = ThreadSafeOutputView(main_pane)
        self._controller._outputView.pack(expand=tk.YES, fill=tk.BOTH)
        main_pane.add(self._controller._outputView)

        # redirect output
        sys.stdout = self._controller._outputView
        sys.stderr = self._controller._outputView
        # reupdate logging after redirect
        preferences = Preferences()
        config = preferences.get_logging_config()
        if config is not None:
            set_logging_config(config)

        self.update_idletasks()
        self._controller._sectionsView.show_add_button(False)
        self._controller._sectionsView.show_remove_button(False)
        self._controller._sectionsView.show_defaults_button(False)
        self._controller._emptyView.set_toolbar_size(
            self._controller._sectionsView.get_toolbar_size())
コード例 #11
0
ファイル: _credentialsview.py プロジェクト: mtreinish/aqua
    def __init__(self, parent, **options):
        super(CredentialsView, self).__init__(parent, **options)

        self.pack(fill=tk.BOTH, expand=tk.TRUE)

        preferences = Preferences()
        self._credentials_preferences = preferences.credentials_preferences

        ttk.Label(self, text="URL:", borderwidth=0,
                  anchor=tk.E).grid(row=0, column=0, pady=5, sticky='nsew')
        urls = [
            credentials.url for credentials in
            self._credentials_preferences.get_all_credentials()
        ]
        self._urlCombobox = URLCombobox(self,
                                        self,
                                        width=80,
                                        exportselection=0,
                                        state='readonly',
                                        values=urls)
        self._urlCombobox._text = self._credentials_preferences.get_url('')
        self._urlCombobox.set(self._urlCombobox._text)
        if len(urls) > 0:
            if self._urlCombobox.get() in urls:
                self._urlCombobox.current(urls.index(self._urlCombobox.get()))
            else:
                self._urlCombobox.current(0)

        self._urlCombobox.grid(row=0, column=1, pady=5, sticky='nsew')

        button_container = tk.Frame(self)
        button_container.grid(row=0, column=2, pady=5, sticky='nsw')
        self._add_button = ttk.Button(button_container,
                                      text='Add',
                                      state='enable',
                                      command=self.onadd)
        self._remove_button = ttk.Button(button_container,
                                         text='Remove',
                                         state='enable',
                                         command=self.onremove)
        self._add_button.pack(side=tk.LEFT)
        if len(urls) > 0:
            self._remove_button.pack(side=tk.LEFT)

        self._apiToken = tk.StringVar()
        self._apiToken.set(self._credentials_preferences.get_token(''))
        ttk.Label(self, text="Token:", borderwidth=0,
                  anchor=tk.E).grid(row=1, column=0, pady=5, sticky='nsew')
        self._apiTokenEntry = EntryCustom(
            self,
            textvariable=self._apiToken,
            width=120,
            state=tk.NORMAL if len(urls) > 0 else tk.DISABLED)
        self._apiTokenEntry.grid(row=1,
                                 column=1,
                                 columnspan=2,
                                 pady=5,
                                 sticky='nsew')

        ttk.Label(self, text="Proxies:", borderwidth=0,
                  anchor=tk.E).grid(row=2, column=0, pady=5, sticky='nsew')
        self._proxiespage = ProxiesPage(self, self._credentials_preferences)
        self._proxiespage.grid(row=3,
                               column=0,
                               columnspan=3,
                               pady=5,
                               sticky='nsew')
        self._proxiespage.show_add_button(True)
        self._proxiespage.show_remove_button(self._proxiespage.has_selection())
        self._proxiespage.show_defaults_button(False)
        if len(urls) == 0:
            self._proxiespage.enable(False)

        self.initial_focus = self._urlCombobox
コード例 #12
0
ファイル: _preferencesdialog.py プロジェクト: kifumi/aqua
 def body(self,parent,options):
     preferences = Preferences()
     logging_config = preferences.get_logging_config()
     if logging_config is not None:
         set_logging_config(logging_config)
     
     uipreferences = UIPreferences()
     populate = uipreferences.get_populate_defaults(True)
     self._populateDefaults.set(1 if populate else 0)
     
     qiskitGroup = ttk.LabelFrame(parent,
                                  text='Qiskit Configuration',
                                  padding=(6,6,6,6),
                                  borderwidth=4,
                                  relief=tk.GROOVE)
     qiskitGroup.grid(padx=(7,7),pady=6,row=0, column=0,sticky='nsew')
     self._qconfigview = QconfigView(qiskitGroup)
     
     defaultsGroup = ttk.LabelFrame(parent,
                                  text='Defaults',
                                  padding=(6,6,6,6),
                                  borderwidth=4,
                                  relief=tk.GROOVE)
     defaultsGroup.grid(padx=(7,7),pady=6,row=1, column=0,sticky='nsw')
     defaultsGroup.columnconfigure(1,pad=7)
     
     self._checkButton = ttk.Checkbutton(defaultsGroup,
                                         text="Populate on file new/open",
                                         variable=self._populateDefaults)
     self._checkButton.grid(row=0, column=1,sticky='nsw')
     
     packagesGroup = ttk.LabelFrame(parent,
                                  text='Packages',
                                  padding=(6,6,6,6),
                                  borderwidth=4,
                                  relief=tk.GROOVE)
     packagesGroup.grid(padx=(7,7),pady=6,row=2, column=0,sticky='nsw')
     packagesGroup.columnconfigure(1,pad=7)
     
     frame = ttk.Frame(packagesGroup)
     frame.grid(row=0, column=0,sticky='nsew')
     
     self._packagesPage = PackagesPage(frame,preferences)
     self._packagesPage.pack(side=tk.TOP,fill=tk.BOTH, expand=tk.TRUE)
     self._packagesPage.show_add_button(True)
     self._packagesPage.show_remove_button(self._packagesPage.has_selection())
     self._packagesPage.show_defaults_button(False)
     
     loggingGroup = ttk.LabelFrame(parent,
                                  text='Logging Configuration',
                                  padding=(6,6,6,6),
                                  borderwidth=4,
                                  relief=tk.GROOVE)
     loggingGroup.grid(padx=(7,7),pady=6,row=3, column=0,sticky='nsw')
     loggingGroup.columnconfigure(1,pad=7)
     
     loglevel = get_logging_level()
     
     ttk.Label(loggingGroup,
               text="Level:",
               borderwidth=0,
               anchor=tk.E).grid(row=0, column=0,sticky='nsew')
     self._levelCombo = ttk.Combobox(loggingGroup,
                               exportselection=0,
                               state='readonly',
                               values=list(PreferencesDialog._LOG_LEVELS.values()))
     index = list(PreferencesDialog._LOG_LEVELS.keys()).index(loglevel)
     self._levelCombo.current(index)
     self._levelCombo.grid(row=0, column=1,sticky='nsw')
     
     self.entry = self._qconfigview.initial_focus
     return self.entry # initial focus