Esempio n. 1
0
    def __init__(self, parent, data, readonly=False, title="",
                 names=False, truncate=True, minmax=False,
                 inplace=False, collvalue=True):
        BaseTableView.__init__(self, parent)
        self.dictfilter = None
        self.readonly = readonly or isinstance(data, tuple)
        self.model = None
        self.delegate = None
        DictModelClass = ReadOnlyDictModel if self.readonly else DictModel
        self.model = DictModelClass(self, data, title, names=names,
                                    truncate=truncate, minmax=minmax,
                                    collvalue=collvalue)
        self.setModel(self.model)
        self.delegate = DictDelegate(self, inplace=inplace)
        self.setItemDelegate(self.delegate)

        self.setup_table()
        self.menu = self.setup_menu(truncate, minmax, inplace, collvalue)
        self.copy_action = create_action(self,
                                      translate("DictEditor", "Copy"),
                                      icon=get_icon('editcopy.png'),
                                      triggered=self.copy)                                      
        self.paste_action = create_action(self,
                                      translate("DictEditor", "Paste"),
                                      icon=get_icon('editpaste.png'),
                                      triggered=self.paste)
        self.menu.insertAction(self.remove_action, self.copy_action)
        self.menu.insertAction(self.remove_action, self.paste_action)
        
        self.empty_ws_menu = QMenu(self)
        self.empty_ws_menu.addAction(self.paste_action)
Esempio n. 2
0
 def setup_context_menu(self):
     """Reimplements ShellBaseWidget method"""
     ShellBaseWidget.setup_context_menu(self)
     self.copy_without_prompts_action = create_action(self,
                                  translate("PythonShellWidget",
                                            "Copy without prompts"),
                                  icon=get_icon('copywop.png'),
                                  triggered=self.copy_without_prompts)
     clear_line_action = create_action(self, translate("PythonShellWidget",
                                                       "Clear line"),
                                  QKeySequence("Escape"),
                                  icon=get_icon('eraser.png'),
                                  tip=translate("PythonShellWidget",
                                                "Clear line"),
                                  triggered=self.clear_line)
     clear_action = create_action(self,
                                  translate("PythonShellWidget",
                                            "Clear shell"),
                                  icon=get_icon('clear.png'),
                                  tip=translate("PythonShellWidget",
                                                "Clear shell contents "
                                              "('cls' command)"),
                                  triggered=self.clear_terminal)
     add_actions(self.menu, (self.copy_without_prompts_action,
                 clear_line_action, clear_action))
Esempio n. 3
0
 def setup_common_actions(self):
     """Setup context menu common actions"""
     self.collapse_all_action = create_action(self,
                                  text=_('Collapse all'),
                                  icon=get_icon('collapse.png'),
                                  triggered=self.collapseAll)
     self.expand_all_action = create_action(self,
                                  text=_('Expand all'),
                                  icon=get_icon('expand.png'),
                                  triggered=self.expandAll)
     self.restore_action = create_action(self,
                                  text=_('Restore'),
                                  tip=_('Restore original tree layout'),
                                  icon=get_icon('restore.png'),
                                  triggered=self.restore)
     self.collapse_selection_action = create_action(self,
                                  text=_('Collapse selection'),
                                  icon=get_icon('collapse_selection.png'),
                                  triggered=self.collapse_selection)
     self.expand_selection_action = create_action(self,
                                  text=_('Expand selection'),
                                  icon=get_icon('expand_selection.png'),
                                  triggered=self.expand_selection)
     return [self.collapse_all_action, self.expand_all_action,
             self.restore_action, None,
             self.collapse_selection_action, self.expand_selection_action]
Esempio n. 4
0
 def get_toolbar_buttons(self):
     if self.run_button is None:
         self.run_button = create_toolbutton(self, text=_("Run"),
                                          icon=get_icon('run.png'),
                                          tip=_("Run again this program"),
                                          triggered=self.start_shell)
     if self.kill_button is None:
         self.kill_button = create_toolbutton(self, text=_("Kill"),
                                  icon=get_icon('kill.png'),
                                  tip=_("Kills the current process, "
                                        "causing it to exit immediately"))
     buttons = [self.run_button]
     if self.options_button is None:
         options = self.get_options_menu()
         if options:
             self.options_button = create_toolbutton(self, text=_("Options"),
                                         icon=get_icon('tooloptions.png'))
             self.options_button.setPopupMode(QToolButton.InstantPopup)
             menu = QMenu(self)
             add_actions(menu, options)
             self.options_button.setMenu(menu)
     if self.options_button is not None:
         buttons.append(self.options_button)
     buttons.append(self.kill_button)
     return buttons
Esempio n. 5
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
Esempio n. 6
0
 def setup_context_menu(self):
     """Setup shell context menu"""
     self.menu = QMenu(self)
     self.cut_action = create_action(self,
                                     translate("ShellBaseWidget", "Cut"),
                                     shortcut=keybinding('Cut'),
                                     icon=get_icon('editcut.png'),
                                     triggered=self.cut)
     self.copy_action = create_action(self,
                                      translate("ShellBaseWidget", "Copy"),
                                      shortcut=keybinding('Copy'),
                                      icon=get_icon('editcopy.png'),
                                      triggered=self.copy)
     paste_action = create_action(self,
                                  translate("ShellBaseWidget", "Paste"),
                                  shortcut=keybinding('Paste'),
                                  icon=get_icon('editpaste.png'),
                                  triggered=self.paste)
     save_action = create_action(self,
                                 translate("ShellBaseWidget",
                                           "Save history log..."),
                                 icon=get_icon('filesave.png'),
                                 tip=translate(
                                     "ShellBaseWidget",
                                     "Save current history log (i.e. all "
                                     "inputs and outputs) in a text file"),
                                 triggered=self.save_historylog)
     add_actions(self.menu, (self.cut_action, self.copy_action,
                             paste_action, None, save_action))
Esempio n. 7
0
 def create_scedit(self, text, option, default=NoDefault, tip=None,
                   without_layout=False):
     label = QLabel(text)
     clayout = ColorLayout(QColor(Qt.black), self)
     clayout.lineedit.setMaximumWidth(80)
     if tip is not None:
         clayout.setToolTip(tip)
     cb_bold = QCheckBox()
     cb_bold.setIcon(get_icon("bold.png"))
     cb_bold.setToolTip(_("Bold"))
     cb_italic = QCheckBox()
     cb_italic.setIcon(get_icon("italic.png"))
     cb_italic.setToolTip(_("Italic"))
     self.scedits[(clayout, cb_bold, cb_italic)] = (option, default)
     if without_layout:
         return label, clayout, cb_bold, cb_italic
     layout = QHBoxLayout()
     layout.addWidget(label)
     layout.addLayout(clayout)
     layout.addSpacing(10)
     layout.addWidget(cb_bold)
     layout.addWidget(cb_italic)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.setLayout(layout)
     return widget
