Example #1
0
 def onLanguageChange(self):
     languageName = self._langBox.currentText()        
     if pyzo.config.settings.language == languageName:
         return
     # Save new language
     pyzo.config.settings.language = languageName
     setLanguage(pyzo.config.settings.language)
     # Notify user
     text = translate('wizard', """
     The language has been changed for this wizard.
     Pyzo needs to restart for the change to take effect application-wide.
     """)
     m = QtWidgets.QMessageBox(self)
     m.setWindowTitle(translate("wizard", "Language changed"))
     m.setText(text)
     m.setIcon(m.Information)
     m.exec_()
     
     # Get props of current wizard
     geo = self.wizard().geometry()
     parent = self.wizard().parent()
     # Close ourself!        
     self.wizard().close()
     # Start new one
     w = PyzoWizard(parent)
     w.setGeometry(geo)
     w.show()
Example #2
0
    def buildMenu(self):
        menu = self._menu
        menu.clear()
        
        # Add action to remove bookmark
        action = menu.addAction(translate('filebrowser', 'Remove project'))
        action._id = 'remove'
        action.setCheckable(False)
        
        # Add action to change name
        action = menu.addAction(translate('filebrowser', 'Change project name'))
        action._id = 'name'
        action.setCheckable(False)
        
        menu.addSeparator()
        
        # Add check action for adding to Pythonpath
        action = menu.addAction(translate('filebrowser', 'Add path to Python path'))
        action._id = 'pythonpath'
        action.setCheckable(True)
        d = self.currentDict()
        if d:
            checked = bool( d and d['addToPythonpath'] )
            action.setChecked(checked)

        # Add action to cd to the project directory
        action = menu.addAction(translate('filebrowser', 'Go to this directory in the current shell'))
        action._id = 'cd'
        action.setCheckable(False)
Example #3
0
    def __init__(self):
        QtWidgets.QWizardPage.__init__(self)
        
        self.setTitle(translate('importwizard', 'Select file'))
        
        self.txtFilename = QtWidgets.QLineEdit()
        self.btnBrowse = QtWidgets.QPushButton(translate('importwizard', 'Browse...'))
        self.preview = QtWidgets.QPlainTextEdit()
        self.preview.setReadOnly(True)

        vlayout = QtWidgets.QVBoxLayout()
        hlayout = QtWidgets.QHBoxLayout()

        
        hlayout.addWidget(self.txtFilename)
        hlayout.addWidget(self.btnBrowse)
        vlayout.addLayout(hlayout)
        vlayout.addWidget(QtWidgets.QLabel(translate('importwizard', 'Preview:')))
        vlayout.addWidget(self.preview)
        
        self.setLayout(vlayout)
        
        self.registerField('fname', self.txtFilename)
        
        self.btnBrowse.clicked.connect(self.onBrowseClicked)
        self.txtFilename.editingFinished.connect(self.updatePreview)
        self._isComplete = False
Example #4
0
 def _duplicateOrRename(self, rename):
     
     # Get dirname and filename
     dirname, filename = os.path.split(self._item.path())
     
     # Get title and label
     if rename:
         title = translate("filebrowser", "Rename")
         label = translate("filebrowser", "Give the new name for the file")
     else:
         title = translate("filebrowser", "Duplicate")
         label = translate("filebrowser", "Give the name for the new file")
         filename = 'Copy of ' + filename
     
     # Ask for new filename
     s = QtGui.QInputDialog.getText(self.parent(), title,
                 label + ':\n%s' % self._item.path(),
                 QtGui.QLineEdit.Normal,
                 filename
             )
     if isinstance(s, tuple):
         s = s[0] if s[1] else ''
     
     # Push rename task
     if s:
         newpath = os.path.join(dirname, s)
         task = tasks.RenameTask(newpath=newpath, removeold=rename)
         self._item._proxy.pushTask(task)
Example #5
0
    def buildMenu(self):
        menu = self._menu
        menu.clear()

        # Add action to remove bookmark
        action = menu.addAction(translate("filebrowser", "Remove project"))
        action._id = "remove"
        action.setCheckable(False)

        # Add action to change name
        action = menu.addAction(translate("filebrowser", "Change project name"))
        action._id = "name"
        action.setCheckable(False)

        menu.addSeparator()

        # Add check action for adding to Pythonpath
        action = menu.addAction(translate("filebrowser", "Add path to Python path"))
        action._id = "pythonpath"
        action.setCheckable(True)
        d = self.currentDict()
        if d:
            checked = bool(d and d["addToPythonpath"])
            action.setChecked(checked)

        # Add action to cd to the project directory
        action = menu.addAction(translate("filebrowser", "Go to this directory in the current shell"))
        action._id = "cd"
        action.setCheckable(False)
