Example #1
0
    def update_warning(self, warning_type=NO_WARNING, conflicts=[]):
        """Update warning label to reflect conflict status of new shortcut"""
        if warning_type == NO_WARNING:
            warn = False
            tip = 'This shortcut is correct!'
        elif warning_type == SEQUENCE_CONFLICT:
            template = '<i>{0}<b>{1}</b></i>'
            tip_title = _('The new shorcut conflicts with:') + '<br>'
            tip_body = ''
            for s in conflicts:
                tip_body += ' - {0}: {1}<br>'.format(s.context, s.name)
            tip_body = tip_body[:-4]  # Removing last <br>
            tip = template.format(tip_title, tip_body)
            warn = True
        elif warning_type == SEQUENCE_LENGTH:
            # Sequences with 5 keysequences (i.e. Ctrl+1, Ctrl+2, Ctrl+3,
            # Ctrl+4, Ctrl+5) are invalid
            template = '<i>{0}</i>'
            tip = _('A compound sequence can have {break} a maximum of '
                    '4 subsequences.{break}').format(**{'break': '<br>'})
            warn = True
        elif warning_type == INVALID_KEY:
            template = '<i>{0}</i>'
            tip = _('Invalid key entered') + '<br>'
            warn = True

        self.helper_button.show()
        if warn:
            self.label_warning.show()
            self.helper_button.setIcon(get_std_icon('MessageBoxWarning'))
            self.button_ok.setEnabled(False)
        else:
            self.helper_button.setIcon(get_std_icon('DialogApplyButton'))

        self.label_warning.setText(tip)
Example #2
0
    def __init__(self, parent=None, name_filters=['*.py', '*.pyw'],
                 show_all=False, show_cd_only=None, show_icontext=True):
        QWidget.__init__(self, parent)
        
        self.treewidget = ExplorerTreeWidget(self, show_cd_only=show_cd_only)
        self.treewidget.setup(name_filters=name_filters, show_all=show_all)
        self.treewidget.chdir(getcwd())
        
        icontext_action = create_action(self, _("Show icons and text"),
                                        toggled=self.toggle_icontext)
        self.treewidget.common_actions += [None, icontext_action]
        
        # Setup toolbar
        self.toolbar = QToolBar(self)
        self.toolbar.setIconSize(QSize(16, 16))
        
        self.previous_action = create_action(self, text=_("Previous"),
                            icon=get_std_icon("ArrowBack"),
                            triggered=self.treewidget.go_to_previous_directory)
        self.toolbar.addAction(self.previous_action)
        self.previous_action.setEnabled(False)
        self.connect(self.treewidget, SIGNAL("set_previous_enabled(bool)"),
                     self.previous_action.setEnabled)
        
        self.next_action = create_action(self, text=_("Next"),
                            icon=get_std_icon("ArrowForward"),
                            triggered=self.treewidget.go_to_next_directory)
        self.toolbar.addAction(self.next_action)
        self.next_action.setEnabled(False)
        self.connect(self.treewidget, SIGNAL("set_next_enabled(bool)"),
                     self.next_action.setEnabled)
        
        parent_action = create_action(self, text=_("Parent"),
                            icon=get_std_icon("ArrowUp"),
                            triggered=self.treewidget.go_to_parent_directory)
        self.toolbar.addAction(parent_action)
        self.toolbar.addSeparator()

        options_action = create_action(self, text='', tip=_("Options"),
                                       icon=get_icon('tooloptions.png'))
        self.toolbar.addAction(options_action)
        widget = self.toolbar.widgetForAction(options_action)
        widget.setPopupMode(QToolButton.InstantPopup)
        menu = QMenu(self)
        add_actions(menu, self.treewidget.common_actions)
        options_action.setMenu(menu)
            
        icontext_action.setChecked(show_icontext)
        self.toggle_icontext(show_icontext)     
        
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.toolbar)
        vlayout.addWidget(self.treewidget)
        self.setLayout(vlayout)
 def setup_context_menu(self):
     """Reimplement PythonShellWidget method"""
     PythonShellWidget.setup_context_menu(self)
     self.help_action = create_action(self, _("Help..."),
                        icon=get_std_icon('DialogHelpButton'),
                        triggered=self.help)
     self.menu.addAction(self.help_action)
 def setup_context_menu(self):
     """Reimplement PythonShellWidget method"""
     PythonShellWidget.setup_context_menu(self)
     self.help_action = create_action(self, _("Help..."),
                        icon=get_std_icon('DialogHelpButton'),
                        triggered=self.help)
     self.menu.addAction(self.help_action)
Example #5
0
 def add_actions_to_context_menu(self, menu):
     """Add actions to IPython widget context menu"""
     # See spyderlib/widgets/ipython.py for more details on this method
     inspect_action = create_action(
         self,
         _("Inspect current object"),
         QKeySequence(get_shortcut('console', 'inspect current object')),
         icon=get_std_icon('MessageBoxInformation'),
         triggered=self.inspect_object)
     clear_line_action = create_action(self,
                                       _("Clear line or block"),
                                       QKeySequence("Shift+Escape"),
                                       icon=get_icon('eraser.png'),
                                       triggered=self.clear_line)
     clear_console_action = create_action(
         self,
         _("Clear console"),
         QKeySequence(get_shortcut('console', 'clear shell')),
         icon=get_icon('clear.png'),
         triggered=self.clear_console)
     quit_action = create_action(self,
                                 _("&Quit"),
                                 icon='exit.png',
                                 triggered=self.exit_callback)
     add_actions(menu, (None, inspect_action, clear_line_action,
                        clear_console_action, None, quit_action))
     return menu
Example #6
0
 def get_toolbar_buttons(self):
     ExternalShellBase.get_toolbar_buttons(self)
     if self.namespacebrowser_button is None and self.stand_alone:
         self.namespacebrowser_button = create_toolbutton(self,
                       get_icon('dictedit.png'), self.tr("Variables"),
                       tip=self.tr("Show/hide global variables explorer"),
                       toggled=self.toggle_globals_explorer)
     if self.cwd_button is None:
         self.cwd_button = create_toolbutton(self,
                       get_std_icon('DirOpenIcon'), self.tr("Working directory"),
                       tip=self.tr("Set current working directory"),
                       triggered=self.set_current_working_directory)
     if self.terminate_button is None:
         self.terminate_button = create_toolbutton(self,
                       get_icon('terminate.png'), self.tr("Terminate"),
                       tip=self.tr("Attempts to terminate the process.\n"
                                   "The process may not exit as a result of "
                                   "clicking this button\n"
                                   "(it is given the chance to prompt "
                                   "the user for any unsaved files, etc)."))        
     buttons = [self.cwd_button]
     if self.namespacebrowser_button is not None:
         buttons.append(self.namespacebrowser_button)
     buttons += [self.run_button, self.options_button,
                 self.terminate_button, self.kill_button]
     return buttons
Example #7
0
 def create_browsefile(self,
                       text,
                       option,
                       default=NoDefault,
                       tip=None,
                       filters=None):
     widget = self.create_lineedit(text,
                                   option,
                                   default,
                                   alignment=Qt.Horizontal)
     for edit in self.lineedits:
         if widget.isAncestorOf(edit):
             break
     msg = _("Invalid file path")
     self.validate_data[edit] = (osp.isfile, msg)
     browse_btn = QPushButton(get_std_icon('FileIcon'), "", self)
     browse_btn.setToolTip(_("Select file"))
     self.connect(browse_btn, SIGNAL("clicked()"),
                  lambda: self.select_file(edit, filters))
     layout = QHBoxLayout()
     layout.addWidget(widget)
     layout.addWidget(browse_btn)
     layout.setContentsMargins(0, 0, 0, 0)
     browsedir = QWidget(self)
     browsedir.setLayout(layout)
     return browsedir
Example #8
0
 def get_options_menu(self):
     ExternalShellBase.get_options_menu(self)
     self.interact_action = create_action(self, _("Interact"))
     self.interact_action.setCheckable(True)
     self.debug_action = create_action(self, _("Debug"))
     self.debug_action.setCheckable(True)
     self.args_action = create_action(self, _("Arguments..."),
                                      triggered=self.get_arguments)
     run_settings_menu = QMenu(_("Run settings"), self)
     add_actions(run_settings_menu,
                 (self.interact_action, self.debug_action, self.args_action))
     self.cwd_button = create_action(self, _("Working directory"),
                             icon=get_std_icon('DirOpenIcon'),
                             tip=_("Set current working directory"),
                             triggered=self.set_current_working_directory)
     self.env_button = create_action(self, _("Environment variables"),
                                     icon=get_icon('environ.png'),
                                     triggered=self.show_env)
     self.syspath_button = create_action(self,
                                         _("Show sys.path contents"),
                                         icon=get_icon('syspath.png'),
                                         triggered=self.show_syspath)
     actions = [run_settings_menu, self.show_time_action, None,
                self.cwd_button, self.env_button, self.syspath_button]
     if self.menu_actions is not None:
         actions += [None]+self.menu_actions
     return actions
Example #9
0
 def get_options_menu(self):
     ExternalShellBase.get_options_menu(self)
     self.interact_action = create_action(self, _("Interact"))
     self.interact_action.setCheckable(True)
     self.debug_action = create_action(self, _("Debug"))
     self.debug_action.setCheckable(True)
     self.args_action = create_action(self, _("Arguments..."),
                                      triggered=self.get_arguments)
     self.post_mortem_action = create_action(self, _("Post Mortem Debug"))
     self.post_mortem_action.setCheckable(True)
     run_settings_menu = QMenu(_("Run settings"), self)
     add_actions(run_settings_menu,
                 (self.interact_action, self.debug_action, self.args_action,
                  self.post_mortem_action))
     self.cwd_button = create_action(self, _("Working directory"),
                             icon=get_std_icon('DirOpenIcon'),
                             tip=_("Set current working directory"),
                             triggered=self.set_current_working_directory)
     self.env_button = create_action(self, _("Environment variables"),
                                     icon=get_icon('environ.png'),
                                     triggered=self.show_env)
     self.syspath_button = create_action(self,
                                         _("Show sys.path contents"),
                                         icon=get_icon('syspath.png'),
                                         triggered=self.show_syspath)
     actions = [run_settings_menu, self.show_time_action, None,
                self.cwd_button, self.env_button, self.syspath_button]
     if self.menu_actions is not None:
         actions += [None]+self.menu_actions
     return actions
