def __init__(self, parent): QtGui.QWidget.__init__(self, parent) # Create text field, checkbox, and button self._text = QtGui.QLineEdit(self) self._printBut = QtGui.QPushButton("Print", self) # Create options button self._options = QtGui.QToolButton(self) self._options.setIcon(pyzo.icons.wrench) self._options.setIconSize(QtCore.QSize(16, 16)) self._options.setPopupMode(self._options.InstantPopup) self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) # Create options menu self._options._menu = QtGui.QMenu() self._options.setMenu(self._options._menu) # Create browser self._browser = QtGui.QTextBrowser(self) self._browser_text = initText # Create two sizers self._sizer1 = QtGui.QVBoxLayout(self) self._sizer2 = QtGui.QHBoxLayout() # Put the elements together self._sizer2.addWidget(self._text, 4) self._sizer2.addWidget(self._printBut, 0) self._sizer2.addWidget(self._options, 2) # self._sizer1.addLayout(self._sizer2, 0) self._sizer1.addWidget(self._browser, 1) # self._sizer1.setSpacing(2) self._sizer1.setContentsMargins(4, 4, 4, 4) self.setLayout(self._sizer1) # Set config toolId = self.__class__.__name__.lower() self._config = config = pyzo.config.tools[toolId] # if not hasattr(config, 'smartNewlines'): config.smartNewlines = True if not hasattr(config, 'fontSize'): if sys.platform == 'darwin': config.fontSize = 12 else: config.fontSize = 10 # Create callbacks self._text.returnPressed.connect(self.queryDoc) self._printBut.clicked.connect(self.printDoc) # self._options.pressed.connect(self.onOptionsPress) self._options._menu.triggered.connect(self.onOptionMenuTiggered) # Start self.setText() # Set default text self.onOptionsPress() # Fill menu
def __init__(self, parent): QtGui.QTreeWidget.__init__(self, parent) self._config = parent._config # Set header stuff self.setHeaderHidden(False) self.setColumnCount(3) self.setHeaderLabels(['Name', 'Type', 'Repr']) #self.setColumnWidth(0, 100) self.setSortingEnabled(True) # Nice rows self.setAlternatingRowColors(True) self.setRootIsDecorated(False) # Create proxy self._proxy = WorkspaceProxy() self._proxy.haveNewData.connect(self.fillWorkspace) # For menu self.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) self._menu = QtGui.QMenu() self._menu.triggered.connect(self.contextMenuTriggered) # Bind to events self.itemActivated.connect(self.onItemExpand)
def __init__(self, parent): QtGui.QWidget.__init__(self, parent) # Make sure there is a configuration entry for this tool # The pyzo tool manager makes sure that there is an entry in # config.tools before the tool is instantiated. toolId = self.__class__.__name__.lower() self._config = pyzo.config.tools[toolId] if not hasattr(self._config, 'hideTypes'): self._config.hideTypes = [] # Create tool button self._up = QtGui.QToolButton(self) style = QtGui.qApp.style() self._up.setIcon(style.standardIcon(style.SP_ArrowLeft)) self._up.setIconSize(QtCore.QSize(16, 16)) # Create "path" line edit self._line = QtGui.QLineEdit(self) self._line.setReadOnly(True) self._line.setStyleSheet("QLineEdit { background:#ddd; }") self._line.setFocusPolicy(QtCore.Qt.NoFocus) # Create options menu self._options = QtGui.QToolButton(self) self._options.setIcon(pyzo.icons.filter) self._options.setIconSize(QtCore.QSize(16, 16)) self._options.setPopupMode(self._options.InstantPopup) self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) # self._options._menu = QtGui.QMenu() self._options.setMenu(self._options._menu) self.onOptionsPress() # create menu now # Create tree self._tree = WorkspaceTree(self) # Set layout layout = QtGui.QHBoxLayout() layout.addWidget(self._up, 0) layout.addWidget(self._line, 1) layout.addWidget(self._options, 0) # mainLayout = QtGui.QVBoxLayout(self) mainLayout.addLayout(layout, 0) mainLayout.addWidget(self._tree, 1) mainLayout.setSpacing(2) mainLayout.setContentsMargins(4, 4, 4, 4) self.setLayout(mainLayout) # Bind events self._up.pressed.connect(self._tree._proxy.goUp) self._options.pressed.connect(self.onOptionsPress) self._options._menu.triggered.connect(self.onOptionMenuTiggered)
def createPopupMenu(self): # Init menu menu = QtGui.QMenu() # Insert two items for item in ['Editors', 'Shells']: action = menu.addAction(item) action.setCheckable(True) action.setChecked(True) action.setEnabled(False) # Insert tools for tool in pyzo.toolManager.loadToolInfo(): action = menu.addAction(tool.name) action.setCheckable(True) action.setChecked(bool(tool.instance)) action.menuLauncher = tool.menuLauncher # Show menu and process result a = menu.popup(QtGui.QCursor.pos()) if a: a.menuLauncher(not a.menuLauncher(None))
def __init__(self, parent): QtGui.QWidget.__init__(self, parent) # Make sure there is a configuration entry for this tool # The pyzo tool manager makes sure that there is an entry in # config.tools before the tool is instantiated. toolId = self.__class__.__name__.lower() self._config = pyzo.config.tools[toolId] if not hasattr(self._config, 'showTypes'): self._config.showTypes = ['class', 'def', 'cell', 'todo'] if not hasattr(self._config, 'level'): self._config.level = 2 # Create icon for slider self._sliderIcon = QtGui.QToolButton(self) self._sliderIcon.setIcon(pyzo.icons.text_align_right) self._sliderIcon.setIconSize(QtCore.QSize(16, 16)) self._sliderIcon.setStyleSheet( "QToolButton { border: none; padding: 0px; }") # Create slider self._slider = QtGui.QSlider(QtCore.Qt.Horizontal, self) self._slider.setTickPosition(QtGui.QSlider.TicksBelow) self._slider.setSingleStep(1) self._slider.setPageStep(1) self._slider.setRange(1, 9) self._slider.setValue(self._config.level) self._slider.valueChanged.connect(self.updateStructure) # Create options button #self._options = QtGui.QPushButton(self) #self._options.setText('Options')) #self._options.setToolTip("What elements to show.") self._options = QtGui.QToolButton(self) self._options.setIcon(pyzo.icons.filter) self._options.setIconSize(QtCore.QSize(16, 16)) self._options.setPopupMode(self._options.InstantPopup) self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) # Create options menu self._options._menu = QtGui.QMenu() self._options.setMenu(self._options._menu) # Create tree widget self._tree = QtGui.QTreeWidget(self) self._tree.setHeaderHidden(True) self._tree.itemCollapsed.connect(self.updateStructure) # keep expanded self._tree.itemClicked.connect(self.onItemClick) # Create two sizers self._sizer1 = QtGui.QVBoxLayout(self) self._sizer2 = QtGui.QHBoxLayout() self._sizer1.setSpacing(2) self._sizer1.setContentsMargins(4, 4, 4, 4) # Set layout self._sizer1.addLayout(self._sizer2, 0) self._sizer1.addWidget(self._tree, 1) self._sizer2.addWidget(self._sliderIcon, 0) self._sizer2.addWidget(self._slider, 4) self._sizer2.addStretch(1) self._sizer2.addWidget(self._options, 2) # self.setLayout(self._sizer1) # Init current-file name self._currentEditorId = 0 # Bind to events pyzo.editors.currentChanged.connect(self.onEditorsCurrentChanged) pyzo.editors.parserDone.connect(self.updateStructure) self._options.pressed.connect(self.onOptionsPress) self._options._menu.triggered.connect(self.onOptionMenuTiggered) # Start # When the tool is loaded, the editorStack is already done loading # all previous files and selected the appropriate file. self.onOptionsPress() # Create menu now self.onEditorsCurrentChanged()
def setTrace(self, info): """ Set the stack trace. This method is called from the shell that receives the trace via its status channel directly from the interpreter. If trace is None, removes the trace """ # Get info if info: index, frames, debugmode = info['index'], info['frames'], info[ 'debugmode'] else: index, frames = -1, [] if (not frames) or (debugmode == 0): # Remove trace self.setMenu(None) self.setText('') #(self._baseText) self.setEnabled(False) pyzo.editors.setDebugLineIndicators(None) else: # Get the current frame theAction = None # Create menu and add __main__ menu = QtGui.QMenu(self) self.setMenu(menu) # Fill trace for i in range(len(frames)): thisIndex = i + 1 # Set text for action text = '{}: File "{}", line {}, in {}' text = text.format(thisIndex, *frames[i]) action = menu.addAction(text) action._index = thisIndex action._isCurrent = False if thisIndex == index: action._isCurrent = True theAction = action self.debugFocus(text.split(': ', 1)[1]) # Load editor # Get debug indicators debugIndicators = [] for i in range(len(frames)): thisIndex = i + 1 filename, linenr, func = frames[i] debugIndicators.append((filename, linenr)) if thisIndex == index: break # Set debug indicators pyzo.editors.setDebugLineIndicators(*debugIndicators) # Highlight current item and set the button text if theAction: menu.setDefaultAction(theAction) #self.setText(theAction.text().ljust(20)) i = theAction._index text = "{} ({}/{}): ".format(self._baseText, i, len(frames)) self.setText(text) self.setEnabled(True)