Example #6
0
    def onMenuTriggered(self, action):
        d = self.currentDict()
        if not d:
            return

        if action._id == "remove":
            # Remove this project
            self.parent().removeStarredDir(d.path)

        elif action._id == "name":
            # Open dialog to ask for name
            name = QtGui.QInputDialog.getText(
                self.parent(),
                translate("filebrowser", "Project name"),
                translate("filebrowser", "New project name:"),
                text=d["name"],
            )
            if isinstance(name, tuple):
                name = name[0] if name[1] else ""
            if name:
                d["name"] = name
            self.updateProjectList()

        elif action._id == "pythonpath":
            # Flip add-to-pythonpath flag
            d["addToPythonpath"] = not d["addToPythonpath"]

        elif action._id == "cd":
            # cd to the directory
            shell = pyzo.shells.getCurrentShell()
            if shell:
                shell.executeCommand("cd " + d.path + "\n")
Example #7
0
 def __init__(self, parent, distro=None):
     QtWidgets.QWidget.__init__(self, parent)
     self.setMinimumSize(360, 256)  # Ensure title fits nicely
     
     # Create label widget and costumize
     self._label = QtWidgets.QLabel(self)
     self._label.setTextFormat(QtCore.Qt.RichText)
     self._label.setOpenExternalLinks(True)
     self._label.setWordWrap(True)
     self._label.setMargin(20)
     
     # Set font size (absolute value)
     font = self._label.font()
     font.setPointSize(11)  #(font.pointSize()+1)
     self._label.setFont(font)
     
     # Build
     text_title = translate('splash', 'This is <b>Pyzo</b><br />the Python IDE for scientific computing')
     text_version = translate('splash', 'Version')
     text_os = translate('splash', 'Pyzo is open source software and freely available for everyone.')
     text = splash_text.format(version=pyzo.__version__,
                               text_title=text_title, text_version=text_version, text_os=text_os)
     
     # Set text
     self._label.setText(text)
     
     layout = QtWidgets.QVBoxLayout(self)
     self.setLayout(layout)
     layout.addStretch(1)
     layout.addWidget(self._label, 0)
     layout.addStretch(1)
Example #8
0
 def onMenuTriggered(self, action):
     d = self.currentDict()
     if not d:
         return
     
     if action._id == 'remove':
         # Remove this project
         self.parent().removeStarredDir(d.path)
     
     elif action._id == 'name':
         # Open dialog to ask for name
         name = QtWidgets.QInputDialog.getText(self.parent(),
                             translate('filebrowser', 'Project name'),
                             translate('filebrowser', 'New project name:'),
                             text=d['name'],
                         )
         if isinstance(name, tuple):
             name = name[0] if name[1] else ''
         if name:
             d['name'] = name
         self.updateProjectList()
     
     elif action._id == 'pythonpath':
         # Flip add-to-pythonpath flag
         d['addToPythonpath'] = not d['addToPythonpath']
 
     elif action._id == 'cd':
         # cd to the directory
         shell = pyzo.shells.getCurrentShell()
         if shell:
             shell.executeCommand('cd '+d.path+'\n')
Example #9
0
 def onBtnExecuteClicked(self):
     shell = pyzo.shells.getCurrentShell()
     if shell is None:
         QtWidgets.QMessageBox.information(self, 
             translate('importwizard', 'Import data wizard'),
             translate('importwizard', 'No current shell active'))
         return
         
     shell.executeCode(self.getCode(), 'importwizard')
Example #10
0
    def open(self, filename):
        if self.isVisible():
            QtWidgets.QMessageBox.information(self, 
                translate('importwizard', 'Import data wizard'),
                translate('importwizard', 'The import data wizard is already open'))
            return

        self.restart()
        self.selectFilePage.txtFilename.setText(filename)
        self.selectFilePage.updatePreview()
        self.show()
Example #11
0
 def onDelete(self):
     # Ask for new filename
     b = QtGui.QMessageBox.question(self.parent(), 
                 translate("filebrowser", "Delete"), 
                 translate("filebrowser", "Are you sure that you want to delete") + 
                 ':\n%s' % self._item.path(),
                 QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
             )       
     # Push delete task
     if b is QtGui.QMessageBox.Yes:            
         self._item._proxy.pushTask(tasks.RemoveTask())