Example #10
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.runconf = RunConfiguration()

        common_group = QGroupBox(_("General settings"))
        common_layout = QGridLayout()
        common_group.setLayout(common_layout)
        self.clo_cb = QCheckBox(_("Command line options:"))
        common_layout.addWidget(self.clo_cb, 0, 0)
        self.clo_edit = QLineEdit()
        self.connect(self.clo_cb, SIGNAL("toggled(bool)"), self.clo_edit.setEnabled)
        self.clo_edit.setEnabled(False)
        common_layout.addWidget(self.clo_edit, 0, 1)
        self.wd_cb = QCheckBox(_("Working directory:"))
        common_layout.addWidget(self.wd_cb, 1, 0)
        wd_layout = QHBoxLayout()
        self.wd_edit = QLineEdit()
        self.connect(self.wd_cb, SIGNAL("toggled(bool)"), self.wd_edit.setEnabled)
        self.wd_edit.setEnabled(False)
        wd_layout.addWidget(self.wd_edit)
        browse_btn = QPushButton(get_std_icon("DirOpenIcon"), "", self)
        browse_btn.setToolTip(_("Select directory"))
        self.connect(browse_btn, SIGNAL("clicked()"), self.select_directory)
        wd_layout.addWidget(browse_btn)
        common_layout.addLayout(wd_layout, 1, 1)

        radio_group = QGroupBox(_("Interpreter"))
        radio_layout = QVBoxLayout()
        radio_group.setLayout(radio_layout)
        self.current_radio = QRadioButton(_("Execute in current Python " "or IPython interpreter"))
        radio_layout.addWidget(self.current_radio)
        self.new_radio = QRadioButton(_("Execute in a new dedicated " "Python interpreter"))
        radio_layout.addWidget(self.new_radio)
        self.systerm_radio = QRadioButton(_("Execute in an external " "system terminal"))
        radio_layout.addWidget(self.systerm_radio)

        new_group = QGroupBox(_("Dedicated Python interpreter"))
        self.connect(self.current_radio, SIGNAL("toggled(bool)"), new_group.setDisabled)
        new_layout = QGridLayout()
        new_group.setLayout(new_layout)
        self.interact_cb = QCheckBox(_("Interact with the Python " "interpreter after execution"))
        new_layout.addWidget(self.interact_cb, 1, 0, 1, -1)
        self.pclo_cb = QCheckBox(_("Command line options:"))
        new_layout.addWidget(self.pclo_cb, 2, 0)
        self.pclo_edit = QLineEdit()
        self.connect(self.pclo_cb, SIGNAL("toggled(bool)"), self.pclo_edit.setEnabled)
        self.pclo_edit.setEnabled(False)
        new_layout.addWidget(self.pclo_edit, 2, 1)
        pclo_label = QLabel(_("The <b>-u</b> option is " "added to these commands"))
        pclo_label.setWordWrap(True)
        new_layout.addWidget(pclo_label, 3, 1)

        # TODO: Add option for "Post-mortem debugging"

        layout = QVBoxLayout()
        layout.addWidget(common_group)
        layout.addWidget(radio_group)
        layout.addWidget(new_group)
        self.setLayout(layout)
Example #11
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist:
         item = QListWidgetItem(name)
         item.setIcon(get_std_icon('DirClosedIcon'))
         self.listwidget.addItem(item)
     self.refresh()
Example #12
0
 def create_dir_item(dirname, parent):
     if dirname != root_path:
         displayed_name = osp.basename(dirname)
     else:
         displayed_name = dirname
     item = QTreeWidgetItem(parent, [displayed_name])
     item.setIcon(0, get_std_icon('DirClosedIcon'))
     return item
Example #13
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist:
         item = QListWidgetItem(name)
         item.setIcon(get_std_icon('DirClosedIcon'))
         self.listwidget.addItem(item)
     self.refresh()
Example #14
0
 def create_dir_item(dirname, parent):
     if dirname != root_path:
         displayed_name = osp.basename(dirname)
     else:
         displayed_name = dirname
     item = QTreeWidgetItem(parent, [displayed_name])
     item.setIcon(0, get_std_icon('DirClosedIcon'))
     return item
Example #15
0
 def update_warning(self):
     """ """
     widget = self._button_warning
     if not self.is_valid():
         tip = _('Array dimensions not valid')
         widget.setIcon(get_std_icon('MessageBoxWarning'))
         widget.setToolTip(tip)
         QToolTip.showText(self._widget.mapToGlobal(QPoint(0, 5)), tip)
     else:
         self._button_warning.setToolTip('')
Example #16
0
 def update_warning(self):
     """ """
     widget = self._button_warning
     if not self.is_valid():
         tip = _('Array dimensions not valid')
         widget.setIcon(get_std_icon('MessageBoxWarning'))
         widget.setToolTip(tip)
         QToolTip.showText(self._widget.mapToGlobal(QPoint(0, 5)), tip)
     else:
         self._button_warning.setToolTip('')
Example #17
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist + self.ro_pathlist:
         item = QListWidgetItem(name)
         item.setIcon(get_std_icon("DirClosedIcon"))
         if name in self.ro_pathlist:
             item.setFlags(Qt.NoItemFlags)
         self.listwidget.addItem(item)
     self.refresh()
Example #18
0
    def update_warning(self, reset=False):
        """ """
        conflicts = self.check_conflicts()
        if reset:
            conflicts = []

        widget = self.helper_button

        if conflicts:
            tip_title = _('The new entered shorcut conflicts with:') + '\n'
            tip_body = ''
            for s in conflicts:
                tip_body += ' - {0}: {1}\n'.format(s.context, s.name)
            tip = '{0}{1}'.format(tip_title, tip_body)
            widget.setIcon(get_std_icon('MessageBoxWarning'))
            widget.setToolTip(tip)
            QToolTip.showText(widget.mapToGlobal(QPoint(0, 5)), tip)
        else:
            widget.setToolTip('')
            QToolTip.hideText()
            widget.setIcon(get_std_icon('DialogApplyButton'))
Example #19
0
 def __init__(self):
     QToolButton.__init__(self)
     self.setIcon(get_std_icon('MessageBoxInformation'))
     style = """
         QToolButton {
           border: 1px solid grey;
           padding:0px;
           border-radius: 2px;
           background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
               stop: 0 #f6f7fa, stop: 1 #dadbde);
         }
         """
     self.setStyleSheet(style)
Example #20
0
 def __init__(self):
     QToolButton.__init__(self)
     self.setIcon(get_std_icon('MessageBoxInformation'))
     style = """
         QToolButton {
           border: 1px solid grey;
           padding:0px;
           border-radius: 2px;
           background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
               stop: 0 #f6f7fa, stop: 1 #dadbde);
         }
         """
     self.setStyleSheet(style)
Example #21
0
 def create_browsedir(self, text, option, default=NoDefault, tip=None):
     widget = self.create_lineedit(text, option, default,
                                   alignment=Qt.Horizontal)
     for edit in self.lineedits:
         if widget.isAncestorOf(edit):
             break
     msg = _("Invalid directory path")
     self.validate_data[edit] = (osp.isdir, msg)
     browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self)
     browse_btn.setToolTip(_("Select directory"))
     browse_btn.clicked.connect(lambda: self.select_directory(edit))
     layout = QHBoxLayout()
     layout.addWidget(widget)
     layout.addWidget(browse_btn)
     layout.setContentsMargins(0, 0, 0, 0)
     browsedir = QWidget(self)
     browsedir.setLayout(layout)
     return browsedir
Example #22
0
 def create_browsedir(self, text, option, default=NoDefault, tip=None):
     widget = self.create_lineedit(text, option, default,
                                   alignment=Qt.Horizontal)
     for edit in self.lineedits:
         if widget.isAncestorOf(edit):
             break
     msg = _("Invalid directory path")
     self.validate_data[edit] = (osp.isdir, msg)
     browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self)
     browse_btn.setToolTip(_("Select directory"))
     browse_btn.clicked.connect(lambda: self.select_directory(edit))
     layout = QHBoxLayout()
     layout.addWidget(widget)
     layout.addWidget(browse_btn)
     layout.setContentsMargins(0, 0, 0, 0)
     browsedir = QWidget(self)
     browsedir.setLayout(layout)
     return browsedir
Example #23
0
 def create_browsefile(self, text, option, default=NoDefault, tip=None,
                       filters=None):
     widget = self.create_lineedit(text, option, default,
                                   alignment=Qt.Horizontal)
     for edit in self.lineedits:
         if widget.isAncestorOf(edit):
             break
     msg = _("Invalid file path")
     self.validate_data[edit] = (osp.isfile, msg)
     browse_btn = QPushButton(get_std_icon('FileIcon'), "", self)
     browse_btn.setToolTip(_("Select file"))
     self.connect(browse_btn, SIGNAL("clicked()"),
                  lambda: self.select_file(edit, filters))
     layout = QHBoxLayout()
     layout.addWidget(widget)
     layout.addWidget(browse_btn)
     layout.setContentsMargins(0, 0, 0, 0)
     browsedir = QWidget(self)
     browsedir.setLayout(layout)
     return browsedir
