Exemplo n.º 1
0
    def save_current(self, path=None):
        """
        Save current editor content. Leave file to None to erase the previous
        file content. If the current editor's file_path is None and path
        is None, the function will call
        ``QtWidgets.QFileDialog.getSaveFileName`` to get a valid save filename.

        :param path: path of the file to save, leave it None to overwrite
            existing file.

        """
        try:
            if not path and not self._current.file.path:
                path, filter = QtWidgets.QFileDialog.getSaveFileName(
                    self, _('Choose destination path'))
                if not path:
                    return False
            old_path = self._current.file.path
            code_edit = self._current
            self._save_editor(code_edit, path)
            path = code_edit.file.path
            # path (and icon) may have changed
            if path and old_path != path:
                self._ensure_unique_name(code_edit, code_edit.file.name)
                self.setTabText(self.currentIndex(), code_edit._tab_name)
                ext = os.path.splitext(path)[1]
                old_ext = os.path.splitext(old_path)[1]
                if ext != old_ext or not old_path:
                    icon = QtWidgets.QFileIconProvider().icon(
                        QtCore.QFileInfo(code_edit.file.path))
                    self.setTabIcon(self.currentIndex(), icon)
            return True
        except AttributeError:  # not an editor widget
            pass
        return False
Exemplo n.º 2
0
    def __init__(self,
                 parent,
                 recent_files_manager=None,
                 title='Recent files',
                 icon_provider=None,
                 clear_icon=('edit-clear', '')):
        """
        :param organisation: name of your organisation as used for your own
                             QSettings
        :param application: name of your application as used for your own
                            QSettings
        :param parent: parent object

        :param icon_provider: Object that provides icon based on the file path.
        :type icon_provider: QtWidgets.QFileIconProvider

        :param clear_icon: Clear action icon. This parameter is a tuple made up
            of the icon theme name and the fallback icon path (from your
            resources). Default is None, clear action has no icons.
        """
        super(MenuRecentFiles, self).__init__(title, parent)
        if icon_provider is None:
            self.icon_provider = QtWidgets.QFileIconProvider()
        else:
            self.icon_provider = icon_provider
        self.clear_icon = clear_icon
        #: Recent files manager
        self.manager = recent_files_manager
        #: List of recent files actions
        self.recent_files_actions = []
        self.update_actions()
Exemplo n.º 3
0
 def __init__(self, parent=None):
     super(FileSystemTreeView, self).__init__(parent)
     self.context_menu = None
     self._root_path = None
     self.root_path = ''
     self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self.customContextMenuRequested.connect(self._show_context_menu)
     self.helper = FileSystemHelper(self)
     self.setSelectionMode(self.ExtendedSelection)
     self._ignored_patterns = []
     self._icon_provider = QtWidgets.QFileIconProvider()
     self._hide_extra_colums = True
     from pyqode.core.widgets import FileIconProvider
     self.set_icon_provider(FileIconProvider())
Exemplo n.º 4
0
 def _update_recents(self):
     """
     Updates the recent files list.
     """
     self.ui.listWidgetRecents.clear()
     for file in self.app.file.recent_files_manager.get_recent_files():
         item = QtWidgets.QListWidgetItem()
         if ('.' + QtCore.QFileInfo(file).suffix().upper()
                 in CobolCodeEdit.extensions):
             icon = QtGui.QIcon(icons.ICON_MIMETYPE)
         else:
             icon = QtWidgets.QFileIconProvider().icon(
                 QtCore.QFileInfo(file))
         item.setText(QtCore.QFileInfo(file).fileName())
         item.setToolTip(file)
         item.setIcon(icon)
         item.setData(QtCore.Qt.UserRole, file)
         self.ui.listWidgetRecents.addItem(item)
Exemplo n.º 5
0
 def icon(self, type_or_info):
     if 'linux' in sys.platform:
         if isinstance(type_or_info, QtCore.QFileInfo):
             if type_or_info.isDir():
                 return QtGui.QIcon.fromTheme('folder')
             else:
                 ret_val = self.mimetype_icon(
                     type_or_info.absoluteFilePath())
                 return ret_val
         else:
             map = {
                 FileIconProvider.File:
                 QtGui.QIcon.fromTheme('text-x-generic'),
                 FileIconProvider.Folder: QtGui.QIcon.fromTheme('folder'),
             }
             try:
                 return map[type_or_info]
             except KeyError:
                 return super().icon(type_or_info)
     else:
         return QtWidgets.QFileIconProvider().icon(type_or_info)
Exemplo n.º 6
0
 def _get_icon(self):
     return QtWidgets.QFileIconProvider().icon(QtCore.QFileInfo(self.path))
Exemplo n.º 7
0
 def _add_file(self, path):
     icon = QtWidgets.QFileIconProvider().icon(QtCore.QFileInfo(path))
     item = QtWidgets.QListWidgetItem(icon, path)
     self.listWidget.addItem(item)