Example #12
0
 def __init__(self, parent = None):
     super().__init__(parent)
     
     # Widgets
     self._search = QtWidgets.QLineEdit(self)
     self._list = QtWidgets.QListWidget(self)
     
     # Set monospace
     font = self._list.font()
     font.setFamily(pyzo.config.view.fontname)
     self._list.setFont(font)
     
     # Layout
     layout = QtWidgets.QVBoxLayout(self)
     self.setLayout(layout)
     layout.addWidget(self._search, 0)
     layout.addWidget(self._list, 1)
     
     # Customize line edit
     self._search.setPlaceholderText(translate('menu', 'Search'))
     self._search.textChanged.connect(self._on_search)
     
     # Drag/drop
     self._list.setSelectionMode(self._list.ExtendedSelection)
     self._list.setDragEnabled(True)
     self._list.doubleClicked.connect(self._onDoubleClicked)
     
     # Context menu
     self._menu = Menu(self, translate("menu", "History"))
     self._menu.addItem(translate("menu", "Copy ::: Copy selected lines"),
         pyzo.icons.page_white_copy, self.copy, "copy")
     self._menu.addItem(translate("menu", "Run ::: Run selected lines in current shell"),
         pyzo.icons.run_lines, self.runSelection, "run")
     self._menu.addItem(translate("menu", "Remove ::: Remove selected history items(s)"),
         pyzo.icons.delete, self.removeSelection, "remove")
     
     self._list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self._list.customContextMenuRequested.connect(self._onCustomContextMenuRequested)
     
     # Populate
     for command in pyzo.command_history.get_commands():
         self._list.addItem(command)
     
     # Scroll to end of list on start up
     self._list.setCurrentRow(self._list.count()-1)
     item = self._list.currentItem()
     self._list.scrollToItem(item)
     
     # Keep up to date ...
     pyzo.command_history.command_added.connect(self._on_command_added)
     pyzo.command_history.command_removed.connect(self._on_command_removed)
     pyzo.command_history.commands_reset.connect(self._on_commands_reset)
Example #13
0
 def updateProjectList(self):
     # Get sorted version of starredDirs
     starredDirs = self.parent().starredDirs
     starredDirs.sort(key=lambda p:self.parent().dictForStarredDir(p).name.lower())
     # Refill the combo box
     self._combo.clear()
     if starredDirs:
         self._combo.addItem(translate('filebrowser', 'Projects:'), '') # No-project item
         for p in starredDirs:
             name = self.parent().dictForStarredDir(p).name
             self._combo.addItem(name, p)
     else:
         self._combo.addItem(
             translate('filebrowser', 'Click star to bookmark current dir'), '')
Example #14
0
 def updateProjectList(self):
     # Get sorted version of starredDirs
     starredDirs = self.parent().starredDirs
     starredDirs.sort(key=lambda p: p.lower())
     # Refill the combo box
     self._combo.clear()
     for p in starredDirs:
         name = self.parent().dictForStarredDir(p).name
         self._combo.addItem(name, p)
     # Insert dummy item
     if starredDirs:
         self._combo.insertItem(0, translate("filebrowser", "Projects:"), "")  # No-project item
     else:
         self._combo.addItem(translate("filebrowser", "Click star to bookmark current dir"), "")
Example #15
0
 def __init__(self, parent):
     # Do not pass parent, because is a sublayout
     QtWidgets.QVBoxLayout.__init__(self)
     
     # Create sub-widget
     self._edit1 = QtWidgets.QLineEdit(parent)
     self._edit1.textEdited.connect(self.onEditChanged)
     if sys.platform.startswith('win'):
         self._edit1.setPlaceholderText('C:\\path\\to\\script.py')
     else:
         self._edit1.setPlaceholderText('/path/to/script.py')
     #
     self._edit2 = QtWidgets.QTextEdit(parent)
     self._edit2.zoomOut(1)
     self._edit2.setMaximumHeight(80)
     self._edit2.setMinimumWidth(200)
     self._edit2.textChanged.connect(self.onEditChanged)
     
     # Layout
     self.setSpacing(1)
     self.addWidget(self._edit1)
     self.addWidget(self._edit2)
     
     # Create radio widget for system default
     t = translate('shell', 'Use system default')
     self._radio_system = QtWidgets.QRadioButton(t, parent)
     self._radio_system.toggled.connect(self.onCheckChanged)
     self.addWidget(self._radio_system)
     if self.DISABLE_SYSTEM_DEFAULT:
         self._radio_system.hide()
     
     # Create radio widget for file
     t = translate('shell', 'File to run at startup')
     self._radio_file = QtWidgets.QRadioButton(t, parent)
     self._radio_file.toggled.connect(self.onCheckChanged)
     self.addWidget(self._radio_file)
     
     # Create radio widget for code
     t = translate('shell', 'Code to run at startup')
     self._radio_code = QtWidgets.QRadioButton(t, parent)
     self._radio_code.toggled.connect(self.onCheckChanged)
     self.addWidget(self._radio_code)
     
     # The actual value of this shell config attribute
     self._value = ''
     
     # A buffered version, so that clicking the text box does not
     # remove the value at once
     self._valueFile = ''
     self._valueCode = '\n'