Example #24
0
 def add_actions_to_context_menu(self, menu):
     """Add actions to IPython widget context menu"""
     # See spyderlib/widgets/ipython.py for more details on this method
     inspect_action = create_action(self, _("Inspect current object"),
                                 QKeySequence("Ctrl+I"),
                                 icon=get_std_icon('MessageBoxInformation'),
                                 triggered=self.inspect_object)
     clear_line_action = create_action(self, _("Clear line or block"),
                                       QKeySequence("Shift+Escape"),
                                       icon=get_icon('eraser.png'),
                                       triggered=self.clear_line)
     clear_console_action = create_action(self, _("Clear console"),
                                          QKeySequence("Ctrl+L"),
                                          icon=get_icon('clear.png'),
                                          triggered=self.clear_console)
     quit_action = create_action(self, _("&Quit"), icon='exit.png',
                                 triggered=self.exit_callback)
     add_actions(menu, (None, inspect_action, clear_line_action,
                        clear_console_action, None, quit_action))
     return menu
    def __init__(self, parent, enable_replace=False):
        QWidget.__init__(self, parent)
        self.enable_replace = enable_replace
        self.editor = None
        self.is_code_editor = None
        
        glayout = QGridLayout()
        glayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(glayout)
        
        self.close_button = create_toolbutton(self, triggered=self.hide,
                                      icon=get_std_icon("DialogCloseButton"))
        glayout.addWidget(self.close_button, 0, 0)
        
        # Find layout
        self.search_text = PatternComboBox(self, tip=_("Search string"),
                                           adjust_to_minimum=False)
        self.connect(self.search_text, SIGNAL('valid(bool)'),
                     lambda state:
                     self.find(changed=False, forward=True, rehighlight=False))
        self.connect(self.search_text.lineEdit(),
                     SIGNAL("textEdited(QString)"), self.text_has_been_edited)
        
        self.previous_button = create_toolbutton(self,
                                             triggered=self.find_previous,
                                             icon=get_std_icon("ArrowBack"))
        self.next_button = create_toolbutton(self,
                                             triggered=self.find_next,
                                             icon=get_std_icon("ArrowForward"))
        self.connect(self.next_button, SIGNAL('clicked()'),
                     self.update_search_combo)
        self.connect(self.previous_button, SIGNAL('clicked()'),
                     self.update_search_combo)

        self.re_button = create_toolbutton(self, icon=get_icon("advanced.png"),
                                           tip=_("Regular expression"))
        self.re_button.setCheckable(True)
        self.connect(self.re_button, SIGNAL("toggled(bool)"),
                     lambda state: self.find())
        
        self.case_button = create_toolbutton(self,
                                             icon=get_icon("upper_lower.png"),
                                             tip=_("Case Sensitive"))
        self.case_button.setCheckable(True)
        self.connect(self.case_button, SIGNAL("toggled(bool)"),
                     lambda state: self.find())
                     
        self.words_button = create_toolbutton(self,
                                              icon=get_icon("whole_words.png"),
                                              tip=_("Whole words"))
        self.words_button.setCheckable(True)
        self.connect(self.words_button, SIGNAL("toggled(bool)"),
                     lambda state: self.find())
                     
        self.highlight_button = create_toolbutton(self,
                                              icon=get_icon("highlight.png"),
                                              tip=_("Highlight matches"))
        self.highlight_button.setCheckable(True)
        self.connect(self.highlight_button, SIGNAL("toggled(bool)"),
                     self.toggle_highlighting)

        hlayout = QHBoxLayout()
        self.widgets = [self.close_button, self.search_text,
                        self.previous_button, self.next_button,
                        self.re_button, self.case_button, self.words_button,
                        self.highlight_button]
        for widget in self.widgets[1:]:
            hlayout.addWidget(widget)
        glayout.addLayout(hlayout, 0, 1)

        # Replace layout
        replace_with = QLabel(_("Replace with:"))
        self.replace_text = PatternComboBox(self, adjust_to_minimum=False,
                                            tip=_("Replace string"))
        
        self.replace_button = create_toolbutton(self,
                                     text=_("Replace/find"),
                                     icon=get_std_icon("DialogApplyButton"),
                                     triggered=self.replace_find,
                                     text_beside_icon=True)
        self.connect(self.replace_button, SIGNAL('clicked()'),
                     self.update_replace_combo)
        self.connect(self.replace_button, SIGNAL('clicked()'),
                     self.update_search_combo)
        
        self.all_check = QCheckBox(_("Replace all"))
        
        self.replace_layout = QHBoxLayout()
        widgets = [replace_with, self.replace_text, self.replace_button,
                   self.all_check]
        for widget in widgets:
            self.replace_layout.addWidget(widget)
        glayout.addLayout(self.replace_layout, 1, 1)
        self.widgets.extend(widgets)
        self.replace_widgets = widgets
        self.hide_replace()
        
        self.search_text.setTabOrder(self.search_text, self.replace_text)
        
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        
        self.shortcuts = self.create_shortcuts(parent)
        
        self.highlight_timer = QTimer(self)
        self.highlight_timer.setSingleShot(True)
        self.highlight_timer.setInterval(1000)
        self.connect(self.highlight_timer, SIGNAL("timeout()"),
                     self.highlight_matches)
Example #26
0
    def __init__(self, parent, enable_replace=False):
        QWidget.__init__(self, parent)
        self.enable_replace = enable_replace
        self.editor = None
        self.is_code_editor = None

        glayout = QGridLayout()
        glayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(glayout)

        self.close_button = create_toolbutton(
            self, triggered=self.hide, icon=get_std_icon("DialogCloseButton"))
        glayout.addWidget(self.close_button, 0, 0)

        # Find layout
        self.search_text = PatternComboBox(self,
                                           tip=_("Search string"),
                                           adjust_to_minimum=False)
        self.search_text.valid.connect(lambda state: self.find(
            changed=False, forward=True, rehighlight=False))
        self.search_text.lineEdit().textEdited.connect(
            self.text_has_been_edited)

        self.previous_button = create_toolbutton(self,
                                                 triggered=self.find_previous,
                                                 icon=get_std_icon("ArrowUp"))
        self.next_button = create_toolbutton(self,
                                             triggered=self.find_next,
                                             icon=get_std_icon("ArrowDown"))
        self.next_button.clicked.connect(self.update_search_combo)
        self.previous_button.clicked.connect(self.update_search_combo)

        self.re_button = create_toolbutton(self,
                                           icon=get_icon("advanced.png"),
                                           tip=_("Regular expression"))
        self.re_button.setCheckable(True)
        self.re_button.toggled.connect(lambda state: self.find())

        self.case_button = create_toolbutton(self,
                                             icon=get_icon("upper_lower.png"),
                                             tip=_("Case Sensitive"))
        self.case_button.setCheckable(True)
        self.case_button.toggled.connect(lambda state: self.find())

        self.words_button = create_toolbutton(self,
                                              icon=get_icon("whole_words.png"),
                                              tip=_("Whole words"))
        self.words_button.setCheckable(True)
        self.words_button.toggled.connect(lambda state: self.find())

        self.highlight_button = create_toolbutton(
            self, icon=get_icon("highlight.png"), tip=_("Highlight matches"))
        self.highlight_button.setCheckable(True)
        self.highlight_button.toggled.connect(self.toggle_highlighting)

        hlayout = QHBoxLayout()
        self.widgets = [
            self.close_button, self.search_text, self.previous_button,
            self.next_button, self.re_button, self.case_button,
            self.words_button, self.highlight_button
        ]
        for widget in self.widgets[1:]:
            hlayout.addWidget(widget)
        glayout.addLayout(hlayout, 0, 1)

        # Replace layout
        replace_with = QLabel(_("Replace with:"))
        self.replace_text = PatternComboBox(self,
                                            adjust_to_minimum=False,
                                            tip=_("Replace string"))

        self.replace_button = create_toolbutton(
            self,
            text=_("Replace/find"),
            icon=get_std_icon("DialogApplyButton"),
            triggered=self.replace_find,
            text_beside_icon=True)
        self.replace_button.clicked.connect(self.update_replace_combo)
        self.replace_button.clicked.connect(self.update_search_combo)

        self.all_check = QCheckBox(_("Replace all"))

        self.replace_layout = QHBoxLayout()
        widgets = [
            replace_with, self.replace_text, self.replace_button,
            self.all_check
        ]
        for widget in widgets:
            self.replace_layout.addWidget(widget)
        glayout.addLayout(self.replace_layout, 1, 1)
        self.widgets.extend(widgets)
        self.replace_widgets = widgets
        self.hide_replace()

        self.search_text.setTabOrder(self.search_text, self.replace_text)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)

        self.shortcuts = self.create_shortcuts(parent)

        self.highlight_timer = QTimer(self)
        self.highlight_timer.setSingleShot(True)
        self.highlight_timer.setInterval(1000)
        self.highlight_timer.timeout.connect(self.highlight_matches)
 def get_plugin_icon(self):
     """Return widget icon"""
     return get_std_icon('DirOpenIcon')
Example #28
0
    def __init__(self, parent, enable_replace=False):
        QWidget.__init__(self, parent)
        self.enable_replace = enable_replace
        self.editor = None
        
        glayout = QGridLayout()
        glayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(glayout)
        
        self.close_button = create_toolbutton(self, triggered=self.hide,
                                      icon=get_std_icon("DialogCloseButton"))
        glayout.addWidget(self.close_button, 0, 0)
        
        # Find layout
        self.search_text = PatternComboBox(self, tip=self.tr("Search string"),
                                           adjust_to_minimum=False)
        self.connect(self.search_text, SIGNAL("editTextChanged(QString)"),
                     self.text_has_changed)
        
        self.previous_button = create_toolbutton(self,
                                             text=self.tr("Previous"),
                                             triggered=self.find_previous,
                                             icon=get_std_icon("ArrowBack"))
        self.next_button = create_toolbutton(self,
                                             text=self.tr("Next"),
                                             triggered=self.find_next,
                                             icon=get_std_icon("ArrowForward"))
        self.connect(self.next_button, SIGNAL('clicked()'),
                     self.update_search_combo)
        self.connect(self.previous_button, SIGNAL('clicked()'),
                     self.update_search_combo)

        self.case_check = QCheckBox(self.tr("Case Sensitive"))
        self.connect(self.case_check, SIGNAL("stateChanged(int)"), self.find)
        self.words_check = QCheckBox(self.tr("Whole words"))
        self.connect(self.words_check, SIGNAL("stateChanged(int)"), self.find)

        hlayout = QHBoxLayout()
        self.widgets = [self.close_button, self.search_text, self.previous_button,
                        self.next_button, self.case_check, self.words_check]
        for widget in self.widgets[1:]:
            hlayout.addWidget(widget)
        glayout.addLayout(hlayout, 0, 1)

        # Replace layout
        replace_with1 = QLabel(self.tr("Replace"))
        replace_with2 = QLabel()
        font = replace_with2.font()
        font.setBold(True)
        replace_with2.setFont(font)
        replace_with3 = QLabel(self.tr("with:"))
        self.replace_text = PatternComboBox(self, adjust_to_minimum=False,
                                            tip=self.tr("Replace string"))
        
        self.replace_button = create_toolbutton(self,
                                     text=self.tr("Replace/find"),
                                     triggered=self.replace_find,
                                     icon=get_std_icon("DialogApplyButton"))
        self.connect(self.replace_button, SIGNAL('clicked()'),
                     self.update_replace_combo)
        self.connect(self.replace_button, SIGNAL('clicked()'),
                     self.update_search_combo)
        
        self.all_check = QCheckBox(self.tr("Replace all"))
        
        self.replace_layout = QHBoxLayout()
        widgets = [replace_with1, replace_with2, replace_with3,
                   self.replace_text, self.replace_button, self.all_check]
        for widget in widgets:
            self.replace_layout.addWidget(widget)
        self.connect(self.search_text, SIGNAL("editTextChanged(QString)"),
                     replace_with2, SLOT("setText(QString)"))
        glayout.addLayout(self.replace_layout, 1, 1)
        self.widgets.extend(widgets)
        self.replace_widgets = widgets
        self.hide_replace()
        
        self.search_text.setTabOrder(self.search_text, self.replace_text)
        
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
Example #29
0
 def get_plugin_icon(self):
     """Return widget icon"""
     return get_std_icon('DirOpenIcon')
    def __init__(self, parent, workdir=None):
        QToolBar.__init__(self, parent)
        SpyderPluginMixin.__init__(self, parent)

        # Initialize plugin
        self.initialize_plugin()
        
        self.setWindowTitle(self.get_plugin_title()) # Toolbar title
        self.setObjectName(self.get_plugin_title()) # Used to save Window state
        
        # Previous dir action
        self.history = []
        self.histindex = None
        self.previous_action = create_action(self, "previous", None,
                                     get_icon('previous.png'), _('Back'),
                                     triggered=self.previous_directory)
        self.addAction(self.previous_action)
        
        # Next dir action
        self.history = []
        self.histindex = None
        self.next_action = create_action(self, "next", None,
                                     get_icon('next.png'), _('Next'),
                                     triggered=self.next_directory)
        self.addAction(self.next_action)
        
        # Enable/disable previous/next actions
        self.connect(self, SIGNAL("set_previous_enabled(bool)"),
                     self.previous_action.setEnabled)
        self.connect(self, SIGNAL("set_next_enabled(bool)"),
                     self.next_action.setEnabled)
        
        # Path combo box
        adjust = self.get_option('working_dir_adjusttocontents')
        self.pathedit = PathComboBox(self, adjust_to_contents=adjust)
        self.pathedit.setToolTip(_("This is the working directory for newly\n"
                               "opened consoles (Python/IPython consoles and\n"
                               "terminals), for the file explorer, for the\n"
                               "find in files plugin and for new files\n"
                               "created in the editor"))
        self.connect(self.pathedit, SIGNAL("open_dir(QString)"), self.chdir)
        self.pathedit.setMaxCount(self.get_option('working_dir_history'))
        wdhistory = self.load_wdhistory( workdir )
        if workdir is None:
            if self.get_option('startup/use_last_directory'):
                if wdhistory:
                    workdir = wdhistory[0]
                else:
                    workdir = "."
            else:
                workdir = self.get_option('startup/fixed_directory', ".")
                if not osp.isdir(workdir):
                    workdir = "."
        self.chdir(workdir)
        self.pathedit.addItems( wdhistory )
        self.refresh_plugin()
        self.addWidget(self.pathedit)
        
        # Browse action
        browse_action = create_action(self, "browse", None,
                                      get_std_icon('DirOpenIcon'),
                                      _('Browse a working directory'),
                                      triggered=self.select_directory)
        self.addAction(browse_action)
        
        # Set current console working directory action
        setwd_action = create_action(self, icon=get_icon('set_workdir.png'),
                                     text=_("Set as current console's "
                                                  "working directory"),
                                     triggered=self.set_as_current_console_wd)
        self.addAction(setwd_action)
        
        # Parent dir action
        parent_action = create_action(self, "parent", None,
                                      get_icon('up.png'),
                                      _('Change to parent directory'),
                                      triggered=self.parent_directory)
        self.addAction(parent_action)
