コード例 #1
0
ファイル: client_api.py プロジェクト: amccarty/ac0n3
    def set_domain(self, domain='https://api.anaconda.org'):
        """Reset current api domain."""
        logger.debug('Setting domain {}'.format(domain))
        config = binstar_client.utils.get_config()
        config['url'] = domain

        try:
            binstar_client.utils.set_config(config)
        except binstar_client.errors.BinstarError:
            logger.error('Could not write anaconda client configuation')
            traceback = format_exc()
            msg_box = MessageBoxError(
                title='Anaconda Client configuration error',
                text='Anaconda Client domain could not be updated.<br><br>'
                'This may result in Navigator not working properly.<br>',
                error='<pre>' + traceback + '</pre>',
                report=False,
                learn_more=None,
            )
            msg_box.exec_()

        self._anaconda_client_api = binstar_client.utils.get_server_api(
            token=None,
            log_level=logging.NOTSET,
        )
コード例 #2
0
 def move(self, fnames=None):
     """Move files/directories."""
     if fnames is None:
         fnames = self.get_selected_filenames()
     orig = fixpath(osp.dirname(fnames[0]))
     while True:
         self.redirect_stdio.emit(False)
         folder = getexistingdirectory(self, "Select directory", orig)
         self.redirect_stdio.emit(True)
         if folder:
             folder = fixpath(folder)
             if folder != orig:
                 break
         else:
             return
     for fname in fnames:
         basename = osp.basename(fname)
         try:
             misc.move_file(fname, osp.join(folder, basename))
         except EnvironmentError as error:
             msg_box = MessageBoxError(
                 text="<b>Unable to move <i>%s</i></b>"
                 "<br><br>Error message:<br>%s" %
                 (basename, to_text_string(error)),
                 title='Error',
             )
             msg_box.exec_()
コード例 #3
0
    def create_new_file(self, current_path, title, filters, create_func):
        """
        Create new file.

        Returns True if successful.
        """
        if current_path is None:
            current_path = ''
        if osp.isfile(current_path):
            current_path = osp.dirname(current_path)
        self.redirect_stdio.emit(False)
        fname, _selfilter = getsavefilename(self, title, current_path, filters)
        self.redirect_stdio.emit(True)
        if fname:
            try:
                create_func(fname)
                return fname
            except EnvironmentError as error:
                msg_box = MessageBoxError(
                    text="<b>Unable to create file <i>%s</i>"
                    "</b><br><br>Error message:<br>%s" %
                    (fname, to_text_string(error)),
                    title='New file error',
                )
                msg_box.exec_()
コード例 #4
0
 def chdir(self, directory=None, browsing_history=False):
     """Set directory as working directory."""
     if directory is not None:
         directory = osp.abspath(to_text_string(directory))
     if browsing_history:
         directory = self.history[self.histindex]
     elif directory in self.history:
         self.histindex = self.history.index(directory)
     else:
         if self.histindex is None:
             self.history = []
         else:
             self.history = self.history[:self.histindex + 1]
         if len(self.history) == 0 or \
            (self.history and self.history[-1] != directory):
             self.history.append(directory)
         self.histindex = len(self.history) - 1
     directory = to_text_string(directory)
     #        if PY2:
     #            PermissionError = OSError
     if os.path.isdir(directory):
         try:
             os.chdir(directory)
             self.sig_open_dir.emit(directory)
             self.refresh(new_path=directory, force_current=True)
         except OSError:
             #        except PermissionError:
             msg_box = MessageBoxError(
                 text="You don't have the right permissions to "
                 "open this directory",
                 title='Error',
             )
             msg_box.exec_()
         self.sig_changed_dir.emit()
コード例 #5
0
 def convert_notebook(self, fname):
     """Convert an IPython notebook to a Python script in editor."""
     try:
         script = nbexporter().from_filename(fname)[0]
     except Exception as e:
         msg_box = MessageBoxError(
             text="It was not possible to convert this "
             "notebook. The error is:\n\n" + to_text_string(e),
             title='Conversion error',
         )
         msg_box.exec_()
         return
     self.sig_new_file.emit(script)
コード例 #6
0
 def rename_file(self, fname):
     """Rename file."""
     dlg = InputDialog(
         title='Rename',
         text='New name:',
         value=osp.basename(fname),
     )
     if dlg.exec_():
         path = dlg.text.text()
         path = osp.join(osp.dirname(fname), to_text_string(path))
         if path == fname:
             return
         if osp.exists(path):
             msg_box = MessageBoxQuestion(
                 self,
                 title="Rename",
                 text="Do you really want to rename <b>%s</b> and "
                 "overwrite the existing file <b>%s</b>?" %
                 (osp.basename(fname), osp.basename(path)),
             )
             if not msg_box.exec_():
                 return
         try:
             misc.rename_file(fname, path)
             self.sig_renamed.emit(fname, path)
             return path
         except EnvironmentError as error:
             msg_box = MessageBoxError(
                 text="<b>Unable to rename file <i>%s</i></b>"
                 "<br><br>Error message:<br>%s" %
                 (osp.basename(fname), to_text_string(error)),
                 title='Rename error',
             )
             msg_box.exec_()