Example #16
0
 def __init__(self, parent, config, path=None):
     QtWidgets.QWidget.__init__(self, parent)
     
     # Store config
     self.config = config
     
     # Create star button
     self._projects = Projects(self)
     
     # Create path input/display lineEdit
     self._pathEdit = PathInput(self)
     
     # Create file system proxy
     self._fsProxy = proxies.NativeFSProxy()
     self.destroyed.connect(self._fsProxy.stop)
     
     # Create tree widget
     self._tree = Tree(self)
     self._tree.setPath(cleanpath(self.config.path))
     
     # Create name filter
     self._nameFilter = NameFilter(self)
     #self._nameFilter.lineEdit().setToolTip('File filter pattern')
     self._nameFilter.setToolTip(translate('filebrowser', 'Filename filter'))
     self._nameFilter.setPlaceholderText(self._nameFilter.toolTip())
     
     # Create search filter
     self._searchFilter = SearchFilter(self)
     self._searchFilter.setToolTip(translate('filebrowser', 'Search in files'))
     self._searchFilter.setPlaceholderText(self._searchFilter.toolTip())
     
     # Signals to sync path.
     # Widgets that can change the path transmit signal to _tree
     self._pathEdit.dirUp.connect(self._tree.setFocus)
     self._pathEdit.dirUp.connect(self._tree.setPathUp)
     self._pathEdit.dirChanged.connect(self._tree.setPath)
     self._projects.dirChanged.connect(self._tree.setPath)
     #
     self._nameFilter.filterChanged.connect(self._tree.onChanged) # == update
     self._searchFilter.filterChanged.connect(self._tree.onChanged)
     # The tree transmits signals to widgets that need to know the path
     self._tree.dirChanged.connect(self._pathEdit.setPath)
     self._tree.dirChanged.connect(self._projects.setPath)
     
     self._layout()
     
     # Set and sync path ...
     if path is not None:
         self._tree.SetPath(path)
     self._tree.dirChanged.emit(self._tree.path())
Example #17
0
 def __init__(self, fname):
     super().__init__()
     
     self._file = None
     
     try:
         filename = os.path.join(pyzo.appDataDir, fname)
         if not os.path.isfile(filename):
             open(filename, 'wt').close()
         file = self._file = open(filename, 'r+', encoding = 'utf-8')
     
         # Truncate the file to my max number of lines
         lines = file.readlines()
         if len(lines) > self.maxLines:
             lines = lines[-self.maxLines:]
             
             # move to start of file, write the last lines and truncate
             file.seek(0)
             file.writelines(lines)
             file.truncate()
         
         # Move to the end of the file for appending
         file.seek(0, 2) # 2 = relative to end
         
         self.setStringList([line.rstrip() for line in lines])
         
     except Exception as e:
         print (translate('pyzoHistoryViewer', 'An error occurred while loading the history: ' + str(e)))
         self._file = None
     
     # When data is appended for the first time, a marker will be appended first
     self._firstTime = True
Example #18
0
def retranslate(t):
    """ To allow retranslating after selecting the language.
    """
    if hasattr(t, 'original'):
        return translate('wizard', t.original)
    else:        
        return t
Example #19
0
 def __init__(self, parent):
     QtWidgets.QWizard.__init__(self, parent)
     
     # Set some appearance stuff
     self.setMinimumSize(600, 500)
     self.setWindowTitle(translate('wizard', 'Getting started with Pyzo'))
     self.setWizardStyle(self.ModernStyle)
     self.setButtonText(self.CancelButton, 'Stop')
     
     # Set logo
     pm = QtGui.QPixmap()
     pm.load(os.path.join(pyzo.pyzoDir, 'resources', 'appicons', 'pyzologo48.png'))
     self.setPixmap(self.LogoPixmap, pm)
     
     # Define pages
     klasses = [ IntroWizardPage, 
                 TwocomponentsWizardPage, EditorWizardPage, 
                 ShellWizardPage1, ShellWizardPage2,
                 RuncodeWizardPage1, RuncodeWizardPage2, 
                 ToolsWizardPage1, ToolsWizardPage2,
                 FinalPage]
     
     # Create pages
     self._n = len(klasses)        
     for i, klass in enumerate(klasses):
         self.addPage(klass(self, i))