Example #31
0
    def __init__(self, parent, search_text, search_text_regexp, search_path,
                 include, include_idx, include_regexp,
                 exclude, exclude_idx, exclude_regexp,
                 supported_encodings, in_python_path, more_options):
        QWidget.__init__(self, parent)
        
        if search_path is None:
            search_path = getcwd()
        
        if not isinstance(search_text, (list, tuple)):
            search_text = [search_text]
        if not isinstance(search_path, (list, tuple)):
            search_path = [search_path]
        if not isinstance(include, (list, tuple)):
            include = [include]
        if not isinstance(exclude, (list, tuple)):
            exclude = [exclude]

        self.supported_encodings = supported_encodings

        # Layout 1
        hlayout1 = QHBoxLayout()
        self.search_text = PatternComboBox(self, search_text,
                                           _("Search pattern"))
        self.edit_regexp = create_toolbutton(self,
                                             icon=get_icon("advanced.png"),
                                             tip=_("Regular expression"))
        self.edit_regexp.setCheckable(True)
        self.edit_regexp.setChecked(search_text_regexp)
        self.more_widgets = ()
        self.more_options = create_toolbutton(self,
                                              toggled=self.toggle_more_options)
        self.more_options.setCheckable(True)
        self.more_options.setChecked(more_options)
        
        self.ok_button = create_toolbutton(self, text=_("Search"),
                                icon=get_std_icon("DialogApplyButton"),
                                triggered=lambda: self.find.emit(),
                                tip=_("Start search"),
                                text_beside_icon=True)
        self.ok_button.clicked.connect(self.update_combos)
        self.stop_button = create_toolbutton(self, text=_("Stop"),
                                icon=get_icon("stop.png"),
                                triggered=lambda: self.stop.emit(),
                                tip=_("Stop search"),
                                text_beside_icon=True)
        self.stop_button.setEnabled(False)
        for widget in [self.search_text, self.edit_regexp,
                       self.ok_button, self.stop_button, self.more_options]:
            hlayout1.addWidget(widget)

        # Layout 2
        hlayout2 = QHBoxLayout()
        self.include_pattern = PatternComboBox(self, include,
                                               _("Included filenames pattern"))
        if include_idx is not None and include_idx >= 0 \
           and include_idx < self.include_pattern.count():
            self.include_pattern.setCurrentIndex(include_idx)
        self.include_regexp = create_toolbutton(self,
                                            icon=get_icon("advanced.png"),
                                            tip=_("Regular expression"))
        self.include_regexp.setCheckable(True)
        self.include_regexp.setChecked(include_regexp)
        include_label = QLabel(_("Include:"))
        include_label.setBuddy(self.include_pattern)
        self.exclude_pattern = PatternComboBox(self, exclude,
                                               _("Excluded filenames pattern"))
        if exclude_idx is not None and exclude_idx >= 0 \
           and exclude_idx < self.exclude_pattern.count():
            self.exclude_pattern.setCurrentIndex(exclude_idx)
        self.exclude_regexp = create_toolbutton(self,
                                            icon=get_icon("advanced.png"),
                                            tip=_("Regular expression"))
        self.exclude_regexp.setCheckable(True)
        self.exclude_regexp.setChecked(exclude_regexp)
        exclude_label = QLabel(_("Exclude:"))
        exclude_label.setBuddy(self.exclude_pattern)
        for widget in [include_label, self.include_pattern,
                       self.include_regexp,
                       exclude_label, self.exclude_pattern,
                       self.exclude_regexp]:
            hlayout2.addWidget(widget)

        # Layout 3
        hlayout3 = QHBoxLayout()
        self.python_path = QRadioButton(_("PYTHONPATH"), self)
        self.python_path.setChecked(in_python_path)
        self.python_path.setToolTip(_(
                          "Search in all directories listed in sys.path which"
                          " are outside the Python installation directory"))        
        self.hg_manifest = QRadioButton(_("Hg repository"), self)
        self.detect_hg_repository()
        self.hg_manifest.setToolTip(
                                _("Search in current directory hg repository"))
        self.custom_dir = QRadioButton(_("Here:"), self)
        self.custom_dir.setChecked(not in_python_path)
        self.dir_combo = PathComboBox(self)
        self.dir_combo.addItems(search_path)
        self.dir_combo.setToolTip(_("Search recursively in this directory"))
        self.dir_combo.open_dir.connect(self.set_directory)
        self.python_path.toggled.connect(self.dir_combo.setDisabled)
        self.hg_manifest.toggled.connect(self.dir_combo.setDisabled)
        browse = create_toolbutton(self, icon=get_std_icon('DirOpenIcon'),
                                   tip=_('Browse a search directory'),
                                   triggered=self.select_directory)
        for widget in [self.python_path, self.hg_manifest, self.custom_dir,
                       self.dir_combo, browse]:
            hlayout3.addWidget(widget)
            
        self.search_text.valid.connect(lambda valid: self.find.emit())
        self.include_pattern.valid.connect(lambda valid: self.find.emit())
        self.exclude_pattern.valid.connect(lambda valid: self.find.emit())
        self.dir_combo.valid.connect(lambda valid: self.find.emit())
            
        vlayout = QVBoxLayout()
        vlayout.setContentsMargins(0, 0, 0, 0)
        vlayout.addLayout(hlayout1)
        vlayout.addLayout(hlayout2)
        vlayout.addLayout(hlayout3)
        self.more_widgets = (hlayout2, hlayout3)
        self.toggle_more_options(more_options)
        self.setLayout(vlayout)
                
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
Example #32
0
 def update_menu(self):
     """Update option menu"""
     self.menu.clear()
     actions = []
     newdir_action = create_action(self,
                                   translate('Explorer',
                                             "New folder..."),
                                   icon="folder_new.png",
                                   triggered=self.new_folder)
     actions.append(newdir_action)
     newfile_action = create_action(self,
                                    translate('Explorer',
                                              "New file..."),
                                    icon="filenew.png",
                                    triggered=self.new_file)
     actions.append(newfile_action)
     fname = self.get_filename()
     if fname is not None:
         is_dir = osp.isdir(fname)
         ext = osp.splitext(fname)[1]
         run_action = create_action(self,
                                    translate('Explorer', "Run"),
                                    icon="run_small.png",
                                    triggered=self.run)
         edit_action = create_action(self,
                                     translate('Explorer', "Edit"),
                                     icon="edit.png",
                                     triggered=self.clicked)
         delete_action = create_action(self,
                                       translate('Explorer', "Delete..."),
                                       icon="delete.png",
                                       triggered=self.delete)
         rename_action = create_action(self,
                                       translate('Explorer', "Rename..."),
                                       icon="rename.png",
                                       triggered=self.rename)
         browse_action = create_action(self,
                                       translate('Explorer', "Browse"),
                                       icon=get_std_icon("CommandLink"),
                                       triggered=self.clicked)
         open_action = create_action(self,
                                     translate('Explorer', "Open"),
                                     triggered=self.startfile)
         if ext in ('.py', '.pyw'):
             actions.append(run_action)
         if ext in self.valid_types or os.name != 'nt':
             actions.append(browse_action if is_dir else edit_action)
         else:
             actions.append(open_action)
         actions += [delete_action, rename_action]
         if is_dir and os.name == 'nt':
             # Actions specific to Windows directories
             actions.append( create_action(self,
                        translate('Explorer', "Open in Windows Explorer"),
                        icon="magnifier.png",
                        triggered=self.startfile) )
     if os.name == 'nt':
         actions.append( create_action(self,
                    translate('Explorer', "Open command prompt here"),
                    icon="cmdprompt.png",
                    triggered=lambda cmd='cmd.exe': os.startfile(cmd)) )
     if actions:
         actions.append(None)
     actions += self.common_actions
     add_actions(self.menu, actions)
Example #33
0
    def __init__(self, parent, inline=True, offset=0):
        QDialog.__init__(self, parent)
        self._parent = parent
        self._text = None
        self._valid = None
        self._offset = offset

        # TODO: add this as an option in the General Preferences?
        self._force_float = False

        self._help_inline = _("""
           <b>Numpy Array/Matrix Helper</b><br>
           Type an array in Matlab    : <code>[1 2;3 4]</code><br>
           or Spyder simplified syntax : <code>1 2;3 4</code>
           <br><br>
           Hit 'Enter' for array or 'Ctrl+Enter' for matrix.
           <br><br>
           <b>Hint:</b><br>
           Use two spaces or two tabs to generate a ';'.
           """)

        self._help_table = _("""
           <b>Numpy Array/Matrix Helper</b><br>
           Enter an array in the table. <br>
           Use Tab to move between cells.
           <br><br>
           Hit 'Enter' for array or 'Ctrl+Enter' for matrix.
           <br><br>
           <b>Hint:</b><br>
           Use two tabs at the end of a row to move to the next row.
           """)

        # widgets
        self._button_warning = QToolButton()
        self._button_help = HelperToolButton()
        self._button_help.setIcon(get_std_icon('MessageBoxInformation'))

        style = """
            QToolButton {
              border: 1px solid grey;
              padding:0px;
              border-radius: 2px;
              background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                  stop: 0 #f6f7fa, stop: 1 #dadbde);
            }
            """
        self._button_help.setStyleSheet(style)

        if inline:
            self._button_help.setToolTip(self._help_inline)
            self._text = NumpyArrayInline(self)
            self._widget = self._text
        else:
            self._button_help.setToolTip(self._help_table)
            self._table = NumpyArrayTable(self)
            self._widget = self._table

        style = """
            QDialog {
              margin:0px;
              border: 1px solid grey;
              padding:0px;
              border-radius: 2px;
            }"""
        self.setStyleSheet(style)

        style = """
            QToolButton {
              margin:1px;
              border: 0px solid grey;
              padding:0px;
              border-radius: 0px;
            }"""
        self._button_warning.setStyleSheet(style)

        # widget setup
        self.setWindowFlags(Qt.Window | Qt.Dialog | Qt.FramelessWindowHint)
        self.setModal(True)
        self.setWindowOpacity(0.90)
        self._widget.setMinimumWidth(200)

        # layout
        self._layout = QHBoxLayout()
        self._layout.addWidget(self._widget)
        self._layout.addWidget(self._button_warning, 1, Qt.AlignTop)
        self._layout.addWidget(self._button_help, 1, Qt.AlignTop)
        self.setLayout(self._layout)

        self._widget.setFocus()