Esempio n. 8
0
 def setup_top_toolbar(self, layout):
     toolbar = []
     movetop_button = create_toolbutton(
         self,
         text=self.tr("Move to top"),
         icon=get_icon('2uparrow.png'),
         triggered=lambda: self.move_to(absolute=0))
     toolbar.append(movetop_button)
     moveup_button = create_toolbutton(
         self,
         text=self.tr("Move up"),
         icon=get_icon('1uparrow.png'),
         triggered=lambda: self.move_to(relative=-1))
     toolbar.append(moveup_button)
     movedown_button = create_toolbutton(
         self,
         text=self.tr("Move down"),
         icon=get_icon('1downarrow.png'),
         triggered=lambda: self.move_to(relative=1))
     toolbar.append(movedown_button)
     movebottom_button = create_toolbutton(
         self,
         text=self.tr("Move to bottom"),
         icon=get_icon('2downarrow.png'),
         triggered=lambda: self.move_to(absolute=1))
     toolbar.append(movebottom_button)
     self.selection_widgets.extend(toolbar)
     self._add_widgets_to_layout(layout, toolbar)
     return toolbar
Esempio n. 9
0
 def setup_top_toolbar(self, layout):
     toolbar = []
     movetop_button = create_toolbutton(self,
                                 text=self.tr("Move to top"),
                                 icon=get_icon('2uparrow.png'),
                                 triggered=lambda: self.move_to(absolute=0))
     toolbar.append(movetop_button)
     moveup_button = create_toolbutton(self,
                                 text=self.tr("Move up"),
                                 icon=get_icon('1uparrow.png'),
                                 triggered=lambda: self.move_to(relative=-1))
     toolbar.append(moveup_button)
     movedown_button = create_toolbutton(self,
                                 text=self.tr("Move down"),
                                 icon=get_icon('1downarrow.png'),
                                 triggered=lambda: self.move_to(relative=1))
     toolbar.append(movedown_button)
     movebottom_button = create_toolbutton(self,
                                 text=self.tr("Move to bottom"),
                                 icon=get_icon('2downarrow.png'),
                                 triggered=lambda: self.move_to(absolute=1))
     toolbar.append(movebottom_button)
     self.selection_widgets.extend(toolbar)
     self._add_widgets_to_layout(layout, toolbar)
     return toolbar
Esempio n. 10
0
    def add_history(self, filename):
        """
        Add new history tab
        Slot for SIGNAL('add_history(QString)') emitted by shell instance
        """
        filename = encoding.to_unicode(filename)
        if filename in self.filenames:
            return
        editor = CodeEditor(self)
        if osp.splitext(filename)[1] == '.py':
            language = 'py'
            icon = get_icon('python.png')
        else:
            language = 'bat'
            icon = get_icon('cmdprompt.png')
        editor.setup_editor(linenumbers=False, language=language,
                            code_folding=True, scrollflagarea=False)
        self.connect(editor, SIGNAL("focus_changed()"),
                     lambda: self.emit(SIGNAL("focus_changed()")))
        editor.setReadOnly(True)
        editor.set_font( get_font(self.ID) )
        editor.toggle_wrap_mode( CONF.get(self.ID, 'wrap') )

        text, _ = encoding.read(filename)
        editor.set_text(text)
        editor.set_cursor_position('eof')
        
        self.editors.append(editor)
        self.filenames.append(filename)
        self.icons.append(icon)
        index = self.tabwidget.addTab(editor, osp.basename(filename))
        self.find_widget.set_editor(editor)
        self.tabwidget.setTabToolTip(index, filename)
        self.tabwidget.setTabIcon(index, icon)
        self.tabwidget.setCurrentIndex(index)
Esempio n. 11
0
    def __init__(self, parent=None, name_filters=['*.py', '*.pyw'],
                 valid_types=('.py', '.pyw'), show_all=False,
                 show_cd_only=None, show_toolbar=True, show_icontext=True):
        QWidget.__init__(self, parent)
        
        self.treewidget = ExplorerTreeWidget(self, show_cd_only=show_cd_only)
        self.treewidget.setup(name_filters=name_filters,
                              valid_types=valid_types, show_all=show_all)
        self.treewidget.chdir(os.getcwdu())
        
        toolbar_action = create_action(self, _("Show toolbar"),
                                       toggled=self.toggle_toolbar)
        icontext_action = create_action(self, _("Show icons and text"),
                                        toggled=self.toggle_icontext)
        self.treewidget.common_actions += [None,
                                           toolbar_action, icontext_action]
        
        # Setup toolbar
        self.toolbar = QToolBar(self)
        self.toolbar.setIconSize(QSize(16, 16))
        
        self.previous_action = create_action(self, text=_("Previous"),
                            icon=get_icon('previous.png'),
                            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_icon('next.png'),
                            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_icon('up.png'),
                            triggered=self.treewidget.go_to_parent_directory)
        self.toolbar.addAction(parent_action)

        options_action = create_action(self, text=_("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)
            
        toolbar_action.setChecked(show_toolbar)
        self.toggle_toolbar(show_toolbar)   
        icontext_action.setChecked(show_icontext)
        self.toggle_icontext(show_icontext)     
        
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.toolbar)
        vlayout.addWidget(self.treewidget)
        self.setLayout(vlayout)
Esempio n. 12
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
Esempio n. 13
0
 def setup_bottom_toolbar(self, layout):
     toolbar = []
     add_button = create_toolbutton(self,
                                    text=self.tr("Add path"),
                                    icon=get_icon('edit_add.png'),
                                    triggered=self.add_path)
     toolbar.append(add_button)
     remove_button = create_toolbutton(self,
                                       text=self.tr("Remove path"),
                                       icon=get_icon('edit_remove.png'),
                                       triggered=self.remove_path)
     toolbar.append(remove_button)
     self.selection_widgets.append(remove_button)
     self._add_widgets_to_layout(layout, toolbar)
     layout.addStretch(1)
     if os.name == 'nt':
         self.sync_button = create_toolbutton(
             self,
             text=self.tr("Synchronize..."),
             icon=get_icon('synchronize.png'),
             triggered=self.synchronize,
             tip=self.tr("Synchronize Spyder's path list with PYTHONPATH "
                         "environment variable"))
         layout.addWidget(self.sync_button)
     return toolbar
Esempio n. 14
0
 def setup_context_menu(self):
     """Setup shell context menu"""
     self.menu = QMenu(self)
     self.cut_action = create_action(self,
                                     translate("ShellBaseWidget", "Cut"),
                                     shortcut=keybinding('Cut'),
                                     icon=get_icon('editcut.png'),
                                     triggered=self.cut)
     self.copy_action = create_action(self,
                                      translate("ShellBaseWidget", "Copy"),
                                      shortcut=keybinding('Copy'),
                                      icon=get_icon('editcopy.png'),
                                      triggered=self.copy)
     paste_action = create_action(self,
                                  translate("ShellBaseWidget", "Paste"),
                                  shortcut=keybinding('Paste'),
                                  icon=get_icon('editpaste.png'),
                                  triggered=self.paste)
     save_action = create_action(self,
                                 translate("ShellBaseWidget",
                                           "Save history log..."),
                                 icon=get_icon('filesave.png'),
                                 tip=translate("ShellBaseWidget",
                                       "Save current history log (i.e. all "
                                       "inputs and outputs) in a text file"),
                                 triggered=self.save_historylog)
     add_actions(self.menu, (self.cut_action, self.copy_action,
                             paste_action, None, save_action) )
Esempio n. 15
0
 def setup_bottom_toolbar(self, layout, sync=True):
     toolbar = []
     add_button = create_toolbutton(
         self, text=_("Add path"), icon=get_icon("edit_add.png"), triggered=self.add_path, text_beside_icon=True
     )
     toolbar.append(add_button)
     remove_button = create_toolbutton(
         self,
         text=_("Remove path"),
         icon=get_icon("edit_remove.png"),
         triggered=self.remove_path,
         text_beside_icon=True,
     )
     toolbar.append(remove_button)
     self.selection_widgets.append(remove_button)
     self._add_widgets_to_layout(layout, toolbar)
     layout.addStretch(1)
     if os.name == "nt" and sync:
         self.sync_button = create_toolbutton(
             self,
             text=_("Synchronize..."),
             icon=get_icon("synchronize.png"),
             triggered=self.synchronize,
             tip=_("Synchronize Spyder's path list with PYTHONPATH " "environment variable"),
             text_beside_icon=True,
         )
         layout.addWidget(self.sync_button)
     return toolbar
Esempio n. 16
0
 def __init__(self, parent):
     QWebView.__init__(self, parent)
     self.zoom_factor = 1.
     self.zoom_out_action = create_action(self, _("Zoom out"),
                                          icon=get_icon('zoom_out.png'),
                                          triggered=self.zoom_out)
     self.zoom_in_action = create_action(self, _("Zoom in"),
                                         icon=get_icon('zoom_in.png'),
                                         triggered=self.zoom_in)
Esempio n. 17
0
    def __init__(self,
                 parent,
                 search_text=r"# ?TODO|# ?FIXME|# ?XXX",
                 search_text_regexp=True,
                 search_path=None,
                 include=".",
                 include_regexp=True,
                 exclude=r"\.pyc$|\.orig$|\.hg|\.svn",
                 exclude_regexp=True,
                 supported_encodings=("utf-8", "iso-8859-1", "cp1252")):
        QWidget.__init__(self, parent)

        self.search_thread = SearchThread(self)
        self.connect(self.search_thread, SIGNAL("finished()"),
                     self.search_complete)

        self.find_options = FindOptions(self, search_text, search_text_regexp,
                                        search_path, include, include_regexp,
                                        exclude, exclude_regexp,
                                        supported_encodings)
        self.connect(self.find_options, SIGNAL('find()'), self.find)
        self.connect(self.find_options, SIGNAL('stop()'), self.stop)

        self.result_browser = ResultsBrowser(self)

        collapse_btn = create_toolbutton(
            self,
            get_icon("collapse.png"),
            tip=translate('FindInFiles', "Collapse all"),
            triggered=self.result_browser.collapseAll)
        expand_btn = create_toolbutton(self,
                                       get_icon("expand.png"),
                                       tip=translate('FindInFiles',
                                                     "Expand all"),
                                       triggered=self.result_browser.expandAll)
        restore_btn = create_toolbutton(self,
                                        get_icon("restore.png"),
                                        tip=translate(
                                            'FindInFiles',
                                            "Restore original tree layout"),
                                        triggered=self.result_browser.restore)
        btn_layout = QVBoxLayout()
        btn_layout.setAlignment(Qt.AlignTop)
        for widget in [collapse_btn, expand_btn, restore_btn]:
            btn_layout.addWidget(widget)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.result_browser)
        hlayout.addLayout(btn_layout)

        layout = QVBoxLayout()
        left, _, right, bottom = layout.getContentsMargins()
        layout.setContentsMargins(left, 0, right, bottom)
        layout.addWidget(self.find_options)
        layout.addLayout(hlayout)
        self.setLayout(layout)