Example #20
0
 def __init__(self, parent = None):
     super().__init__(parent)
     
     # Drag/drop
     self.setSelectionMode(self.ExtendedSelection)
     self.setDragEnabled(True)
     
     # Double click
     self.doubleClicked.connect(self._onDoubleClicked)
     
     # Context menu
     self._menu = Menu(self, translate("menu", "History"))
     self._menu.addItem(translate("menu", "Copy ::: Copy selected lines"),
         pyzo.icons.page_white_copy, self.copy, "copy")
     self._menu.addItem(translate("menu", "Run ::: Run selected lines in current shell"),
         pyzo.icons.run_lines, self.runSelection, "run")
     
     self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self.customContextMenuRequested.connect(self._onCustomContextMenuRequested)
Example #21
0
 def onBtnInsertClicked(self):
     editor = pyzo.editors.getCurrentEditor()
     if editor is None:
         QtWidgets.QMessageBox.information(self, 
             translate('importwizard', 'Import data wizard'),
             translate('importwizard', 'No current file open'))
         return
     
     code = self.getCode()
     
     # Format tabs/spaces according to editor setting
     if editor.indentUsingSpaces():
         code = code.replace('\t', ' ' * editor.indentWidth())
     
     
     # insert code at start of line
     cursor = editor.textCursor()
     cursor.movePosition(cursor.StartOfBlock)
     cursor.insertText(code)
Example #22
0
 def __init__(self, parent, i):
     BasePyzoWizardPage.__init__(self, parent, i)
     
     # Create label and checkbox
     t1 = translate('wizard', "This wizard can be opened using 'Help > Pyzo wizard'")
     t2 = translate('wizard', "Show this wizard on startup")
     self._label_info = QtWidgets.QLabel(t1, self)
     #self._check_show = QtWidgets.QCheckBox(t2, self)
     #self._check_show.stateChanged.connect(self._setNewUser)
     
     # Create language switcher
     self._langLabel = QtWidgets.QLabel(translate('wizard', "Select language"), self)
     #
     self._langBox = QtWidgets.QComboBox(self)
     self._langBox.setEditable(False)
     # Fill
     index, theIndex = -1, -1
     cur = pyzo.config.settings.language
     for lang in sorted(LANGUAGES):
         index += 1
         self._langBox.addItem(lang)
         if lang == LANGUAGE_SYNONYMS.get(cur, cur):
             theIndex = index
     # Set current index
     if theIndex >= 0:
         self._langBox.setCurrentIndex(theIndex)
     # Bind signal
     self._langBox.activated.connect(self.onLanguageChange)
     
     # Init check state
     #if pyzo.config.state.newUser:
     #    self._check_show.setCheckState(QtCore.Qt.Checked)
     
     # Create sublayout
     layout = QtWidgets.QHBoxLayout()
     layout.addWidget(self._langLabel, 0)
     layout.addWidget(self._langBox, 0)
     layout.addStretch(2)
     self.layout().addLayout(layout)
     
     # Add to layout
     self.layout().addSpacing(10)
     self.layout().addWidget(self._label_info)
Example #23
0
 def _runNotebook(self):
     filename = self._item.path()
     shell = pyzo.shells.getCurrentShell()
     if shell is not None:
         shell.restart(filename)
     else:
         msg = "No shell to run notebook in. "
         m = QtGui.QMessageBox(self)
         m.setWindowTitle(translate("menu dialog", "Could not run notebook"))
         m.setText("Could not run " + filename + ":\n\n" + msg)
         m.setIcon(m.Warning)
         m.exec_()
Example #24
0
 def __init__(self, parent):
     QtGui.QToolButton.__init__(self, parent)
     
     # Set text and tooltip
     self._baseText = translate('debug', 'Stack')
     self.setText('%s:' % self._baseText)
     self.setIcon(pyzo.icons.text_align_justify)
     self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
     self.setPopupMode(self.InstantPopup)
     
     # Bind to triggers
     self.triggered.connect(self.onTriggered)