Example #34
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.current_radio = None
        self.dedicated_radio = None
        self.systerm_radio = None

        self.runconf = RunConfiguration()
        
        firstrun_o = CONF.get('run', ALWAYS_OPEN_FIRST_RUN_OPTION, False)

        # --- General settings ----
        common_group = QGroupBox(_("General settings"))
        common_layout = QGridLayout()
        common_group.setLayout(common_layout)
        self.clo_cb = QCheckBox(_("Command line options:"))
        common_layout.addWidget(self.clo_cb, 0, 0)
        self.clo_edit = QLineEdit()
        self.clo_cb.toggled.connect(self.clo_edit.setEnabled)
        self.clo_edit.setEnabled(False)
        common_layout.addWidget(self.clo_edit, 0, 1)
        self.wd_cb = QCheckBox(_("Working directory:"))
        common_layout.addWidget(self.wd_cb, 1, 0)
        wd_layout = QHBoxLayout()
        self.wd_edit = QLineEdit()
        self.wd_cb.toggled.connect(self.wd_edit.setEnabled)
        self.wd_edit.setEnabled(False)
        wd_layout.addWidget(self.wd_edit)
        browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self)
        browse_btn.setToolTip(_("Select directory"))
        browse_btn.clicked.connect(self.select_directory)
        wd_layout.addWidget(browse_btn)
        common_layout.addLayout(wd_layout, 1, 1)
        self.post_mortem_cb = QCheckBox(_("Enter post mortem debugging"
                                          " for uncaught exceptions"))
        common_layout.addWidget(self.post_mortem_cb)
        
        # --- Interpreter ---
        interpreter_group = QGroupBox(_("Console"))
        interpreter_layout = QVBoxLayout()
        interpreter_group.setLayout(interpreter_layout)
        self.current_radio = QRadioButton(CURRENT_INTERPRETER)
        interpreter_layout.addWidget(self.current_radio)
        self.dedicated_radio = QRadioButton(DEDICATED_INTERPRETER)
        interpreter_layout.addWidget(self.dedicated_radio)
        self.systerm_radio = QRadioButton(SYSTERM_INTERPRETER)
        interpreter_layout.addWidget(self.systerm_radio)
        
        # --- Dedicated interpreter ---
        new_group = QGroupBox(_("Dedicated Python console"))
        self.current_radio.toggled.connect(new_group.setDisabled)
        new_layout = QGridLayout()
        new_group.setLayout(new_layout)
        self.interact_cb = QCheckBox(_("Interact with the Python "
                                       "console after execution"))
        new_layout.addWidget(self.interact_cb, 1, 0, 1, -1)
        
        self.show_kill_warning_cb = QCheckBox(_("Show warning when killing"
                                                " running process"))

        new_layout.addWidget(self.show_kill_warning_cb, 2, 0, 1, -1)
        self.pclo_cb = QCheckBox(_("Command line options:"))
        new_layout.addWidget(self.pclo_cb, 3, 0)
        self.pclo_edit = QLineEdit()
        self.pclo_cb.toggled.connect(self.pclo_edit.setEnabled)
        self.pclo_edit.setEnabled(False)
        self.pclo_edit.setToolTip(_("<b>-u</b> is added to the "
                                    "other options you set here"))
        new_layout.addWidget(self.pclo_edit, 3, 1)
        

        # Checkbox to preserve the old behavior, i.e. always open the dialog
        # on first run
        hline = QFrame()
        hline.setFrameShape(QFrame.HLine)
        hline.setFrameShadow(QFrame.Sunken)
        self.firstrun_cb = QCheckBox(ALWAYS_OPEN_FIRST_RUN % _("this dialog"))
        self.firstrun_cb.clicked.connect(self.set_firstrun_o)
        self.firstrun_cb.setChecked(firstrun_o)
        
        layout = QVBoxLayout()
        layout.addWidget(interpreter_group)
        layout.addWidget(common_group)
        layout.addWidget(new_group)
        layout.addWidget(hline)
        layout.addWidget(self.firstrun_cb)
        self.setLayout(layout)
Example #35
0
    def __init__(self, parent, inline=True, offset=0):
        QDialog.__init__(self, parent)
        self._parent = parent
        self._text = None
        self._valid = None
        self._offset = offset

        # TODO: add this as an option in the General Preferences?
        self._force_float = False

        self._help_inline = _("""
           <b>Numpy Array/Matrix Helper</b><br>
           Type an array in Matlab    : <code>[1 2;3 4]</code><br>
           or Spyder simplified syntax : <code>1 2;3 4</code>
           <br><br>
           Hit 'Enter' for array or 'Ctrl+Enter' for matrix.
           <br><br>
           <b>Hint:</b><br>
           Use two spaces or two tabs to generate a ';'.
           """)

        self._help_table = _("""
           <b>Numpy Array/Matrix Helper</b><br>
           Enter an array in the table. <br>
           Use Tab to move between cells.
           <br><br>
           Hit 'Enter' for array or 'Ctrl+Enter' for matrix.
           <br><br>
           <b>Hint:</b><br>
           Use two tabs at the end of a row to move to the next row.
           """)

        # widgets
        self._button_warning = QToolButton()
        self._button_help = HelperToolButton()
        self._button_help.setIcon(get_std_icon('MessageBoxInformation'))

        style = """
            QToolButton {
              border: 1px solid grey;
              padding:0px;
              border-radius: 2px;
              background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                  stop: 0 #f6f7fa, stop: 1 #dadbde);
            }
            """
        self._button_help.setStyleSheet(style)

        if inline:
            self._button_help.setToolTip(self._help_inline)
            self._text = NumpyArrayInline(self)
            self._widget = self._text
        else:
            self._button_help.setToolTip(self._help_table)
            self._table = NumpyArrayTable(self)
            self._widget = self._table

        style = """
            QDialog {
              margin:0px;
              border: 1px solid grey;
              padding:0px;
              border-radius: 2px;
            }"""
        self.setStyleSheet(style)

        style = """
            QToolButton {
              margin:1px;
              border: 0px solid grey;
              padding:0px;
              border-radius: 0px;
            }"""
        self._button_warning.setStyleSheet(style)

        # widget setup
        self.setWindowFlags(Qt.Window | Qt.Dialog | Qt.FramelessWindowHint)
        self.setModal(True)
        self.setWindowOpacity(0.90)
        self._widget.setMinimumWidth(200)

        # layout
        self._layout = QHBoxLayout()
        self._layout.addWidget(self._widget)
        self._layout.addWidget(self._button_warning, 1, Qt.AlignTop)
        self._layout.addWidget(self._button_help, 1, Qt.AlignTop)
        self.setLayout(self._layout)

        self._widget.setFocus()
Example #36
0
    def __init__(self, parent, workdir=None):
        QToolBar.__init__(self, parent)
        PluginMixin.__init__(self, parent)

        self.setWindowTitle(self.get_widget_title())  # Toolbar title
        self.setObjectName(
            self.get_widget_title())  # Used to save Window state

        self.addWidget(QLabel(self.tr("Working directory:") + " "))

        # Previous dir action
        self.history = []
        self.histindex = None
        self.previous_action = create_action(self,
                                             "previous",
                                             None,
                                             get_icon('previous.png'),
                                             self.tr('Back'),
                                             triggered=self.previous_directory)
        self.addAction(self.previous_action)

        # Next dir action
        self.history = []
        self.histindex = None
        self.next_action = create_action(self,
                                         "next",
                                         None,
                                         get_icon('next.png'),
                                         self.tr('Next'),
                                         triggered=self.next_directory)
        self.addAction(self.next_action)

        # Enable/disable previous/next actions
        self.connect(self, SIGNAL("set_previous_enabled(bool)"),
                     self.previous_action.setEnabled)
        self.connect(self, SIGNAL("set_next_enabled(bool)"),
                     self.next_action.setEnabled)

        # Path combo box
        adjust = CONF.get('shell', 'working_dir_adjusttocontents', False)
        self.pathedit = PathComboBox(self, adjust_to_contents=adjust)
        self.pathedit.setToolTip(self.tr("Working directory"))
        self.connect(self.pathedit, SIGNAL("open_dir(QString)"),
                     self.pathedit_activated)
        self.pathedit.setMaxCount(CONF.get('shell', 'working_dir_history'))
        wdhistory = self.load_wdhistory(workdir)
        if workdir is None:
            if wdhistory:
                workdir = wdhistory[0]
            else:
                workdir = "."
        self.chdir(workdir)
        self.pathedit.addItems(wdhistory)
        self.refresh()
        self.addWidget(self.pathedit)

        # Browse action
        browse_action = create_action(self,
                                      "browse",
                                      None,
                                      get_std_icon('DirOpenIcon'),
                                      self.tr('Browse a working directory'),
                                      triggered=self.select_directory)
        self.addAction(browse_action)

        # Parent dir action
        parent_action = create_action(self,
                                      "parent",
                                      None,
                                      get_icon('up.png'),
                                      self.tr('Change to parent directory'),
                                      triggered=self.parent_directory)
        self.addAction(parent_action)