Esempio n. 18
0
 def get_toolbar_buttons(self):
     self.run_button = create_toolbutton(self, get_icon('run.png'),
                           self.tr("Run"),
                           tip=self.tr("Run again this program"),
                           triggered=self.start)
     self.kill_button = create_toolbutton(self, get_icon('kill.png'),
                           self.tr("Kill"),
                           tip=self.tr("Kills the current process, "
                                       "causing it to exit immediately"))
     return [self.run_button, self.kill_button]
Esempio n. 19
0
 def setup_common_actions(self):
     """Setup context menu common actions"""
     collapse_act = create_action(self,
                 text=self.tr('Collapse all'),
                 icon=get_icon('collapse.png'),
                 triggered=self.collapseAll)
     expand_act = create_action(self,
                 text=self.tr('Expand all'),
                 icon=get_icon('expand.png'),
                 triggered=self.expandAll)
     return [collapse_act, expand_act]
Esempio n. 20
0
 def populate_classes(self):
     """Populate classes"""
     self.lines = {}
     for lineno, c_name, methods in self.classes:
         item = QTreeWidgetItem(self, [c_name])
         self.lines[item] = lineno
         if methods is None:
             item.setIcon(0, get_icon('function.png'))
         else:
             item.setIcon(0, get_icon('class.png'))
         if methods:
             self.populate_methods(item, c_name, methods)
Esempio n. 21
0
 def populate_classes(self):
     """Populate classes"""
     self.lines = {}
     for lineno, c_name, methods in self.classes:
         item = QTreeWidgetItem(self, [c_name])
         self.lines[item] = lineno
         if methods is None:
             item.setIcon(0, get_icon('function.png'))
         else:
             item.setIcon(0, get_icon('class.png'))
         if methods:
             self.populate_methods(item, c_name, methods)
Esempio n. 22
0
def create_action(parent,
                  text,
                  shortcut=None,
                  icon=None,
                  tip=None,
                  toggled=None,
                  triggered=None,
                  data=None,
                  window_context=True):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        parent.connect(action, SIGNAL("triggered()"), triggered)
    if toggled is not None:
        parent.connect(action, SIGNAL("toggled(bool)"), toggled)
        action.setCheckable(True)
    if icon is not None:
        if isinstance(icon, (str, unicode)):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(QVariant(data))
    if window_context:
        action.setShortcutContext(Qt.WindowShortcut)
    else:
        #TODO: Hard-code all shortcuts and choose window_context=False
        # (this will avoid calling shortcuts from another dockwidget
        #  since the context thing doesn't work quite well with these)
        action.setShortcutContext(Qt.WidgetShortcut)
    return action
Esempio n. 23
0
 def populate_methods(self, parent, c_name, methods):
     """Populate methods"""
     for lineno, m_name in methods:
         decorator = m_name.startswith('@')
         if decorator:
             m_name = m_name[1:]
         item = QTreeWidgetItem(parent, [m_name])
         self.lines[item] = lineno
         if m_name.startswith('__'):
             item.setIcon(0, get_icon('private2.png'))
         elif m_name.startswith('_'):
             item.setIcon(0, get_icon('private1.png'))
         elif decorator:
             item.setIcon(0, get_icon('decorator.png'))
         else:
             item.setIcon(0, get_icon('method.png'))
Esempio n. 24
0
 def populate_methods(self, parent, c_name, methods):
     """Populate methods"""
     for lineno, m_name in methods:
         decorator = m_name.startswith('@')
         if decorator:
             m_name = m_name[1:]
         item = QTreeWidgetItem(parent, [m_name])
         self.lines[item] = lineno
         if m_name.startswith('__'):
             item.setIcon(0, get_icon('private2.png'))
         elif m_name.startswith('_'):
             item.setIcon(0, get_icon('private1.png'))
         elif decorator:
             item.setIcon(0, get_icon('decorator.png'))
         else:
             item.setIcon(0, get_icon('method.png'))