コード例 #7
0
def display_qt_error_box(error, traceback):
    """Display a Qt styled error message box."""
    from anaconda_navigator.widgets.dialogs import MessageBoxError
    text = ('An unexpected error occurred on Navigator start-up<br>'
            '{error}'.format(error=error))
    trace = '{trace}'.format(trace=traceback)
    print(text)
    print(trace)
    msg_box = MessageBoxError(
        title='Navigator Error',
        text=text,
        error=trace,
        report=True,
        learn_more=None,
    )
    msg_box.setFixedWidth(600)
    return msg_box.exec_()
コード例 #8
0
ファイル: client_api.py プロジェクト: amccarty/ac0n3
 def set_api_url(url):
     """Set the anaconda client url configuration."""
     config_data = binstar_client.utils.get_config()
     config_data['url'] = url
     try:
         binstar_client.utils.set_config(config_data)
     except Exception as e:
         logger.error('Could not write anaconda client configuration')
         msg_box = MessageBoxError(
             title='Anaconda Client configuration error',
             text='Anaconda Client configuration could not be updated.<br>'
             'This may result in Navigator not working properly.<br>',
             error=e,
             report=False,
             learn_more=None,
         )
         msg_box.exec_()
コード例 #9
0
ファイル: client_api.py プロジェクト: amccarty/ac0n3
 def set_ssl(self, value):
     """Set the anaconda client url configuration."""
     config_data = binstar_client.utils.get_config()
     config_data['verify_ssl'] = value
     try:
         binstar_client.utils.set_config(config_data)
         self._conda_api.config_set('ssl_verify', value).communicate()
     except Exception as e:
         logger.error('Could not write anaconda client configuration')
         msg_box = MessageBoxError(
             title='Anaconda Client configuration error',
             text='Anaconda Client configuration could not be updated.<br>'
             'This may result in Navigator not working properly.<br>',
             error=e,
             report=False,
             learn_more=None,
         )
         msg_box.exec_()
コード例 #10
0
    def delete_file(self, fname, multiple, yes_to_all):
        """Delete file."""
        # if multiple:
        #     buttons = (
        #         QMessageBox.Yes | QMessageBox.YesAll | QMessageBox.No |
        #         QMessageBox.Cancel
        #        )
        # else:
        #     buttons = QMessageBox.Yes | QMessageBox.No
        msg_box = MessageBoxQuestion(
            title="Delete",
            text="Do you really want to delete "
            "<b>{0}</b>?".format(osp.basename(fname)),
        )

        if msg_box.exec_():
            yes_to_all = True
        else:
            return False


#            if answer == QMessageBox.No:
#                return yes_to_all
#            elif answer == QMessageBox.Cancel:
#                return False
#            elif answer == QMessageBox.YesAll:
#                yes_to_all = True
        try:
            if osp.isfile(fname):
                misc.remove_file(fname)
                self.sig_removed.emit(fname)
            else:
                self.remove_tree(fname)
                self.sig_removed_tree.emit(fname)
            return yes_to_all
        except EnvironmentError as error:
            action_str = 'delete'
            msg_box = MessageBoxError(
                text="<b>Unable to %s <i>%s</i></b>"
                "<br><br>Error message:<br>%s" %
                (action_str, fname, to_text_string(error)),
                title='Project Explorer',
            )
            msg_box.exec_()
        return False
コード例 #11
0
    def create_new_folder(self, current_path, title, subtitle, is_package):
        """Create new folder."""
        if current_path is None:
            current_path = ''
        if osp.isfile(current_path):
            current_path = osp.dirname(current_path)

        dlg = InputDialog(title=title, text=subtitle, value='')
        if dlg.exec_():
            name = dlg.text.text()
            dirname = osp.join(current_path, to_text_string(name))
            try:
                os.mkdir(dirname)
            except EnvironmentError as error:
                msg_box = MessageBoxError(
                    text="<b>Unable "
                    "to create folder <i>%s</i></b>"
                    "<br><br>Error message:<br>%s" %
                    (dirname, to_text_string(error)),
                    title=title,
                )
                msg_box.exec_()
            finally:
                if is_package:
                    fname = osp.join(dirname, '__init__.py')
                    try:
                        with open(fname, 'wb') as f:
                            f.write(to_binary_string('#'))
                        return dirname
                    except EnvironmentError as error:
                        msg_box = MessageBoxError(
                            text="<b>Unable "
                            "to create file <i>%s</i></b>"
                            "<br><br>Error message:<br>%s" %
                            (fname, to_text_string(error)),
                            title=title,
                        )
                        msg_box.exec_()
コード例 #12
0
ファイル: main_window.py プロジェクト: fisher2017/Anaconda
 def _update_application(self, worker, output, error):
     self.button_update_available.setDisabled(False)
     if error:
         text = 'Anaconda Navigator Update error:'
         dlg = MessageBoxError(text=text,
                               error=error,
                               title='Application Update Error')
         self.tracker.track_page('/update/error',
                                 pagetitle='Update Application Error '
                                 'Message Box')
         dlg.exec_()
     else:
         text = ('Anaconda Navigator Updated succefully.\n\n'
                 'Please restart the application')
         dlg = MessageBoxInformation(text=text, title='Application Update')
         self.tracker.track_page('/update/successful',
                                 pagetitle='Application Update Succesful '
                                 'Message Box')
         dlg.exec_()
     self._track_tab()