Example #37
0
    def __init__(self, parent, search_text, search_text_regexp, search_path,
                 include, include_regexp, exclude, exclude_regexp,
                 supported_encodings):
        QWidget.__init__(self, parent)
        
        if search_path is None:
            search_path = os.getcwdu()
        
        if not isinstance(search_text, (list, tuple)):
            search_text = [search_text]
        if not isinstance(search_path, (list, tuple)):
            search_path = [search_path]
        if not isinstance(include, (list, tuple)):
            include = [include]
        if not isinstance(exclude, (list, tuple)):
            exclude = [exclude]

        self.supported_encodings = supported_encodings

        # Layout 1
        hlayout1 = QHBoxLayout()
        self.search_text = PatternComboBox(self, search_text,
                                    translate('FindInFiles', "Search pattern"))
        search_label = QLabel(translate('FindInFiles', "Search text:"))
        search_label.setBuddy(self.search_text)
        self.edit_regexp = create_toolbutton(self, get_icon("advanced.png"),
                         tip=translate('FindInFiles', "Regular expression"))
        self.edit_regexp.setCheckable(True)
        self.edit_regexp.setChecked(search_text_regexp)
        self.ok_button = create_toolbutton(self,
                                text=translate('FindInFiles', "Search"),
                                triggered=lambda: self.emit(SIGNAL('find()')),
                                icon=get_std_icon("DialogApplyButton"),
                                tip=translate('FindInFiles', "Start search"))
        self.connect(self.ok_button, SIGNAL('clicked()'), self.update_combos)
        self.stop_button = create_toolbutton(self,
                                text=translate('FindInFiles', "Stop"),
                                triggered=lambda: self.emit(SIGNAL('stop()')),
                                icon=get_icon("terminate.png"),
                                tip=translate('FindInFiles', "Stop search"))
        self.stop_button.setEnabled(False)
        for widget in [search_label, self.search_text, self.edit_regexp,
                       self.ok_button, self.stop_button]:
            hlayout1.addWidget(widget)

        # Layout 2
        hlayout2 = QHBoxLayout()
        self.include_pattern = PatternComboBox(self, include,
                        translate('FindInFiles', "Included filenames pattern"))
        self.include_regexp = create_toolbutton(self, get_icon("advanced.png"),
                                            tip=translate('FindInFiles',
                                                          "Regular expression"))
        self.include_regexp.setCheckable(True)
        self.include_regexp.setChecked(include_regexp)
        include_label = QLabel(translate('FindInFiles', "Include:"))
        include_label.setBuddy(self.include_pattern)
        self.exclude_pattern = PatternComboBox(self, exclude,
                        translate('FindInFiles', "Excluded filenames pattern"))
        self.exclude_regexp = create_toolbutton(self, get_icon("advanced.png"),
                                            tip=translate('FindInFiles',
                                                          "Regular expression"))
        self.exclude_regexp.setCheckable(True)
        self.exclude_regexp.setChecked(exclude_regexp)
        exclude_label = QLabel(translate('FindInFiles', "Exclude:"))
        exclude_label.setBuddy(self.exclude_pattern)
        for widget in [include_label, self.include_pattern,
                       self.include_regexp,
                       exclude_label, self.exclude_pattern,
                       self.exclude_regexp]:
            hlayout2.addWidget(widget)

        # Layout 3
        hlayout3 = QHBoxLayout()
        searchin_label = QLabel(translate('FindInFiles', "Search in:"))
        self.python_path = QRadioButton(translate('FindInFiles',
                                        "PYTHONPATH"), self)
        self.python_path.setToolTip(translate('FindInFiles',
                          "Search in all directories listed in sys.path which"
                          " are outside the Python installation directory"))        
        self.hg_manifest = QRadioButton(translate('FindInFiles',
                                                  "Hg repository"), self)
        self.detect_hg_repository()
        self.hg_manifest.setToolTip(translate('FindInFiles',
                              "Search in current directory hg repository"))
        searchin_label.setBuddy(self.hg_manifest)
        self.custom_dir = QRadioButton(translate('FindInFiles',
                                                 "Directory:"), self)
        self.custom_dir.setChecked(True)
        self.dir_combo = PathComboBox(self)
        self.dir_combo.addItems(search_path)
        self.dir_combo.setToolTip(translate('FindInFiles',
                                    "Search recursively in this directory"))
        self.connect(self.dir_combo, SIGNAL("open_dir(QString)"),
                     self.set_directory)
        self.connect(self.python_path, SIGNAL('toggled(bool)'),
                     self.dir_combo.setDisabled)
        self.connect(self.hg_manifest, SIGNAL('toggled(bool)'),
                     self.dir_combo.setDisabled)
        browse = create_toolbutton(self, get_std_icon('DirOpenIcon'),
                                   tip=translate('FindInFiles',
                                                 'Browse a search directory'),
                                   triggered=self.select_directory)
        for widget in [searchin_label, self.python_path, self.hg_manifest,
                       self.custom_dir, self.dir_combo, browse]:
            hlayout3.addWidget(widget)
            
        vlayout = QVBoxLayout()
        vlayout.addLayout(hlayout1)
        vlayout.addLayout(hlayout2)
        vlayout.addLayout(hlayout3)
        self.setLayout(vlayout)
                
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
Example #38
0
 def update_menu(self):
     """Update option menu"""
     self.menu.clear()
     actions = []
     newdir_action = create_action(self,
                                   translate('Explorer',
                                             "New folder..."),
                                   icon="folder_new.png",
                                   triggered=self.new_folder)
     actions.append(newdir_action)
     newfile_action = create_action(self,
                                    translate('Explorer',
                                              "New file..."),
                                    icon="filenew.png",
                                    triggered=self.new_file)
     actions.append(newfile_action)
     fname = self.get_filename()
     if fname is not None:
         is_dir = osp.isdir(fname)
         ext = osp.splitext(fname)[1]
         run_action = create_action(self,
                                    translate('Explorer', "Run"),
                                    icon="run_small.png",
                                    triggered=self.run)
         edit_action = create_action(self,
                                     translate('Explorer', "Edit"),
                                     icon="edit.png",
                                     triggered=self.clicked)
         delete_action = create_action(self,
                                       translate('Explorer', "Delete..."),
                                       icon="delete.png",
                                       triggered=self.delete)
         rename_action = create_action(self,
                                       translate('Explorer', "Rename..."),
                                       icon="rename.png",
                                       triggered=self.rename)
         browse_action = create_action(self,
                                       translate('Explorer', "Browse"),
                                       icon=get_std_icon("CommandLink"),
                                       triggered=self.clicked)
         open_action = create_action(self,
                                     translate('Explorer', "Open"),
                                     triggered=self.startfile)
         if ext in ('.py', '.pyw'):
             actions.append(run_action)
         if ext in self.valid_types or os.name != 'nt':
             actions.append(browse_action if is_dir else edit_action)
         else:
             actions.append(open_action)
         actions += [delete_action, rename_action, None]
         if is_dir and os.name == 'nt':
             # Actions specific to Windows directories
             actions.append( create_action(self,
                        translate('Explorer', "Open in Windows Explorer"),
                        icon="magnifier.png",
                        triggered=self.startfile) )
         if is_dir:
             if os.name == 'nt':
                 _title = translate('Explorer', "Open command prompt here")
             else:
                 _title = translate('Explorer', "Open terminal here")
             action = create_action(self, _title, icon="cmdprompt.png",
                                    triggered=lambda _fn=fname:
                                    self.parent_widget.emit(
                                    SIGNAL("open_terminal(QString)"), _fn))
             actions.append(action)
             _title = translate('Explorer', "Open Python interpreter here")
             action = create_action(self, _title, icon="python.png",
                                triggered=lambda _fn=fname:
                                self.parent_widget.emit(
                                SIGNAL("open_interpreter(QString)"), _fn))
             actions.append(action)
             if programs.is_module_installed("IPython"):
                 _title = translate('Explorer', "Open IPython here")
                 action = create_action(self, _title, icon="ipython.png",
                                    triggered=lambda _fn=fname:
                                    self.parent_widget.emit(
                                    SIGNAL("open_ipython(QString)"), _fn))
                 actions.append(action)
     if actions:
         actions.append(None)
     actions += self.common_actions
     add_actions(self.menu, actions)
Example #39
0
    def __init__(self, parent, search_text, search_text_regexp, search_path,
                 include, include_idx, include_regexp, exclude, exclude_idx,
                 exclude_regexp, supported_encodings, in_python_path,
                 more_options):
        QWidget.__init__(self, parent)

        if search_path is None:
            search_path = getcwd()

        if not isinstance(search_text, (list, tuple)):
            search_text = [search_text]
        if not isinstance(search_path, (list, tuple)):
            search_path = [search_path]
        if not isinstance(include, (list, tuple)):
            include = [include]
        if not isinstance(exclude, (list, tuple)):
            exclude = [exclude]

        self.supported_encodings = supported_encodings

        # Layout 1
        hlayout1 = QHBoxLayout()
        self.search_text = PatternComboBox(self, search_text,
                                           _("Search pattern"))
        self.edit_regexp = create_toolbutton(self,
                                             icon=get_icon("advanced.png"),
                                             tip=_("Regular expression"))
        self.edit_regexp.setCheckable(True)
        self.edit_regexp.setChecked(search_text_regexp)
        self.more_widgets = ()
        self.more_options = create_toolbutton(self,
                                              toggled=self.toggle_more_options)
        self.more_options.setCheckable(True)
        self.more_options.setChecked(more_options)

        self.ok_button = create_toolbutton(
            self,
            text=_("Search"),
            icon=get_std_icon("DialogApplyButton"),
            triggered=lambda: self.find.emit(),
            tip=_("Start search"),
            text_beside_icon=True)
        self.ok_button.clicked.connect(self.update_combos)
        self.stop_button = create_toolbutton(
            self,
            text=_("Stop"),
            icon=get_icon("stop.png"),
            triggered=lambda: self.stop.emit(),
            tip=_("Stop search"),
            text_beside_icon=True)
        self.stop_button.setEnabled(False)
        for widget in [
                self.search_text, self.edit_regexp, self.ok_button,
                self.stop_button, self.more_options
        ]:
            hlayout1.addWidget(widget)

        # Layout 2
        hlayout2 = QHBoxLayout()
        self.include_pattern = PatternComboBox(self, include,
                                               _("Included filenames pattern"))
        if include_idx is not None and include_idx >= 0 \
           and include_idx < self.include_pattern.count():
            self.include_pattern.setCurrentIndex(include_idx)
        self.include_regexp = create_toolbutton(self,
                                                icon=get_icon("advanced.png"),
                                                tip=_("Regular expression"))
        self.include_regexp.setCheckable(True)
        self.include_regexp.setChecked(include_regexp)
        include_label = QLabel(_("Include:"))
        include_label.setBuddy(self.include_pattern)
        self.exclude_pattern = PatternComboBox(self, exclude,
                                               _("Excluded filenames pattern"))
        if exclude_idx is not None and exclude_idx >= 0 \
           and exclude_idx < self.exclude_pattern.count():
            self.exclude_pattern.setCurrentIndex(exclude_idx)
        self.exclude_regexp = create_toolbutton(self,
                                                icon=get_icon("advanced.png"),
                                                tip=_("Regular expression"))
        self.exclude_regexp.setCheckable(True)
        self.exclude_regexp.setChecked(exclude_regexp)
        exclude_label = QLabel(_("Exclude:"))
        exclude_label.setBuddy(self.exclude_pattern)
        for widget in [
                include_label, self.include_pattern, self.include_regexp,
                exclude_label, self.exclude_pattern, self.exclude_regexp
        ]:
            hlayout2.addWidget(widget)

        # Layout 3
        hlayout3 = QHBoxLayout()
        self.python_path = QRadioButton(_("PYTHONPATH"), self)
        self.python_path.setChecked(in_python_path)
        self.python_path.setToolTip(
            _("Search in all directories listed in sys.path which"
              " are outside the Python installation directory"))
        self.hg_manifest = QRadioButton(_("Hg repository"), self)
        self.detect_hg_repository()
        self.hg_manifest.setToolTip(
            _("Search in current directory hg repository"))
        self.custom_dir = QRadioButton(_("Here:"), self)
        self.custom_dir.setChecked(not in_python_path)
        self.dir_combo = PathComboBox(self)
        self.dir_combo.addItems(search_path)
        self.dir_combo.setToolTip(_("Search recursively in this directory"))
        self.dir_combo.open_dir.connect(self.set_directory)
        self.python_path.toggled.connect(self.dir_combo.setDisabled)
        self.hg_manifest.toggled.connect(self.dir_combo.setDisabled)
        browse = create_toolbutton(self,
                                   icon=get_std_icon('DirOpenIcon'),
                                   tip=_('Browse a search directory'),
                                   triggered=self.select_directory)
        for widget in [
                self.python_path, self.hg_manifest, self.custom_dir,
                self.dir_combo, browse
        ]:
            hlayout3.addWidget(widget)

        self.search_text.valid.connect(lambda valid: self.find.emit())
        self.include_pattern.valid.connect(lambda valid: self.find.emit())
        self.exclude_pattern.valid.connect(lambda valid: self.find.emit())
        self.dir_combo.valid.connect(lambda valid: self.find.emit())

        vlayout = QVBoxLayout()
        vlayout.setContentsMargins(0, 0, 0, 0)
        vlayout.addLayout(hlayout1)
        vlayout.addLayout(hlayout2)
        vlayout.addLayout(hlayout3)
        self.more_widgets = (hlayout2, hlayout3)
        self.toggle_more_options(more_options)
        self.setLayout(vlayout)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