Esempio n. 25
0
    def __init__(self, parent):
        self.tabwidget = None
        self.menu_actions = None
        self.dockviewer = None
        
        self.editors = []
        self.filenames = []
        self.icons = []
        
        SpyderPluginWidget.__init__(self, parent)
        
        layout = QVBoxLayout()
        self.tabwidget = Tabs(self, self.menu_actions)
        self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
                     self.refresh_plugin)
        self.connect(self.tabwidget, SIGNAL('move_data(int,int)'),
                     self.move_tab)
        layout.addWidget(self.tabwidget)

        # Menu as corner widget
        options_button = create_toolbutton(self, text=self.tr("Options"),
                                           icon=get_icon('tooloptions.png'))
        options_button.setPopupMode(QToolButton.InstantPopup)
        menu = QMenu(self)
        add_actions(menu, self.menu_actions)
        options_button.setMenu(menu)
        self.tabwidget.setCornerWidget(options_button)
        
        # Find/replace widget
        self.find_widget = FindReplace(self)
        self.find_widget.hide()
        layout.addWidget(self.find_widget)
        
        self.setLayout(layout)
Esempio n. 26
0
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  toggled=None, triggered=None, data=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        parent.connect(action, SIGNAL("triggered()"), triggered)
    if toggled is not None:
        parent.connect(action, SIGNAL("toggled(bool)"), toggled)
        action.setCheckable(True)
    if icon is not None:
        if isinstance(icon, (str, unicode)):
            icon = get_icon(icon)
        action.setIcon( icon )
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(QVariant(data))
    #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
Esempio n. 27
0
 def _init_toolbar(self):
     super(NavigationToolbar2QT, self)._init_toolbar()
     if edit_parameters is None:
         from spyderlib.config import get_icon
         a = self.addAction(get_icon("options.svg"),
                            'Customize', self.edit_parameters)
         a.setToolTip('Edit curves line and axes parameters')
Esempio n. 28
0
    def __init__(self, text, title='', font=None, parent=None,
                 readonly=False, size=(400, 300)):
        super(TextEditor, self).__init__(parent)
        
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        # Text edit
        self.edit = QTextEdit(parent)
        self.edit.setReadOnly(readonly)
        self.edit.setPlainText(text)
        if font is None:
            font = get_font('texteditor')
        self.edit.setFont(font)
        self.layout.addWidget(self.edit)

        # Buttons configuration
        buttons = QDialogButtonBox.Ok
        if not readonly:
            buttons = buttons | QDialogButtonBox.Cancel
        bbox = QDialogButtonBox(buttons)
        self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
        self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
        self.layout.addWidget(bbox)
        
        # Make the dialog act as a window
        self.setWindowFlags(Qt.Window)
        
        self.setWindowIcon(get_icon('edit.png'))
        self.setWindowTitle(self.tr("Text editor") + \
                            "%s" % (" - "+str(title) if str(title) else ""))
        self.resize(size[0], size[1])
Esempio n. 29
0
    def __init__(self, parent, actions=None, menu=None,
                 corner_widgets=None, menu_use_tooltips=False):
        QTabWidget.__init__(self, parent)
        
        self.setUsesScrollButtons(True)
        
        self.corner_widgets = {}
        self.menu_use_tooltips = menu_use_tooltips
        
        if menu is None:
            self.menu = QMenu(self)
            if actions:
                add_actions(self.menu, actions)
        else:
            self.menu = menu
            
        # Corner widgets
        if corner_widgets is None:
            corner_widgets = {}
        corner_widgets.setdefault(Qt.TopLeftCorner, [])
        corner_widgets.setdefault(Qt.TopRightCorner, [])
        self.browse_button = create_toolbutton(self,
                                          icon=get_icon("browse_tab.png"),
                                          tip=_("Browse tabs"))
        self.browse_tabs_menu = QMenu(self)
        self.browse_button.setMenu(self.browse_tabs_menu)
        self.browse_button.setPopupMode(self.browse_button.InstantPopup)
        self.connect(self.browse_tabs_menu, SIGNAL("aboutToShow()"),
                     self.update_browse_tabs_menu)
        corner_widgets[Qt.TopLeftCorner] += [self.browse_button]

        self.set_corner_widgets(corner_widgets)
Esempio n. 30
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        SizeMixin.__init__(self)

        # Destroying the C++ object right after closing the dialog box,
        # otherwise it may be garbage-collected in another QThread
        # (e.g. the editor's analysis thread in Spyder), thus leading to
        # a segmentation fault on UNIX or an application crash on Windows
        self.setAttribute(Qt.WA_DeleteOnClose)

        self.filename = None

        self.runconfigoptions = RunConfigOptions(self)

        bbox = QDialogButtonBox(QDialogButtonBox.Cancel)
        bbox.addButton(_("Run"), QDialogButtonBox.AcceptRole)
        self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
        self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))

        btnlayout = QHBoxLayout()
        btnlayout.addStretch(1)
        btnlayout.addWidget(bbox)

        layout = QVBoxLayout()
        layout.addWidget(self.runconfigoptions)
        layout.addLayout(btnlayout)
        self.setLayout(layout)

        self.setWindowIcon(get_icon("run.png"))
Esempio n. 31
0
    def __init__(self, data, title="", width=500,
                 readonly=False, icon='dictedit.png', remote=False):
        QDialog.__init__(self)
        import copy
        self.data_copy = copy.deepcopy(data)
        self.widget = DictEditorWidget(self, self.data_copy, title=title,
                                       readonly=readonly, remote=remote)
        
        layout = QVBoxLayout()
        layout.addWidget(self.widget)
        self.setLayout(layout)
        
        # Buttons configuration
        buttons = QDialogButtonBox.Ok
        if not readonly:
            buttons = buttons | QDialogButtonBox.Cancel
        bbox = QDialogButtonBox(buttons)
        self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
        if not readonly:
            self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
        layout.addWidget(bbox)

        constant = 121
        row_height = 30
        error_margin = 20
        height = constant + row_height*min([20, len(data)]) + error_margin
        self.resize(width, height)
        
        self.setWindowTitle(self.widget.get_title())
        if isinstance(icon, (str, unicode)):
            icon = get_icon(icon)
        self.setWindowIcon(icon)
        # Make the dialog act as a window
        self.setWindowFlags(Qt.Window)
Esempio n. 32
0
def create_python_gui_script_action(parent, text, icon, package, module):
    """Create action to run a GUI based Python script"""
    if isinstance(icon, basestring):
        icon = get_icon(icon)
    if programs.is_python_gui_script_installed(package, module):
        return create_action(parent, text, icon=icon,
                             triggered=lambda:
                             programs.run_python_gui_script(package, module))
Esempio n. 33
0
 def get_toolbar_buttons(self):
     ExternalShellBase.get_toolbar_buttons(self)
     self.globalsexplorer_button = create_toolbutton(self,
                       get_icon('dictedit.png'), self.tr("Variables"),
                       tip=self.tr("Show/hide global variables explorer"),
                       toggled=self.toggle_globals_explorer)
     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)."))        
     self.interact_check = QCheckBox(self.tr("Interact"), self)
     self.debug_check = QCheckBox(self.tr("Debug"), self)
     return [self.interact_check, self.debug_check,
             self.globalsexplorer_button, self.run_button,
             self.terminate_button, self.kill_button]