Example #25
0
File: tree.py Project: pyzo/pyzo
    def _createDirOrFile(self, file=True):

        # Get title and label
        if file:
            title = translate("filebrowser", "Create new file")
            label = translate("filebrowser", "Give the new name for the file")
        else:
            title = translate("filebrowser", "Create new directory")
            label = translate("filebrowser", "Give the name for the new directory")

        # Ask for new filename
        s = QtWidgets.QInputDialog.getText(
            self.parent(), title, label + ":\n%s" % self._item.path(), QtWidgets.QLineEdit.Normal, "new name"
        )
        if isinstance(s, tuple):
            s = s[0] if s[1] else ""

        # Push rename task
        if s:
            newpath = op.join(self._item.path(), s)
            task = tasks.CreateTask(newpath=newpath, file=file)
            self._item._proxy.pushTask(task)
Example #26
0
    def __init__(self):
        QtWidgets.QWizardPage.__init__(self)
        self.setTitle("Execute import")
        self.setButtonText(QtWidgets.QWizard.FinishButton, 
            translate('importwizard', 'Close'))

        self.rbAsArray = QtWidgets.QRadioButton(translate('importwizard', 'Import data as single array'))
        self.rbPerColumn = QtWidgets.QRadioButton(translate('importwizard', 'Import data into one variable per column'))
        self.rbAsArray.setChecked(True)

        self.chkInvalidRaise = QtWidgets.QCheckBox(translate('importwizard', 'Raise error upon invalid data'))
        self.chkInvalidRaise.setChecked(True)

        self.codeView = CodeView()
        self.codeView.setParser('python')
        self.codeView.setZoom(pyzo.config.view.zoom)
        self.codeView.setFont(pyzo.config.view.fontname)
        
        self.btnExecute = QtWidgets.QPushButton('Execute in current shell')
        self.btnInsert = QtWidgets.QPushButton('Paste into current file')
        
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.rbAsArray)
        layout.addWidget(self.rbPerColumn)
        layout.addWidget(self.chkInvalidRaise)
        
        layout.addWidget(QtWidgets.QLabel('Resulting import code:'))
        layout.addWidget(self.codeView)
        layout.addWidget(self.btnExecute)
        layout.addWidget(self.btnInsert)  
        self.setLayout(layout)   
        
        self.registerField('invalid_raise', self.chkInvalidRaise)
        
        self.btnExecute.clicked.connect(self.onBtnExecuteClicked)
        self.btnInsert.clicked.connect(self.onBtnInsertClicked)
        self.rbAsArray.clicked.connect(self.updateCode)
        self.rbPerColumn.clicked.connect(self.updateCode)
        self.chkInvalidRaise.stateChanged.connect(lambda state: self.updateCode())
Example #27
0
 def __init__(self, parent):
     QtWidgets.QScrollArea.__init__(self, parent)
     
     # Init the scroll area
     self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
     self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
     self.setWidgetResizable(True)
     self.setFrameShape(QtWidgets.QFrame.NoFrame)
     
     # Create widget and a layout
     self._content = QtWidgets.QWidget(parent)
     self._formLayout = QtWidgets.QFormLayout(self._content)
     
     # Collect classes of widgets to instantiate
     classes = []
     for t in self.INFO_KEYS:
         className = 'ShellInfo_' + t.key
         cls = globals()[className]
         classes.append((t, cls))
     
     # Instantiate all classes
     self._shellInfoWidgets = {}
     for t, cls in classes:
         # Instantiate and store
         instance = cls(self._content)
         self._shellInfoWidgets[t.key] = instance
         # Create label
         label = QtWidgets.QLabel(t, self._content)
         label.setToolTip(t.tt)
         # Add to layout
         self._formLayout.addRow(label, instance)
     
     # Add delete button
     
     t = translate('shell', 'Delete ::: Delete this shell configuration')
     label = QtWidgets.QLabel('', self._content)
     instance = QtWidgets.QPushButton(pyzo.icons.cancel, t, self._content)
     instance.setToolTip(t.tt)
     instance.setAutoDefault(False)
     instance.clicked.connect(self.parent().parent().onTabClose)
     deleteLayout = QtWidgets.QHBoxLayout()
     deleteLayout.addWidget(instance, 0)
     deleteLayout.addStretch(1)
     # Add to layout
     self._formLayout.addRow(label, deleteLayout)
     
     # Apply layout
     self._formLayout.setSpacing(15)
     self._content.setLayout(self._formLayout)
     self.setWidget(self._content)