Example #40
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.current_radio = None
        self.dedicated_radio = None
        self.systerm_radio = None

        self.runconf = RunConfiguration()
        
        firstrun_o = CONF.get('run', ALWAYS_OPEN_FIRST_RUN_OPTION, False)

        # --- General settings ----
        common_group = QGroupBox(_("General settings"))
        common_layout = QGridLayout()
        common_group.setLayout(common_layout)
        self.clo_cb = QCheckBox(_("Command line options:"))
        common_layout.addWidget(self.clo_cb, 0, 0)
        self.clo_edit = QLineEdit()
        self.connect(self.clo_cb, SIGNAL("toggled(bool)"),
                     self.clo_edit.setEnabled)
        self.clo_edit.setEnabled(False)
        common_layout.addWidget(self.clo_edit, 0, 1)
        self.wd_cb = QCheckBox(_("Working directory:"))
        common_layout.addWidget(self.wd_cb, 1, 0)
        wd_layout = QHBoxLayout()
        self.wd_edit = QLineEdit()
        self.connect(self.wd_cb, SIGNAL("toggled(bool)"),
                     self.wd_edit.setEnabled)
        self.wd_edit.setEnabled(False)
        wd_layout.addWidget(self.wd_edit)
        browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self)
        browse_btn.setToolTip(_("Select directory"))
        self.connect(browse_btn, SIGNAL("clicked()"), self.select_directory)
        wd_layout.addWidget(browse_btn)
        common_layout.addLayout(wd_layout, 1, 1)
        
        # --- Interpreter ---
        interpreter_group = QGroupBox(_("Console"))
        interpreter_layout = QVBoxLayout()
        interpreter_group.setLayout(interpreter_layout)
        self.current_radio = QRadioButton(CURRENT_INTERPRETER)
        interpreter_layout.addWidget(self.current_radio)
        self.dedicated_radio = QRadioButton(DEDICATED_INTERPRETER)
        interpreter_layout.addWidget(self.dedicated_radio)
        self.systerm_radio = QRadioButton(SYSTERM_INTERPRETER)
        interpreter_layout.addWidget(self.systerm_radio)
        
        # --- Dedicated interpreter ---
        new_group = QGroupBox(_("Dedicated Python console"))
        self.connect(self.current_radio, SIGNAL("toggled(bool)"),
                     new_group.setDisabled)
        new_layout = QGridLayout()
        new_group.setLayout(new_layout)
        self.interact_cb = QCheckBox(_("Interact with the Python "
                                       "console after execution"))
        new_layout.addWidget(self.interact_cb, 1, 0, 1, -1)
        
        self.show_kill_warning_cb = QCheckBox(_("Show warning when killing"
                                                " running process"))
        new_layout.addWidget(self.show_kill_warning_cb, 2, 0, 1, -1)
        self.pclo_cb = QCheckBox(_("Command line options:"))
        new_layout.addWidget(self.pclo_cb, 3, 0)
        self.pclo_edit = QLineEdit()
        self.connect(self.pclo_cb, SIGNAL("toggled(bool)"),
                     self.pclo_edit.setEnabled)
        self.pclo_edit.setEnabled(False)
        self.pclo_edit.setToolTip(_("<b>-u</b> is added to the "
                                    "other options you set here"))
        new_layout.addWidget(self.pclo_edit, 3, 1)
        
        #TODO: Add option for "Post-mortem debugging"

        # Checkbox to preserve the old behavior, i.e. always open the dialog
        # on first run
        hline = QFrame()
        hline.setFrameShape(QFrame.HLine)
        hline.setFrameShadow(QFrame.Sunken)
        self.firstrun_cb = QCheckBox(ALWAYS_OPEN_FIRST_RUN % _("this dialog"))
        self.connect(self.firstrun_cb, SIGNAL("clicked(bool)"),
                     self.set_firstrun_o)
        self.firstrun_cb.setChecked(firstrun_o)
        
        layout = QVBoxLayout()
        layout.addWidget(interpreter_group)
        layout.addWidget(common_group)
        layout.addWidget(new_group)
        layout.addWidget(hline)
        layout.addWidget(self.firstrun_cb)
        self.setLayout(layout)
Example #41
0
    def __init__(self, parent, workdir=None, **kwds):
        if PYQT5:
            super().__init__(**kwds)
        else:
            QToolBar.__init__(self, parent)
            SpyderPluginMixin.__init__(self, parent)

        # Initialize plugin
        self.initialize_plugin()

        self.setWindowTitle(self.get_plugin_title())  # Toolbar title
        self.setObjectName(
            self.get_plugin_title())  # Used to save Window state

        # Previous dir action
        self.history = []
        self.histindex = None
        self.previous_action = create_action(self,
                                             "previous",
                                             None,
                                             get_icon('previous.png'),
                                             _('Back'),
                                             triggered=self.previous_directory)
        self.addAction(self.previous_action)

        # Next dir action
        self.history = []
        self.histindex = None
        self.next_action = create_action(self,
                                         "next",
                                         None,
                                         get_icon('next.png'),
                                         _('Next'),
                                         triggered=self.next_directory)
        self.addAction(self.next_action)

        # Enable/disable previous/next actions
        self.set_previous_enabled.connect(self.previous_action.setEnabled)
        self.set_next_enabled.connect(self.next_action.setEnabled)

        # Path combo box
        adjust = self.get_option('working_dir_adjusttocontents')
        self.pathedit = PathComboBox(self, adjust_to_contents=adjust)
        self.pathedit.setToolTip(
            _("This is the working directory for newly\n"
              "opened consoles (Python/IPython consoles and\n"
              "terminals), for the file explorer, for the\n"
              "find in files plugin and for new files\n"
              "created in the editor"))
        self.pathedit.open_dir.connect(self.chdir)
        self.pathedit.setMaxCount(self.get_option('working_dir_history'))
        wdhistory = self.load_wdhistory(workdir)
        if workdir is None:
            if self.get_option('startup/use_last_directory'):
                if wdhistory:
                    workdir = wdhistory[0]
                else:
                    workdir = "."
            else:
                workdir = self.get_option('startup/fixed_directory', ".")
                if not osp.isdir(workdir):
                    workdir = "."
        self.chdir(workdir)
        self.pathedit.addItems(wdhistory)
        self.refresh_plugin()
        self.addWidget(self.pathedit)

        # Browse action
        browse_action = create_action(self,
                                      "browse",
                                      None,
                                      get_std_icon('DirOpenIcon'),
                                      _('Browse a working directory'),
                                      triggered=self.select_directory)
        self.addAction(browse_action)

        # Set current console working directory action
        setwd_action = create_action(self,
                                     icon=get_icon('set_workdir.png'),
                                     text=_("Set as current console's "
                                            "working directory"),
                                     triggered=self.set_as_current_console_wd)
        self.addAction(setwd_action)

        # Parent dir action
        parent_action = create_action(self,
                                      "parent",
                                      None,
                                      get_icon('up.png'),
                                      _('Change to parent directory'),
                                      triggered=self.parent_directory)
        self.addAction(parent_action)
Example #42
0
 def update_menu(self):
     """Update option menu"""
     self.menu.clear()
     actions = []
     newdir_action = create_action(self,
                                   translate('Explorer', "New folder..."),
                                   icon="folder_new.png",
                                   triggered=self.new_folder)
     actions.append(newdir_action)
     newfile_action = create_action(self,
                                    translate('Explorer', "New file..."),
                                    icon="filenew.png",
                                    triggered=self.new_file)
     actions.append(newfile_action)
     fname = self.get_filename()
     if fname is not None:
         is_dir = osp.isdir(fname)
         ext = osp.splitext(fname)[1]
         run_action = create_action(self,
                                    translate('Explorer', "Run"),
                                    icon="run_small.png",
                                    triggered=self.run)
         edit_action = create_action(self,
                                     translate('Explorer', "Edit"),
                                     icon="edit.png",
                                     triggered=self.clicked)
         delete_action = create_action(self,
                                       translate('Explorer', "Delete..."),
                                       icon="delete.png",
                                       triggered=self.delete)
         rename_action = create_action(self,
                                       translate('Explorer', "Rename..."),
                                       icon="rename.png",
                                       triggered=self.rename)
         browse_action = create_action(self,
                                       translate('Explorer', "Browse"),
                                       icon=get_std_icon("CommandLink"),
                                       triggered=self.clicked)
         open_action = create_action(self,
                                     translate('Explorer', "Open"),
                                     triggered=self.startfile)
         if ext in ('.py', '.pyw'):
             actions.append(run_action)
         if ext in self.valid_types or os.name != 'nt':
             actions.append(browse_action if is_dir else edit_action)
         else:
             actions.append(open_action)
         actions += [delete_action, rename_action]
         if is_dir and os.name == 'nt':
             # Actions specific to Windows directories
             actions.append(
                 create_action(self,
                               translate('Explorer',
                                         "Open in Windows Explorer"),
                               icon="magnifier.png",
                               triggered=self.startfile))
     if os.name == 'nt':
         actions.append(
             create_action(
                 self,
                 translate('Explorer', "Open command prompt here"),
                 icon="cmdprompt.png",
                 triggered=lambda cmd='cmd.exe': os.startfile(cmd)))
     if actions:
         actions.append(None)
     actions += self.common_actions
     add_actions(self.menu, actions)