Exemplo n.º 8
0
    def _init_actions(self):
        def _icon(theme, rc_path):
            return QtGui.QIcon.fromTheme(theme, QtGui.QIcon(rc_path))

        # New - submenu
        self.menu_new = self.addMenu("&New")
        self.menu_new.setIcon(QtGui.QIcon.fromTheme('document-new'))
        # https://github.com/pyQode/pyqode.core/pull/153
        new_user_actions = self.get_new_user_actions()
        if len(new_user_actions) > 0:
            self.menu_new.addSeparator()
            for user_new_action in self.get_new_user_actions():
                self.menu_new.addAction(user_new_action)
        # New file
        self.action_create_file = QtWidgets.QAction('&File', self)
        self.action_create_file.triggered.connect(
            self._on_create_file_triggered)
        icon_provider = QtWidgets.QFileIconProvider()
        self.action_create_file.setIcon(icon_provider.icon(icon_provider.File))
        self.menu_new.addAction(self.action_create_file)
        # New directory
        self.action_create_directory = QtWidgets.QAction('&Directory', self)
        self.action_create_directory.triggered.connect(
            self._on_create_directory_triggered)
        self.action_create_directory.setIcon(icon_provider.icon(
            icon_provider.Folder))
        self.menu_new.addAction(self.action_create_directory)
        self.addSeparator()

        # cut
        self.action_cut = QtWidgets.QAction('&Cut', self)
        self.action_cut.setShortcut(QtGui.QKeySequence.Cut)
        self.action_cut.setIcon(_icon(
            'edit-cut', ':/pyqode-icons/rc/edit-cut.png'))
        self.addAction(self.action_cut)
        self.action_cut.triggered.connect(self._on_cut_triggered)
        # copy
        self.action_copy = QtWidgets.QAction('&Copy', self)
        self.action_copy.setShortcut(QtGui.QKeySequence.Copy)
        self.action_copy.setIcon(_icon(
            'edit-copy', ':/pyqode-icons/rc/edit-copy.png'))
        self.addAction(self.action_copy)
        self.action_copy.triggered.connect(self._on_copy_triggered)
        # copy path
        self.action_copy_path = QtWidgets.QAction('&Copy path', self)
        self.action_copy_path.setShortcut('Ctrl+Shift+C')
        self.addAction(self.action_copy_path)
        self.action_copy_path.triggered.connect(self._on_copy_path_triggered)
        # Paste
        self.action_paste = QtWidgets.QAction('&Paste', self)
        self.action_paste.setShortcut(QtGui.QKeySequence.Paste)
        self.action_paste.setIcon(_icon(
            'edit-paste', ':/pyqode-icons/rc/edit-paste.png'))
        self.action_paste.triggered.connect(self._on_paste_triggered)
        self.addAction(self.action_paste)
        self.addSeparator()
        # Rename
        self.action_rename = QtWidgets.QAction('&Rename', self)
        self.action_rename.setShortcut('Shift+F2')
        self.action_rename.triggered.connect(self._on_rename_triggered)
        self.addAction(self.action_rename)
        # Delete
        self.action_delete = QtWidgets.QAction('&Delete', self)
        self.action_delete.setShortcut(QtGui.QKeySequence.Delete)
        self.action_delete.setIcon(_icon(
            'edit-delete', ':/pyqode-icons/rc/edit-delete.png'))
        self.action_delete.triggered.connect(self._on_delete_triggered)
        self.addAction(self.action_delete)
        self.addSeparator()

        system = platform.system()
        if system == 'Windows':
            text = 'Open in explorer'
        elif system == 'Darwin':
            text = 'Open in finder'
        else:
            text = 'Show in %s' % self.get_linux_file_explorer().capitalize()
        action = self.addAction(text)
        action.triggered.connect(self._on_show_in_explorer_triggered)
Exemplo n.º 9
0
def init():
    global new_file
    global open_file
    global new_folder
    global open_folder
    global save
    global save_as
    global run
    global stop
    global python_mimetype
    global python_interpreter
    global python_virtualenv
    global preferences
    global help_about
    global help_contents
    global clear
    global configure
    global terminal
    global class_browser
    global window_close
    global application_exit
    global list_add
    global list_remove
    global go_up
    global go_down
    global qidle
    global appearance
    global text_edit
    global folder
    global file
    global preferences_plugin

    new_file = icon(':/icons/document-new.png', 'document-new')
    open_file = icon(':/icons/document-open.png', 'document-open')
    new_folder = icon(':/icons/folder-new.png', 'folder-new')
    open_folder = icon(':/icons/folder-open.png', 'folder-open')
    save = icon(':/icons/document-save.png', 'document-save')
    save_as = icon(':/icons/document-save-as.png', 'document-save-as')
    run = icon(':/icons/media-playback-start.png', 'media-playback-start')
    stop = icon(':/icons/media-playback-stop.png', 'media-playback-stop')
    python_mimetype = icon(':/icons/application-x-python.png', 'text-x-python')
    python_interpreter = icon(':/icons/interpreter-sys.png')
    python_virtualenv = icon(':/icons/interpreter-venv.png')
    preferences = icon(':/icons/Preferences-system.png', 'preferences-system')
    help_about = icon(':/icons/dialog-information.png', 'help-about')
    help_contents = icon(':/icons/help.png', 'help-contents')
    clear = icon(':/icons/edit-clear.png', 'edit-clear')
    configure = icon(':/icons/system-run.png', 'system-run')
    terminal = icon(':/icons/terminal.png', 'terminal')
    class_browser = icon(':/pyqode_python_icons/rc/class.png')
    window_close = icon(':/icons/dialog-close.png', 'window-close')
    application_exit = icon(':/icons/exit.png', 'exit')
    list_add = icon(':/icons/list-add.png', 'list-add')
    list_remove = icon(':/icons/list-remove.png', 'list-remove')
    go_up = icon(':/icons/go-up.png', 'go-up')
    go_down = icon(':/icons/go-up.png', 'go-down')
    qidle = icon(':/icons/QIdle.png')
    appearance = icon(':/icons/applications-graphics.png',
                      'applications-graphics')
    text_edit = icon(':/icons/application-x-text-edit.png',
                     'accessories-text-editor')
    folder = QtWidgets.QFileIconProvider().icon(
        QtWidgets.QFileIconProvider.Folder)
    file = QtWidgets.QFileIconProvider().icon(QtWidgets.QFileIconProvider.File)
    preferences_plugin = icon(':/icons/preferences-plugin.png',
                              'network-wired')