Example #28
0
 def buildMenu(self):
     config = self.parent().config
     menu = self._menu
     menu.clear()
     
     map = [ ('searchMatchCase', False, translate("filebrowser", "Match case")),
             ('searchRegExp', False, translate("filebrowser", "RegExp")),
             ('searchSubDirs', True, translate("filebrowser", "Search in subdirs"))
           ]
     
     # Fill menu
     for option, default, description in map:
         if option is None:
             menu.addSeparator()
         else:
             # Make sure the option exists
             if option not in config:
                 config[option] = default
             # Make action in menu
             action = menu.addAction(description)
             action._option = option
             action.setCheckable(True)
             action.setChecked( bool(config[option]) )
Example #29
0
    def __init__(self):
        QtWidgets.QWizardPage.__init__(self)
        
        self.setTitle("Select parameters")
    
        self._columnNames = None
        
        def genComboBox(choices):
            cbx = QtWidgets.QComboBox()
            for choice in choices:
                cbx.addItem(choice)
            cbx.setEditable(True)
            return cbx

        self.cbxDelimiter = genComboBox(",;")            
        self.cbxComments = genComboBox("#%'")
        self.sbSkipHeader = QtWidgets.QSpinBox()
        
        self.preview = QtWidgets.QTableWidget()
        self.preview.setSelectionModel(QtCore.QItemSelectionModel(self.preview.model())) # Work-around for reference tracking bug in PySide
        self.preview.setSelectionBehavior(self.preview.SelectColumns)
        self.preview.setSelectionMode(self.preview.MultiSelection)


        # Layout

        formlayout = QtWidgets.QFormLayout()       
        formlayout.addRow('Delimiter', self.cbxDelimiter)
        formlayout.addRow('Comments', self.cbxComments)
        formlayout.addRow('Header rows to skip', self.sbSkipHeader)
        
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(formlayout)
        layout.addWidget(QtWidgets.QLabel(
            translate('importwizard', 'Select columns to import:')))
        layout.addWidget(self.preview)

        self.setLayout(layout)
        
        # Wizard fields
        self.registerField('delimiter', self.cbxDelimiter, "currentText")
        self.registerField('comments', self.cbxComments, "currentText")
        self.registerField('skip_header', self.sbSkipHeader)
        
               
        # Signals
        self.cbxComments.editTextChanged.connect(self.updatePreview)
        self.cbxDelimiter.editTextChanged.connect(self.updatePreview)
        self.sbSkipHeader.valueChanged.connect(self.updatePreview)
        self.preview.verticalHeader().sectionClicked.connect(self.onRowHeaderClicked)
Example #30
0
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        self.setWindowTitle("Install miniconda")
        self.setModal(True)
        self.resize(500, 500)

        text = translate("bootstrapconda", "This will download and install miniconda on your computer.")

        self._label = QtWidgets.QLabel(text, self)

        self._scipystack = QtWidgets.QCheckBox(translate("bootstrapconda", "Also install scientific packages"), self)
        self._scipystack.setChecked(True)
        self._path = QtWidgets.QLineEdit(default_conda_dir, self)
        self._progress = QtWidgets.QProgressBar(self)
        self._outputLine = QtWidgets.QLabel(self)
        self._output = QtWidgets.QPlainTextEdit(self)
        self._output.setReadOnly(True)
        self._button = QtWidgets.QPushButton("Install", self)

        self._outputLine.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)

        vbox = QtWidgets.QVBoxLayout(self)
        self.setLayout(vbox)
        vbox.addWidget(self._label, 0)
        vbox.addWidget(self._path, 0)
        vbox.addWidget(self._scipystack, 0)
        vbox.addWidget(self._progress, 0)
        vbox.addWidget(self._outputLine, 0)
        vbox.addWidget(self._output, 1)
        vbox.addWidget(self._button, 0)

        self._button.clicked.connect(self.go)

        self.addOutput(translate("bootstrapconda", "Waiting to start installation.\n"))
        self._progress.setVisible(False)

        self.lineFromStdOut.connect(self.setStatus)