Esempio n. 34
0
    def __init__(self, parent,
                 search_text = r"# ?TODO|# ?FIXME|# ?XXX",
                 search_text_regexp=True, search_path=None,
                 include=".", include_regexp=True,
                 exclude=r"\.pyc$|\.orig$|\.hg|\.svn", exclude_regexp=True,
                 supported_encodings=("utf-8", "iso-8859-1", "cp1252")):
        QWidget.__init__(self, parent)

        self.search_thread = SearchThread(self)
        self.connect(self.search_thread, SIGNAL("finished()"),
                     self.search_complete)
        
        self.find_options = FindOptions(self, search_text, search_text_regexp,
                                        search_path, include, include_regexp,
                                        exclude, exclude_regexp,
                                        supported_encodings)
        self.connect(self.find_options, SIGNAL('find()'), self.find)
        self.connect(self.find_options, SIGNAL('stop()'), self.stop)
        
        self.result_browser = ResultsBrowser(self)
        
        collapse_btn = create_toolbutton(self, get_icon("collapse.png"),
                                 tip=translate('FindInFiles', "Collapse all"),
                                 triggered=self.result_browser.collapseAll)
        expand_btn = create_toolbutton(self, get_icon("expand.png"),
                                 tip=translate('FindInFiles', "Expand all"),
                                 triggered=self.result_browser.expandAll)
        restore_btn = create_toolbutton(self, get_icon("restore.png"),
                                 tip=translate('FindInFiles',
                                               "Restore original tree layout"),
                                 triggered=self.result_browser.restore)
        btn_layout = QVBoxLayout()
        btn_layout.setAlignment(Qt.AlignTop)
        for widget in [collapse_btn, expand_btn, restore_btn]:
            btn_layout.addWidget(widget)
        
        hlayout = QHBoxLayout()
        hlayout.addWidget(self.result_browser)
        hlayout.addLayout(btn_layout)
        
        layout = QVBoxLayout()
        left, _, right, bottom = layout.getContentsMargins()
        layout.setContentsMargins(left, 0, right, bottom)
        layout.addWidget(self.find_options)
        layout.addLayout(hlayout)
        self.setLayout(layout)
Esempio n. 35
0
 def get_plugin_icon(self):
     """
     Return plugin icon (QIcon instance)
     Note: this is required for plugins creating a main window
           (see SpyderPluginMixin.create_mainwindow)
           and for configuration dialog widgets creation
     """
     return get_icon('qt.png')
Esempio n. 36
0
 def __init__(self, parent):
     OneColumnTree.__init__(self, parent)
     title = _("Outline")
     self.setWindowTitle(title)
     self.set_title(title)
     self.fname = None
     self.classes = None
     self.lines = None
     self.setWindowIcon(get_icon('outline_explorer.png'))
Esempio n. 37
0
def create_python_gui_script_action(parent, text, icon, package, module):
    """Create action to run a GUI based Python script"""
    if isinstance(icon, basestring):
        icon = get_icon(icon)
    if programs.is_python_gui_script_installed(package, module):
        return create_action(
            parent,
            text,
            icon=icon,
            triggered=lambda: programs.run_python_gui_script(package, module))
Esempio n. 38
0
def create_bookmark_action(parent, url, title, icon=None, shortcut=None):
    """Create bookmark action"""
    if icon is None:
        icon = get_icon('browser.png')
    if os.name == 'nt':
        callback = os.startfile
    else:
        callback = webbrowser.open
    return create_action( parent, title, shortcut=shortcut, icon=icon,
                          triggered=lambda u=url: callback(u) )
Esempio n. 39
0
    def __init__(self,
                 parent,
                 data,
                 readonly=False,
                 title="",
                 names=False,
                 truncate=True,
                 minmax=False,
                 inplace=False,
                 collvalue=True):
        BaseTableView.__init__(self, parent)
        self.dictfilter = None
        self.readonly = readonly or isinstance(data, tuple)
        self.model = None
        self.delegate = None
        DictModelClass = ReadOnlyDictModel if self.readonly else DictModel
        self.model = DictModelClass(self,
                                    data,
                                    title,
                                    names=names,
                                    truncate=truncate,
                                    minmax=minmax,
                                    collvalue=collvalue)
        self.setModel(self.model)
        self.delegate = DictDelegate(self, inplace=inplace)
        self.setItemDelegate(self.delegate)

        self.setup_table()
        self.menu = self.setup_menu(truncate, minmax, inplace, collvalue)
        self.copy_action = create_action(self,
                                         translate("DictEditor", "Copy"),
                                         icon=get_icon('editcopy.png'),
                                         triggered=self.copy)
        self.paste_action = create_action(self,
                                          translate("DictEditor", "Paste"),
                                          icon=get_icon('editpaste.png'),
                                          triggered=self.paste)
        self.menu.insertAction(self.remove_action, self.copy_action)
        self.menu.insertAction(self.remove_action, self.paste_action)

        self.empty_ws_menu = QMenu(self)
        self.empty_ws_menu.addAction(self.paste_action)
Esempio n. 40
0
def add_module_dependent_bookmarks(parent, menu, bookmarks):
    """
    Add bookmarks to a menu depending on module installation:
    bookmarks = ((module_name, url, title), ...)
    """
    for key, url, title, icon in bookmarks:
        try:
            imp.find_module(key)
            add_bookmark(parent, menu, url, title, get_icon(icon))
        except ImportError:
            pass
Esempio n. 41
0
 def setup_menu(self):
     """Setup context menu"""
     self.copy_action = create_action(self,
                                      translate("ArrayEditor", "Copy"),
                                      shortcut=keybinding("Copy"),
                                      icon=get_icon('editcopy.png'),
                                      triggered=self.copy,
                                      window_context=False)
     menu = QMenu(self)
     add_actions(menu, [
         self.copy_action,
     ])
     return menu
Esempio n. 42
0
 def get_toolbar_buttons(self):
     ExternalShellBase.get_toolbar_buttons(self)
     self.globalsexplorer_button = create_toolbutton(
         self,
         get_icon('dictedit.png'),
         self.tr("Variables"),
         tip=self.tr("Show/hide global variables explorer"),
         toggled=self.toggle_globals_explorer)
     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)."))
     self.interact_check = QCheckBox(self.tr("Interact"), self)
     self.debug_check = QCheckBox(self.tr("Debug"), self)
     return [
         self.interact_check, self.debug_check, self.globalsexplorer_button,
         self.run_button, self.terminate_button, self.kill_button
     ]
Esempio n. 43
0
def add_bookmark(parent, menu, url, title, icon=None, shortcut=None):
    """Add bookmark to a menu"""
    if icon is None:
        icon = get_icon('browser.png')
    if os.name == 'nt':
        callback = os.startfile
    else:
        callback = webbrowser.open
    act = create_action(parent,
                        title,
                        shortcut=shortcut,
                        icon=icon,
                        triggered=lambda u=url: callback(u))
    menu.addAction(act)
Esempio n. 44
0
def create_program_action(parent, text, icon, name, nt_name=None):
    """Create action to run a program"""
    if os.name == 'nt':
        if nt_name is None:
            name += ".exe"
        else:
            name = nt_name
    if isinstance(icon, basestring):
        icon = get_icon(icon)
    if programs.is_program_installed(name):
        return create_action(parent,
                             text,
                             icon=icon,
                             triggered=lambda: programs.run_program(name))