Example #43
0
    def __init__(self, parent, search_text, search_text_regexp, search_path,
                 include, include_regexp, exclude, exclude_regexp,
                 supported_encodings):
        QWidget.__init__(self, parent)

        if search_path is None:
            search_path = os.getcwdu()

        if not isinstance(search_text, (list, tuple)):
            search_text = [search_text]
        if not isinstance(search_path, (list, tuple)):
            search_path = [search_path]
        if not isinstance(include, (list, tuple)):
            include = [include]
        if not isinstance(exclude, (list, tuple)):
            exclude = [exclude]

        self.supported_encodings = supported_encodings

        # Layout 1
        hlayout1 = QHBoxLayout()
        self.search_text = PatternComboBox(
            self, search_text, translate('FindInFiles', "Search pattern"))
        search_label = QLabel(translate('FindInFiles', "Search text:"))
        search_label.setBuddy(self.search_text)
        self.edit_regexp = create_toolbutton(self,
                                             get_icon("advanced.png"),
                                             tip=translate(
                                                 'FindInFiles',
                                                 "Regular expression"))
        self.edit_regexp.setCheckable(True)
        self.edit_regexp.setChecked(search_text_regexp)
        self.ok_button = create_toolbutton(
            self,
            text=translate('FindInFiles', "Search"),
            triggered=lambda: self.emit(SIGNAL('find()')),
            icon=get_std_icon("DialogApplyButton"),
            tip=translate('FindInFiles', "Start search"))
        self.connect(self.ok_button, SIGNAL('clicked()'), self.update_combos)
        self.stop_button = create_toolbutton(
            self,
            text=translate('FindInFiles', "Stop"),
            triggered=lambda: self.emit(SIGNAL('stop()')),
            icon=get_icon("terminate.png"),
            tip=translate('FindInFiles', "Stop search"))
        self.stop_button.setEnabled(False)
        for widget in [
                search_label, self.search_text, self.edit_regexp,
                self.ok_button, self.stop_button
        ]:
            hlayout1.addWidget(widget)

        # Layout 2
        hlayout2 = QHBoxLayout()
        self.include_pattern = PatternComboBox(
            self, include,
            translate('FindInFiles', "Included filenames pattern"))
        self.include_regexp = create_toolbutton(self,
                                                get_icon("advanced.png"),
                                                tip=translate(
                                                    'FindInFiles',
                                                    "Regular expression"))
        self.include_regexp.setCheckable(True)
        self.include_regexp.setChecked(include_regexp)
        include_label = QLabel(translate('FindInFiles', "Include:"))
        include_label.setBuddy(self.include_pattern)
        self.exclude_pattern = PatternComboBox(
            self, exclude,
            translate('FindInFiles', "Excluded filenames pattern"))
        self.exclude_regexp = create_toolbutton(self,
                                                get_icon("advanced.png"),
                                                tip=translate(
                                                    'FindInFiles',
                                                    "Regular expression"))
        self.exclude_regexp.setCheckable(True)
        self.exclude_regexp.setChecked(exclude_regexp)
        exclude_label = QLabel(translate('FindInFiles', "Exclude:"))
        exclude_label.setBuddy(self.exclude_pattern)
        for widget in [
                include_label, self.include_pattern, self.include_regexp,
                exclude_label, self.exclude_pattern, self.exclude_regexp
        ]:
            hlayout2.addWidget(widget)

        # Layout 3
        hlayout3 = QHBoxLayout()
        searchin_label = QLabel(translate('FindInFiles', "Search in:"))
        self.python_path = QRadioButton(translate('FindInFiles', "PYTHONPATH"),
                                        self)
        self.python_path.setToolTip(
            translate(
                'FindInFiles',
                "Search in all directories listed in sys.path which"
                " are outside the Python installation directory"))
        self.hg_manifest = QRadioButton(
            translate('FindInFiles', "Hg repository"), self)
        self.detect_hg_repository()
        self.hg_manifest.setToolTip(
            translate('FindInFiles',
                      "Search in current directory hg repository"))
        searchin_label.setBuddy(self.hg_manifest)
        self.custom_dir = QRadioButton(translate('FindInFiles', "Directory:"),
                                       self)
        self.custom_dir.setChecked(True)
        self.dir_combo = PathComboBox(self)
        self.dir_combo.addItems(search_path)
        self.dir_combo.setToolTip(
            translate('FindInFiles', "Search recursively in this directory"))
        self.connect(self.dir_combo, SIGNAL("open_dir(QString)"),
                     self.set_directory)
        self.connect(self.python_path, SIGNAL('toggled(bool)'),
                     self.dir_combo.setDisabled)
        self.connect(self.hg_manifest, SIGNAL('toggled(bool)'),
                     self.dir_combo.setDisabled)
        browse = create_toolbutton(self,
                                   get_std_icon('DirOpenIcon'),
                                   tip=translate('FindInFiles',
                                                 'Browse a search directory'),
                                   triggered=self.select_directory)
        for widget in [
                searchin_label, self.python_path, self.hg_manifest,
                self.custom_dir, self.dir_combo, browse
        ]:
            hlayout3.addWidget(widget)

        vlayout = QVBoxLayout()
        vlayout.addLayout(hlayout1)
        vlayout.addLayout(hlayout2)
        vlayout.addLayout(hlayout3)
        self.setLayout(vlayout)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
Example #44
0
 def __init__(self, parent, workdir=None):
     QToolBar.__init__(self, parent)
     PluginMixin.__init__(self, parent)
     
     self.setWindowTitle(self.get_widget_title()) # Toolbar title
     self.setObjectName(self.get_widget_title()) # Used to save Window state
     
     self.addWidget( QLabel(self.tr("Working directory:")+" ") )
     
     # Previous dir action
     self.history = []
     self.histindex = None
     self.previous_action = create_action(self, "previous", None,
                                  get_icon('previous.png'), self.tr('Back'),
                                  triggered=self.previous_directory)
     self.addAction(self.previous_action)
     
     # Next dir action
     self.history = []
     self.histindex = None
     self.next_action = create_action(self, "next", None,
                                  get_icon('next.png'), self.tr('Next'),
                                  triggered=self.next_directory)
     self.addAction(self.next_action)
     
     # Enable/disable previous/next actions
     self.connect(self, SIGNAL("set_previous_enabled(bool)"),
                  self.previous_action.setEnabled)
     self.connect(self, SIGNAL("set_next_enabled(bool)"),
                  self.next_action.setEnabled)
     
     # Path combo box
     adjust = CONF.get('shell', 'working_dir_adjusttocontents', False)
     self.pathedit = PathComboBox(self, adjust_to_contents=adjust)
     self.pathedit.setToolTip(self.tr("Working directory"))
     self.connect(self.pathedit, SIGNAL("open_dir(QString)"),
                  self.pathedit_activated)
     self.pathedit.setMaxCount(CONF.get('shell', 'working_dir_history'))
     wdhistory = self.load_wdhistory( workdir )
     if workdir is None:
         if wdhistory:
             workdir = wdhistory[0]
         else:
             workdir = "."
     self.chdir(workdir)
     self.pathedit.addItems( wdhistory )
     self.refresh()
     self.addWidget(self.pathedit)
     
     # Browse action
     browse_action = create_action(self, "browse", None,
                                   get_std_icon('DirOpenIcon'),
                                   self.tr('Browse a working directory'),
                                   triggered=self.select_directory)
     self.addAction(browse_action)
     
     # Parent dir action
     parent_action = create_action(self, "parent", None,
                                   get_icon('up.png'),
                                   self.tr('Change to parent directory'),
                                   triggered=self.parent_directory)
     self.addAction(parent_action)
Example #45
0
    def __init__(self, parent, enable_replace=False):
        QWidget.__init__(self, parent)
        self.enable_replace = enable_replace
        self.editor = None

        glayout = QGridLayout()
        glayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(glayout)

        self.close_button = create_toolbutton(
            self, triggered=self.hide, icon=get_std_icon("DialogCloseButton"))
        glayout.addWidget(self.close_button, 0, 0)

        # Find layout
        self.search_text = PatternComboBox(self,
                                           tip=self.tr("Search string"),
                                           adjust_to_minimum=False)
        self.connect(self.search_text, SIGNAL("editTextChanged(QString)"),
                     self.text_has_changed)

        self.previous_button = create_toolbutton(
            self,
            text=self.tr("Previous"),
            triggered=self.find_previous,
            icon=get_std_icon("ArrowBack"))
        self.next_button = create_toolbutton(self,
                                             text=self.tr("Next"),
                                             triggered=self.find_next,
                                             icon=get_std_icon("ArrowForward"))
        self.connect(self.next_button, SIGNAL('clicked()'),
                     self.update_search_combo)
        self.connect(self.previous_button, SIGNAL('clicked()'),
                     self.update_search_combo)

        self.case_check = QCheckBox(self.tr("Case Sensitive"))
        self.connect(self.case_check, SIGNAL("stateChanged(int)"), self.find)
        self.words_check = QCheckBox(self.tr("Whole words"))
        self.connect(self.words_check, SIGNAL("stateChanged(int)"), self.find)

        hlayout = QHBoxLayout()
        self.widgets = [
            self.close_button, self.search_text, self.previous_button,
            self.next_button, self.case_check, self.words_check
        ]
        for widget in self.widgets[1:]:
            hlayout.addWidget(widget)
        glayout.addLayout(hlayout, 0, 1)

        # Replace layout
        replace_with1 = QLabel(self.tr("Replace"))
        replace_with2 = QLabel()
        font = replace_with2.font()
        font.setBold(True)
        replace_with2.setFont(font)
        replace_with3 = QLabel(self.tr("with:"))
        self.replace_text = PatternComboBox(self,
                                            adjust_to_minimum=False,
                                            tip=self.tr("Replace string"))

        self.replace_button = create_toolbutton(
            self,
            text=self.tr("Replace/find"),
            triggered=self.replace_find,
            icon=get_std_icon("DialogApplyButton"))
        self.connect(self.replace_button, SIGNAL('clicked()'),
                     self.update_replace_combo)
        self.connect(self.replace_button, SIGNAL('clicked()'),
                     self.update_search_combo)

        self.all_check = QCheckBox(self.tr("Replace all"))

        self.replace_layout = QHBoxLayout()
        widgets = [
            replace_with1, replace_with2, replace_with3, self.replace_text,
            self.replace_button, self.all_check
        ]
        for widget in widgets:
            self.replace_layout.addWidget(widget)
        self.connect(self.search_text, SIGNAL("editTextChanged(QString)"),
                     replace_with2, SLOT("setText(QString)"))
        glayout.addLayout(self.replace_layout, 1, 1)
        self.widgets.extend(widgets)
        self.replace_widgets = widgets
        self.hide_replace()

        self.search_text.setTabOrder(self.search_text, self.replace_text)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)