Example #31
0
class IntroWizardPage(BasePyzoWizardPage):
    
    _title = translate('wizard', 'Welcome to the Interactive Editor for Python!')
    _image_filename = 'pyzologo128.png'
    _descriptions = [
        translate('wizard', """This wizard helps you get familiarized with the workings of Pyzo."""),
        
        translate('wizard', """Pyzo is a cross-platform Python IDE
        focused on *interactivity* and *introspection*, which makes it
        very suitable for scientific computing. Its practical design
        is aimed at *simplicity* and *efficiency*."""),
        ]
    
    def __init__(self, parent, i):
        BasePyzoWizardPage.__init__(self, parent, i)
        
        # Create label and checkbox
        t1 = translate('wizard', "This wizard can be opened using 'Help > Pyzo wizard'")
        # t2 = translate('wizard', "Show this wizard on startup")
        self._label_info = QtWidgets.QLabel(t1, self)
        #self._check_show = QtWidgets.QCheckBox(t2, self)
        #self._check_show.stateChanged.connect(self._setNewUser)
        
        # Create language switcher
        self._langLabel = QtWidgets.QLabel(translate('wizard', "Select language"), self)
        #
        self._langBox = QtWidgets.QComboBox(self)
        self._langBox.setEditable(False)
        # Fill
        index, theIndex = -1, -1
        cur = pyzo.config.settings.language
        for lang in sorted(LANGUAGES):
            index += 1
            self._langBox.addItem(lang)
            if lang == LANGUAGE_SYNONYMS.get(cur, cur):
                theIndex = index
        # Set current index
        if theIndex >= 0:
            self._langBox.setCurrentIndex(theIndex)
        # Bind signal
        self._langBox.activated.connect(self.onLanguageChange)
        
        # Init check state
        #if pyzo.config.state.newUser:
        #    self._check_show.setCheckState(QtCore.Qt.Checked)
        
        # Create sublayout
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self._langLabel, 0)
        layout.addWidget(self._langBox, 0)
        layout.addStretch(2)
        self.layout().addLayout(layout)
        
        # Add to layout
        self.layout().addSpacing(10)
        self.layout().addWidget(self._label_info)
        #self.layout().addWidget(self._check_show)
        
    def _setNewUser(self, newUser):
        newUser = bool(newUser)
        self._label_info.setHidden(newUser)
        pyzo.config.state.newUser = newUser
    
    def onLanguageChange(self):
        languageName = self._langBox.currentText()
        if pyzo.config.settings.language == languageName:
            return
        # Save new language
        pyzo.config.settings.language = languageName
        setLanguage(pyzo.config.settings.language)
        # Notify user
        text = translate('wizard', """
        The language has been changed for this wizard.
        Pyzo needs to restart for the change to take effect application-wide.
        """)
        m = QtWidgets.QMessageBox(self)
        m.setWindowTitle(translate("wizard", "Language changed"))
        m.setText(text)
        m.setIcon(m.Information)
        m.exec_()
        
        # Get props of current wizard
        geo = self.wizard().geometry()
        parent = self.wizard().parent()
        # Close ourself!
        self.wizard().close()
        # Start new one
        w = PyzoWizard(parent)
        w.setGeometry(geo)
        w.show()
Example #32
0
class BasePyzoWizardPage(QtWidgets.QWizardPage):
    
    _prefix = translate('wizard', 'Step')
    
    _title = 'dummy title'
    _descriptions = []
    _image_filename = ''
    
    def __init__(self, parent, i):
        QtWidgets.QWizardPage.__init__(self, parent)
        self._i = i
        
        # Create label for description
        self._text_label = QtWidgets.QLabel(self)
        self._text_label.setTextFormat(QtCore.Qt.RichText)
        self._text_label.setWordWrap(True)
        
        # Create label for image
        self._comicLabel = QtWidgets.QLabel(self)
        pm = QtGui.QPixmap()
        if 'logo' in self._image_filename:
            pm.load(os.path.join(pyzo.pyzoDir, 'resources', 'appicons', self._image_filename))
        elif self._image_filename:
            pm.load(os.path.join(pyzo.pyzoDir, 'resources', 'images', self._image_filename))
        self._comicLabel.setPixmap(pm)
        self._comicLabel.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
        
        # Layout
        theLayout = QtWidgets.QVBoxLayout(self)
        self.setLayout(theLayout)
        #
        theLayout.addWidget(self._text_label)
        theLayout.addStretch()
        theLayout.addWidget(self._comicLabel)
        theLayout.addStretch()
    
    
    def initializePage(self):
        
        # Get prefix
        i = self._i
        n = self.wizard()._n - 2 # Dont count the first and last page
        prefix = ''
        if i and i <= n:
            prefix = retranslate(self._prefix) + ' %i/%i: ' % (i, n)
        
        # Set title
        self.setTitle(prefix + retranslate(self._title))
        
        # Parse description
        # Two description units are separated with BR tags
        # Emphasis on words is set to italic tags.
        lines = []
        descriptions = [retranslate(d).strip() for d in self._descriptions]
        for description in descriptions:
            for line in description.splitlines():
                line = line.strip()
                line = re.sub(r'\*(.+?)\*', r'<b>\1</b>', line)
                lines.append(line)
            lines.append('<br /><br />')
        lines = lines[:-1]
        
        # Set description
        self._text_label.setText('\n'.join(lines))