Esempio n. 45
0
 def setup_context_menu(self):
     """Reimplements ShellBaseWidget method"""
     ShellBaseWidget.setup_context_menu(self)
     self.copy_without_prompts_action = create_action(
         self,
         translate("PythonShellWidget", "Copy without prompts"),
         icon=get_icon('copywop.png'),
         triggered=self.copy_without_prompts)
     clear_line_action = create_action(
         self,
         translate("PythonShellWidget", "Clear line"),
         QKeySequence("Escape"),
         icon=get_icon('eraser.png'),
         tip=translate("PythonShellWidget", "Clear line"),
         triggered=self.clear_line)
     clear_action = create_action(
         self,
         translate("PythonShellWidget", "Clear shell"),
         icon=get_icon('clear.png'),
         tip=translate("PythonShellWidget", "Clear shell contents "
                       "('cls' command)"),
         triggered=self.clear_terminal)
     add_actions(self.menu, (self.copy_without_prompts_action,
                             clear_line_action, clear_action))
Esempio n. 46
0
    def add_history(self, filename):
        """
        Add new history tab
        Slot for SIGNAL('add_history(QString)') emitted by shell instance
        """
        filename = encoding.to_unicode(filename)
        if filename in self.filenames:
            return
        editor = QsciEditor(self)
        if osp.splitext(filename)[1] == '.py':
            language = 'py'
            icon = get_icon('python.png')
        else:
            language = 'bat'
            icon = get_icon('cmdprompt.png')
        editor.setup_editor(linenumbers=False,
                            language=language,
                            code_folding=True)
        self.connect(editor, SIGNAL("focus_changed()"),
                     lambda: self.emit(SIGNAL("focus_changed()")))
        editor.setReadOnly(True)
        editor.set_font(get_font(self.ID))
        editor.toggle_wrap_mode(CONF.get(self.ID, 'wrap'))

        text, _ = encoding.read(filename)
        editor.set_text(text)
        editor.set_cursor_position('eof')

        self.editors.append(editor)
        self.filenames.append(filename)
        self.icons.append(icon)
        index = self.tabwidget.addTab(editor, osp.basename(filename))
        self.find_widget.set_editor(editor)
        self.tabwidget.setTabToolTip(index, filename)
        self.tabwidget.setTabIcon(index, icon)
        self.tabwidget.setCurrentIndex(index)
Esempio n. 47
0
    def setup_common_actions(self):
        """Setup context menu common actions"""
        # Filters
        filters_action = create_action(self,
                                       translate('Explorer',
                                                 "Edit filename filters..."),
                                       None,
                                       get_icon('filter.png'),
                                       triggered=self.edit_filter)
        # Show all files
        all_action = create_action(self,
                                   translate('Explorer', "Show all files"),
                                   toggled=self.toggle_all)
        all_action.setChecked(self.show_all)
        self.toggle_all(self.show_all)

        return [filters_action, all_action]
Esempio n. 48
0
    def __init__(self,
                 data,
                 title="",
                 width=500,
                 readonly=False,
                 icon='dictedit.png',
                 remote=False):
        QDialog.__init__(self)
        import copy
        self.data_copy = copy.deepcopy(data)
        self.widget = DictEditorWidget(self,
                                       self.data_copy,
                                       title=title,
                                       readonly=readonly,
                                       remote=remote)

        layout = QVBoxLayout()
        layout.addWidget(self.widget)
        self.setLayout(layout)

        # Buttons configuration
        buttons = QDialogButtonBox.Ok
        if not readonly:
            buttons = buttons | QDialogButtonBox.Cancel
        bbox = QDialogButtonBox(buttons)
        self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
        if not readonly:
            self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
        layout.addWidget(bbox)

        constant = 121
        row_height = 30
        error_margin = 20
        height = constant + row_height * min([20, len(data)]) + error_margin
        self.resize(width, height)

        self.setWindowTitle(self.widget.get_title())
        if isinstance(icon, (str, unicode)):
            icon = get_icon(icon)
        self.setWindowIcon(icon)
        # Make the dialog act as a window
        self.setWindowFlags(Qt.Window)
Esempio n. 49
0
 def refresh(self):
     title = translate('Pylint', 'Results for ') + self.filename
     self.set_title(title)
     self.clear()
     self.data = {}
     # Populating tree
     results = ((translate('Pylint', 'Convention'),
                 get_icon('convention.png'), self.results['C:']),
                (translate('Pylint', 'Refactor'), get_icon('refactor.png'),
                 self.results['R:']),
                (translate('Pylint', 'Warning'), get_icon('warning.png'),
                 self.results['W:']), (translate('Pylint', 'Error'),
                                       get_icon('error.png'),
                                       self.results['E:']))
     for title, icon, messages in results:
         title += ' (%d message%s)' % (len(messages),
                                       's' if len(messages) > 1 else '')
         title_item = QTreeWidgetItem(self, [title])
         title_item.setIcon(0, icon)
         if not messages:
             title_item.setDisabled(True)
         modules = {}
         for module, lineno, message in messages:
             basename = osp.splitext(osp.basename(self.filename))[0]
             if not module.startswith(basename):
                 # Pylint bug
                 i_base = module.find(basename)
                 module = module[i_base:]
             dirname = osp.dirname(self.filename)
             modname = osp.join(dirname, *module.split('.'))
             if osp.isdir(modname):
                 modname = osp.join(modname, '__init__')
             for ext in ('.py', '.pyw'):
                 if osp.isfile(modname + ext):
                     modname = modname + ext
                     break
             if osp.isdir(self.filename):
                 parent = modules.get(modname)
                 if parent is None:
                     item = QTreeWidgetItem(title_item, [module])
                     item.setIcon(0, get_icon('py.png'))
                     modules[modname] = item
                     parent = item
             else:
                 parent = title_item
             msg_item = QTreeWidgetItem(parent,
                                        ["%d : %s" % (lineno, message)])
             msg_item.setIcon(0, get_icon('arrow.png'))
             self.data[msg_item] = (modname, lineno)
Esempio n. 50
0
 def setup_context_menu(self):
     """Setup context menu"""
     self.undo_action = create_action(self,
                        translate("SimpleEditor", "Undo"),
                        shortcut=keybinding('Undo'),
                        icon=get_icon('undo.png'), triggered=self.undo)
     self.redo_action = create_action(self,
                        translate("SimpleEditor", "Redo"),
                        shortcut=keybinding('Redo'),
                        icon=get_icon('redo.png'), triggered=self.redo)
     self.cut_action = create_action(self,
                        translate("SimpleEditor", "Cut"),
                        shortcut=keybinding('Cut'),
                        icon=get_icon('editcut.png'), triggered=self.cut)
     self.copy_action = create_action(self,
                        translate("SimpleEditor", "Copy"),
                        shortcut=keybinding('Copy'),
                        icon=get_icon('editcopy.png'), triggered=self.copy)
     paste_action = create_action(self,
                        translate("SimpleEditor", "Paste"),
                        shortcut=keybinding('Paste'),
                        icon=get_icon('editpaste.png'), triggered=self.paste)
     self.delete_action = create_action(self,
                        translate("SimpleEditor", "Delete"),
                        shortcut=keybinding('Delete'),
                        icon=get_icon('editdelete.png'),
                        triggered=self.removeSelectedText)
     selectall_action = create_action(self,
                        translate("SimpleEditor", "Select all"),
                        shortcut=keybinding('SelectAll'),
                        icon=get_icon('selectall.png'),
                        triggered=self.selectAll)
     self.menu = QMenu(self)
     add_actions(self.menu, (self.undo_action, self.redo_action, None,
                             self.cut_action, self.copy_action,
                             paste_action, self.delete_action,
                             None, selectall_action))        
     # Read-only context-menu
     self.readonly_menu = QMenu(self)
     add_actions(self.readonly_menu,
                 (self.copy_action, None, selectall_action))        
Esempio n. 51
0
    def __init__(self, parent, commands=None):
        self.commands = commands
        self.tabwidget = None
        self.menu_actions = None
        self.docviewer = None
        self.historylog = None

        self.shells = []
        self.filenames = []
        self.icons = []

        PluginWidget.__init__(self, parent)

        layout = QVBoxLayout()
        self.tabwidget = Tabs(self, self.menu_actions)
        self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
                     self.refresh)
        self.connect(self.tabwidget, SIGNAL("close_tab(int)"),
                     self.tabwidget.removeTab)
        self.connect(self.tabwidget, SIGNAL('move_data(int,int)'),
                     self.move_tab)
        self.close_button = create_toolbutton(
            self.tabwidget,
            icon=get_icon("fileclose.png"),
            triggered=self.close_console,
            tip=self.tr("Close current console"))
        self.tabwidget.setCornerWidget(self.close_button)
        layout.addWidget(self.tabwidget)

        # Find/replace widget
        self.find_widget = FindReplace(self)
        self.find_widget.hide()
        layout.addWidget(self.find_widget)

        self.setLayout(layout)

        # Accepting drops
        self.setAcceptDrops(True)
Esempio n. 52
0
 def new_folder(self):
     """Create a new folder"""
     datalist = [
         (translate('Explorer', 'Folder name'), ''),
         (translate('Explorer', 'Python package'), False),
     ]
     answer = fedit(datalist,
                    title=translate('Explorer', "New folder"),
                    parent=self,
                    icon=get_icon('spyder.svg'))
     if answer is not None:
         dirname, pack = answer
         dirname = osp.join(self.get_dirname(), dirname)
         try:
             os.mkdir(dirname)
         except EnvironmentError, error:
             QMessageBox.critical(self,
                 translate('Explorer', "New folder"),
                 translate('Explorer',
                           "<b>Unable to create folder <i>%1</i></b>"
                           "<br><br>Error message:<br>%2") \
                 .arg(dirname).arg(str(error)))
         finally:
Esempio n. 53
0
    def __init__(self, parent):
        self.tabwidget = None
        self.menu_actions = None
        self.dockviewer = None

        self.editors = []
        self.filenames = []
        self.icons = []

        PluginWidget.__init__(self, parent)

        layout = QVBoxLayout()
        self.tabwidget = Tabs(self, self.menu_actions)
        self.connect(self.tabwidget, SIGNAL('currentChanged(int)'),
                     self.refresh)
        self.connect(self.tabwidget, SIGNAL("close_tab(int)"),
                     self.tabwidget.removeTab)
        self.connect(self.tabwidget, SIGNAL('move_data(int,int)'),
                     self.move_tab)
        layout.addWidget(self.tabwidget)

        # Menu as corner widget
        options_button = create_toolbutton(self,
                                           text=self.tr("Options"),
                                           icon=get_icon('tooloptions.png'))
        options_button.setPopupMode(QToolButton.InstantPopup)
        menu = QMenu(self)
        add_actions(menu, self.menu_actions)
        options_button.setMenu(menu)
        self.tabwidget.setCornerWidget(options_button)

        # Find/replace widget
        self.find_widget = FindReplace(self)
        self.find_widget.hide()
        layout.addWidget(self.find_widget)

        self.setLayout(layout)
Esempio n. 54
0
 def setup_menu(self, truncate, minmax, inplace, collvalue):
     """Setup context menu"""
     self.edit_action = create_action(self,
                                      translate("DictEditor", "Edit"),
                                      icon=get_icon('edit.png'),
                                      triggered=self.edit_item)
     self.plot_action = create_action(self,
                                      translate("DictEditor", "Plot"),
                                      icon=get_icon('plot.png'),
                                      triggered=self.plot_item)
     self.plot_action.setVisible(False)
     self.imshow_action = create_action(self,
                                        translate("DictEditor",
                                                  "Show image"),
                                        icon=get_icon('imshow.png'),
                                        triggered=self.imshow_item)
     self.imshow_action.setVisible(False)
     self.save_array_action = create_action(self,
                                            translate(
                                                "DictEditor", "Save array"),
                                            icon=get_icon('filesave.png'),
                                            triggered=self.save_array)
     self.save_array_action.setVisible(False)
     self.insert_action = create_action(self,
                                        translate("DictEditor", "Insert"),
                                        icon=get_icon('insert.png'),
                                        triggered=self.insert_item)
     self.remove_action = create_action(self,
                                        translate("DictEditor", "Remove"),
                                        icon=get_icon('editdelete.png'),
                                        triggered=self.remove_item)
     self.truncate_action = create_action(self,
                                          translate("DictEditor",
                                                    "Truncate values"),
                                          toggled=self.toggle_truncate)
     self.truncate_action.setChecked(truncate)
     self.toggle_truncate(truncate)
     self.minmax_action = create_action(self,
                                        translate("DictEditor",
                                                  "Show arrays min/max"),
                                        toggled=self.toggle_minmax)
     self.minmax_action.setChecked(minmax)
     self.toggle_minmax(minmax)
     self.collvalue_action = create_action(self,
                                           translate(
                                               "DictEditor",
                                               "Show collection contents"),
                                           toggled=self.toggle_collvalue)
     self.collvalue_action.setChecked(collvalue)
     self.toggle_collvalue(collvalue)
     self.inplace_action = create_action(self,
                                         translate("DictEditor",
                                                   "Always edit in-place"),
                                         toggled=self.toggle_inplace)
     self.inplace_action.setChecked(inplace)
     if self.delegate is None:
         self.inplace_action.setEnabled(False)
     else:
         self.toggle_inplace(inplace)
     self.rename_action = create_action(self,
                                        translate("DictEditor", "Rename"),
                                        icon=get_icon('rename.png'),
                                        triggered=self.rename_item)
     self.duplicate_action = create_action(self,
                                           translate(
                                               "DictEditor", "Duplicate"),
                                           icon=get_icon('edit_add.png'),
                                           triggered=self.duplicate_item)
     menu = QMenu(self)
     menu_actions = [
         self.edit_action, self.plot_action, self.imshow_action,
         self.save_array_action, self.insert_action, self.remove_action,
         None, self.rename_action, self.duplicate_action, None,
         self.truncate_action, self.inplace_action, self.collvalue_action
     ]
     if ndarray is not FakeObject:
         menu_actions.append(self.minmax_action)
     add_actions(menu, menu_actions)
     return menu
Esempio n. 55
0
    def __init__(self, parent, max_entries=100):
        QWidget.__init__(self, parent)

        self.output = None
        self.error_output = None

        self.max_entries = max_entries
        self.data = [self.VERSION]
        if osp.isfile(self.DATAPATH):
            try:
                data = cPickle.load(file(self.DATAPATH))
                if data[0] == self.VERSION:
                    self.data = data
            except EOFError:
                pass

        self.filecombo = PythonModulesComboBox(self)
        if self.data:
            self.remove_obsolete_items()
            self.filecombo.addItems(self.get_filenames())

        self.start_button = create_toolbutton(self,
                                              get_icon('run.png'),
                                              translate('Pylint', "Analyze"),
                                              tip=translate(
                                                  'Pylint', "Run analysis"),
                                              triggered=self.start)
        self.stop_button = create_toolbutton(self,
                                             get_icon('terminate.png'),
                                             translate('Pylint', "Stop"),
                                             tip=translate(
                                                 'Pylint',
                                                 "Stop current analysis"))
        self.connect(self.filecombo, SIGNAL('valid(bool)'),
                     self.start_button.setEnabled)
        self.connect(self.filecombo, SIGNAL('valid(bool)'), self.show_data)

        browse_button = create_toolbutton(self,
                                          get_icon('fileopen.png'),
                                          tip=translate(
                                              'Pylint',
                                              'Select Python script'),
                                          triggered=self.select_file)

        self.ratelabel = QLabel()
        self.datelabel = QLabel()
        self.log_button = create_toolbutton(self,
                                            get_icon('log.png'),
                                            translate('Pylint', "Output"),
                                            tip=translate(
                                                'Pylint',
                                                "Complete Pylint output"),
                                            triggered=self.show_log)
        self.treewidget = ResultsTree(self)

        hlayout1 = QHBoxLayout()
        hlayout1.addWidget(self.filecombo)
        hlayout1.addWidget(browse_button)
        hlayout1.addWidget(self.start_button)
        hlayout1.addWidget(self.stop_button)

        hlayout2 = QHBoxLayout()
        hlayout2.addWidget(self.ratelabel)
        hlayout2.addStretch()
        hlayout2.addWidget(self.datelabel)
        hlayout2.addStretch()
        hlayout2.addWidget(self.log_button)

        layout = QVBoxLayout()
        layout.addLayout(hlayout1)
        layout.addLayout(hlayout2)
        layout.addWidget(self.treewidget)
        self.setLayout(layout)

        self.process = None
        self.set_running_state(False)

        if not is_pylint_installed():
            for widget in (self.treewidget, self.filecombo, self.start_button,
                           self.stop_button):
                widget.setDisabled(True)
            text = translate('Pylint', 'Please install <b>pylint</b>:')
            url = 'http://www.logilab.fr'
            text += ' <a href=%s>%s</a>' % (url, url)
            self.ratelabel.setText(text)
        else:
            self.show_data()
Esempio n. 56
0
    def setup_toolbar(self, layout):
        toolbar = []

        explorer_label = QLabel(
            self.tr("<span style=\'color: #444444\'>"
                    "<b>Global variables explorer</b>"
                    "</span>"))
        toolbar.append(explorer_label)

        hide_button = create_toolbutton(self,
                                        text=self.tr("Hide"),
                                        icon=get_icon('hide.png'),
                                        triggered=self.collapse)
        toolbar.append(hide_button)

        refresh_button = create_toolbutton(self,
                                           text=self.tr("Refresh"),
                                           icon=get_icon('reload.png'),
                                           triggered=self.refresh_table)
        toolbar.append(refresh_button)

        exclude_private_action = create_action(
            self,
            self.tr("Exclude private references"),
            tip=self.tr("Exclude references which name starts"
                        " with an underscore"),
            toggled=lambda state: self.emit(SIGNAL('option_changed'),
                                            'exclude_private', state))
        exclude_private_action.setChecked(CONF.get(self.ID, 'exclude_private'))

        exclude_upper_action = create_action(
            self,
            self.tr("Exclude capitalized references"),
            tip=self.tr("Exclude references which name starts with an "
                        "upper-case character"),
            toggled=lambda state: self.emit(SIGNAL('option_changed'),
                                            'exclude_upper', state))
        exclude_upper_action.setChecked(CONF.get(self.ID, 'exclude_upper'))

        exclude_unsupported_action = create_action(
            self,
            self.tr("Exclude unsupported data types"),
            tip=self.tr("Exclude references to unsupported data types"
                        " (i.e. which won't be handled/saved correctly)"),
            toggled=lambda state: self.emit(SIGNAL('option_changed'),
                                            'exclude_unsupported', state))
        exclude_unsupported_action.setChecked(
            CONF.get(self.ID, 'exclude_unsupported'))

        options_button = create_toolbutton(self,
                                           text=self.tr("Options"),
                                           icon=get_icon('tooloptions.png'))
        toolbar.append(options_button)
        options_button.setPopupMode(QToolButton.InstantPopup)
        menu = QMenu(self)
        editor = self.editor
        actions = [
            exclude_private_action, exclude_upper_action,
            exclude_unsupported_action, None, editor.truncate_action,
            editor.inplace_action, editor.collvalue_action
        ]
        try:
            imp.find_module('numpy')
            actions.append(editor.minmax_action)
        except ImportError:
            pass
        add_actions(menu, actions)
        options_button.setMenu(menu)

        layout.setAlignment(Qt.AlignLeft)
        for widget in toolbar:
            layout.addWidget(widget)
        layout.insertStretch(1, 1)
Esempio n. 57
0
    def __init__(self,
                 parent=None,
                 path=None,
                 name_filters=['*.py', '*.pyw'],
                 valid_types=('.py', '.pyw'),
                 show_all=False,
                 show_toolbar=True,
                 show_icontext=True):
        QWidget.__init__(self, parent)

        self.treewidget = ExplorerTreeWidget(self)
        self.treewidget.setup(path=path,
                              name_filters=name_filters,
                              valid_types=valid_types,
                              show_all=show_all)

        toolbar_action = create_action(self,
                                       translate('Explorer', "Show toolbar"),
                                       toggled=self.toggle_toolbar)
        icontext_action = create_action(self,
                                        translate('Explorer',
                                                  "Show icons and text"),
                                        toggled=self.toggle_icontext)
        self.treewidget.common_actions += [
            None, toolbar_action, icontext_action
        ]

        # Setup toolbar
        self.toolbar = QToolBar(self)
        self.toolbar.setIconSize(QSize(16, 16))

        self.previous_action = create_action(
            self,
            text=translate('Explorer', "Previous"),
            icon=get_icon('previous.png'),
            triggered=lambda: self.emit(SIGNAL("open_previous_dir()")))
        self.toolbar.addAction(self.previous_action)
        self.previous_action.setEnabled(False)

        self.next_action = create_action(
            self,
            text=translate('Explorer', "Next"),
            icon=get_icon('next.png'),
            triggered=lambda: self.emit(SIGNAL("open_next_dir()")))
        self.toolbar.addAction(self.next_action)
        self.next_action.setEnabled(False)

        parent_action = create_action(
            self,
            text=translate('Explorer', "Parent"),
            icon=get_icon('up.png'),
            triggered=lambda: self.emit(SIGNAL("open_parent_dir()")))
        self.toolbar.addAction(parent_action)

        refresh_action = create_action(
            self,
            text=translate('Explorer', "Refresh"),
            icon=get_icon('reload.png'),
            triggered=self.treewidget.refresh_whole_model)
        self.toolbar.addAction(refresh_action)

        options_action = create_action(self,
                                       text=translate('Explorer', "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)

        toolbar_action.setChecked(show_toolbar)
        self.toggle_toolbar(show_toolbar)
        icontext_action.setChecked(show_icontext)
        self.toggle_icontext(show_icontext)

        vlayout = QVBoxLayout()
        vlayout.addWidget(self.toolbar)
        vlayout.addWidget(self.treewidget)
        self.setLayout(vlayout)