def walk_dir(self, dir_path, parentNode): dir_path = QtCore.QDir(dir_path) info_list = dir_path.entryInfoList(QtCore.QDir.AllEntries | QtCore.QDir.NoDotAndDotDot) isList = self.toolButtonGroup.checkedId() == 1 for fileInfo in info_list: if fileInfo.isDir(): if isList: self.walk_dir(fileInfo.filePath(), parentNode) else: treeItem = QtGui.QTreeWidgetItem(parentNode) treeItem.setText( 0, fileInfo.fileName()) ## hack to remove .html treeItem.setIcon(0, Icon(Ico.Folder)) self.walk_dir(fileInfo.filePath(), treeItem) #self.tree.addTopLevelItem(treeItem) #self.tree.setItemExpanded(treeItem, True) #return else: #print "pde" , fileInfo.filePath() if fileInfo.suffix() == 'pde': treeItem = QtGui.QTreeWidgetItem(parentNode) treeItem.setText( 0, fileInfo.fileName()) ## hack to remove .html treeItem.setData(0, QtCore.Qt.UserRole, fileInfo.filePath()) treeItem.setIcon(0, Icon(Ico.Sketch))
def on_action_view(self, strOrObject): if isinstance(strOrObject, QtCore.QString): ki = strOrObject else: ki = strOrObject.property("ki").toString() idx = None if ki == 'api_browser': apiBrowser = APIBrowser(self, self) idx = self.mainTabWidget.addTab(apiBrowser, Icon(Ico.Function), "API Browser") elif ki == "file_system_browser": fileSystemBrowser = gui.FileSystemBrowser.FileSystemBrowser( self, self) idx = self.mainTabWidget.addTab(fileSystemBrowser, Icon(Ico.FileSystemBrowser), "Files Browser") elif ki == 'sketches': sketchesWidget = SketchesBrowser(self, self) idx = self.mainTabWidget.addTab(sketchesWidget, Icon(Ico.Sketches), "Sketches") self.connect(sketchesWidget, QtCore.SIGNAL("open_sketch"), self.on_open_sketch) elif ki == 'welcome': welcomePage = Browser(self, self, "welcome.html") self.mainTabWidget.addTab(welcomePage, Icon(Ico.Arduino), "Welcome") if idx: self.mainTabWidget.setCurrentIndex(idx)
def on_view_selected(self, button): for bitt in self.toolButtonGroup.buttons(): if bitt.isChecked(): bitt.setIcon(Icon(Ico.Yellow)) else: bitt.setIcon(Icon(Ico.Black)) self.load_list()
def __init__(self, parent, main): QtGui.QDialog.__init__(self, parent) self.main = main self.setWindowTitle("WebSites") self.setWindowIcon(Icon(Ico.Settings)) self.setMinimumWidth(700) self.setMinimumHeight(500) mainLayout = QtGui.QVBoxLayout() self.setLayout(mainLayout) toolbar = QtGui.QToolBar(self) toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) mainLayout.addWidget(toolbar) self.actionAdd = toolbar.addAction(Icon(Ico.Help), "Add Site", self.on_add_site) #self.actionAddFunction.setDisabled(True) #self.actionEdit = toolbar.addAction(Icon(Ico.SiteEdit), "Edit Site", self.on_edit_site) #self.actionEdite.setDisabled(True) self.actionDelete = toolbar.addAction(Icon(Ico.Help), "Delete Site", self.on_delete_site) self.actionDelete.setDisabled(True) toolbar.addSeparator() self.tree = QtGui.QTreeWidget() mainLayout.addWidget(self.tree)
def walk_dir(self, dir_path, parentNode): ## Grab the children of the path files = dir_path.entryInfoList(QtCore.QDir.AllEntries | QtCore.QDir.NoDotAndDotDot) ## The mode of the tree. isList = (self.toolButtonGroup.checkedId() == 1) ## Recurse through the files for child in files: if child.isDir(): # Add the child directory and scan it if isList: self.walk_dir(QtCore.QDir(child.absoluteFilePath()), parentNode) else: treeItem = QtGui.QTreeWidgetItem(parentNode) treeItem.setText(0, child.fileName()) treeItem.setIcon(0, Icon(Ico.Folder)) self.walk_dir(QtCore.QDir(child.absoluteFilePath()), treeItem) else: # Add it as a file if child.suffix() == 'pde': treeItem = QtGui.QTreeWidgetItem(parentNode) treeItem.setText(0, child.fileName()) treeItem.setData(0, QtCore.Qt.UserRole, child.filePath()) treeItem.setIcon(0, Icon(Ico.Project))
def on_open_sketch(self, file_path): fileInfo = QtCore.QFileInfo(file_path) newEditor = EditorWidget(self, self, arduino_mode=True) newEditor.load_file(fileInfo.filePath()) newTab = self.mainTabWidget.addTab(newEditor, Icon(Ico.Sketch), fileInfo.fileName()) self.mainTabWidget.setCurrentIndex(newTab)
def __init__(self, parent, page): QtGui.QPushButton.__init__(self, parent) self._page = page self.setToolTip("Show help") self.setFlat(True) self.setIcon(Icon(Ico.Help)) self.connect(self, QtCore.SIGNAL("clicked()"), self.on_help)
def load_file(self): file_path = settings.hardware_path().absoluteFilePath( "programmers.txt") self.editor.load_file(file_path) boot_loaders = app.utils.load_arduino_config_file(file_path) c = 0 for boot_loader in boot_loaders: c += 1 bootLoaderItem = QtGui.QTreeWidgetItem() self.tree.addTopLevelItem(bootLoaderItem) bootLoaderItem.setIcon(0, Icon(Ico.BootLoader)) bootLoaderItem.setText(0, boot_loaders[boot_loader]['name']) font = bootLoaderItem.font(0) font.setBold(True) bootLoaderItem.setFont(0, font) bootLoaderItem.setFirstColumnSpanned(True) del boot_loaders[boot_loader][ 'name'] # nuke "name" node used above for prop in boot_loaders[boot_loader]: propItem = QtGui.QTreeWidgetItem(bootLoaderItem) propItem.setText(1, prop) propItem.setText(2, boot_loaders[boot_loader][prop]) for i in range(2, 3): self.tree.resizeColumnToContents(i) self.tree.sortByColumn(0, QtCore.Qt.AscendingOrder) self.statusBar.showMessage("%s items" % c)
def __init__(self, parent, label=None): QtGui.QPushButton.__init__(self, parent) self.parent = parent self.setIcon(Icon(Ico.Refresh2)) self.setFlat(True) self.setStyleSheet("padding: 0px;") self.connect(self, QtCore.SIGNAL("clicked()"), parent.on_refresh)
def __init__(self, parent, main): QtGui.QDialog.__init__(self, parent) self.main = main self.setWindowIcon(Icon(Ico.Help)) self.setWindowTitle("Help") self.setMinimumWidth(800) self.setMinimumHeight(500) self.statusLabel = GenericWidgets.StatusLabel(self) layout = QtGui.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) splitter = QtGui.QSplitter(self) layout.addWidget(splitter) self.helpTree = gui.widgets.HelpWidgets.HelpTree(self, self.main) splitter.addWidget(self.helpTree) #splitter.setStretchFactor(0, 1) self.browser = QtWebKit.QWebView() splitter.addWidget(self.browser)
def on_website_action(self, act): webPage = Browser(self, self, initial_page=act.property("url").toString()) newIdx = self.mainTabWidget.addTab(webPage, Icon(Ico.WebPage), act.text()) self.mainTabWidget.setCurrentIndex(newIdx)
def on_compile_log(self, log_type, log_txt): #print "compile_LOG", log_type , log_txt self.statusIcon.setIcon(Icon(Ico.CompileError)) self.statusMessage.setText(log_type) string = "" if log_type == "start_compile": ## start compile "resets the string" self.terminalTextWidget.setText("") string = "<font color=magenta>>>Compile: %s</font><br>" % log_txt elif log_type == 'env': string = "<font color=yellow>%s</font><br>" % log_txt elif log_type == 'command': string = "<font color=blue>%s</font><br>" % log_txt elif log_type == 'error': string = "<font color=red>%s</font><br>" % log_txt elif log_type == 'result': string = "<font color=green>%s</font><br>" % log_txt else: string = "<font color=white>%s</font><br>" % log_txt #self.terminalTextWidget.setText(self.terminal_string) self.terminalTextWidget.insertHtml(string) self.terminalTextWidget.textCursor().setPosition( QtGui.QTextCursor.MoveAnchor) self.terminalTextWidget.scrollToAnchor("")
def __init__(self, parent, label=None, sending=None, done=None): QtGui.QPushButton.__init__(self, parent) self.parent = parent self.setMinimumWidth(100) self.setText(label if label else "Save") self.setIcon(Icon(Ico.Save)) self.connect(self, QtCore.SIGNAL("clicked()"), parent.on_save)
def on_open_project(self, file_path): fileInfo = QtCore.QFileInfo(file_path) newEditor = ArduinoEditorWidget(self, self) newTab = self.mainTabWidget.addTab(newEditor, Icon(Ico.Project), fileInfo.fileName()) self.mainTabWidget.setCurrentIndex(newTab) newEditor.load_project(fileInfo.filePath( )) ## load file after adding as child, parented = events ?
def load_bookmarks(self): return paths = self.main.settings.all_paths() for pathinfo in paths: item = QtGui.QTreeWidgetItem() item.setIcon(0, Icon(Ico.Folder)) item.setText(0, pathinfo[0]) item.setText(1, pathinfo[1]) self.treeBookmarks.addTopLevelItem(item)
def __init__(self, parent, main, initial_page=None, compact=False, enable_api=True, auto_compact_exit=True): """ Initializes the browser pane """ QtGui.QWidget.__init__(self, parent) self.main = main self.compact = compact self.auto_compact_exit = auto_compact_exit mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(0,0,0,0) mainLayout.setSpacing(0) self.setLayout(mainLayout) self.toolbar = QtGui.QToolBar() mainLayout.addWidget(self.toolbar, 0) act = self.toolbar.addAction(Icon(Ico.Back), "", self.on_back) act.setToolTip("Back") act = self.toolbar.addAction(Icon(Ico.Forward), "", self.on_forward) act.setToolTip("Forward") act = self.toolbar.addAction(Icon(Ico.Refresh), "", self.on_refresh) act.setToolTip("Refresh") self.txtUrl = QtGui.QLineEdit(initial_page) self.toolbar.addWidget(self.txtUrl) ### Brwoser - declared below self.browser = BrowserWidget(self, self.main, enable_api=enable_api) mainLayout.addWidget(self.browser, 2000) self.browser.statusBarMessage.connect(self.on_browser_status_message) self.browser.urlChanged.connect(self.on_browser_url_changed) self.browser.linkClicked.connect(self.on_browser_link_clicked) print "Connected Events" self.statusBar = QtGui.QStatusBar() mainLayout.addWidget(self.statusBar, 0) if compact: self.mode_change(compact) if initial_page: self.browser.setUrl(QtCore.QUrl(QtCore.QString(initial_page)))
def __init__(self, parent, main): QtGui.QWidget.__init__(self) self.main = main self.paths = None layout = QtGui.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) ################################################################## ## Filter Bar ################################################################## hBox = QtGui.QHBoxLayout() layout.addLayout(hBox) buttClearFilter = QtGui.QPushButton(self) buttClearFilter.setIcon( Icon(Ico.Black) ) buttClearFilter.setFlat(True) buttClearFilter.setText("All") self.connect( buttClearFilter, QtCore.SIGNAL("clicked()"), self.on_filter_clear) hBox.addWidget( buttClearFilter, 1 ) self.txtFilter = QtGui.QLineEdit("") self.connect(self.txtFilter, QtCore.SIGNAL('textChanged(const QString &)'), self.on_filter_changed) hBox.addWidget( self.txtFilter, 222 ) ################################################################## ### Models ################################################################## self.model = QtGui.QStandardItemModel(0, 1, self) self.model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("Topic")) self.proxyModel = QtGui.QSortFilterProxyModel(self) self.proxyModel.setSourceModel( self.model ) ################################################################# ### Tree ################################################################## self.tree = QtGui.QTreeView() self.tree.setRootIsDecorated(False) self.tree.setAlternatingRowColors(True) self.tree.setSortingEnabled(True) self.tree.setModel(self.proxyModel) layout.addWidget(self.tree) self.connect(self.tree, QtCore.SIGNAL("clicked(const QModelIndex&)"), self.on_tree_double_clicked) self.api_lines = None self.load()
def on_action_view(self, strOrObject): """ Creates a new tab """ #TODO: Banish this! if isinstance(strOrObject, QtCore.QString): ki = strOrObject else: ki = strOrObject.property("ki").toString() idx = None if ki == 'api_browser': apiBrowser = APIBrowserPane(self, self) idx = self.mainTabWidget.addTab(apiBrowser, Icon(Ico.Function), "API Browser") elif ki == "file_system_browser": fileSystemBrowser = FileSystemBrowserPane(self, self) idx = self.mainTabWidget.addTab(fileSystemBrowser, Icon(Ico.FileSystemBrowser), "Files Browser") elif ki == 'projects': projectsWidget = ProjectsBrowser(self, self) idx = self.mainTabWidget.addTab(projectsWidget, Icon(Ico.Projects), "Projects") self.connect(projectsWidget, QtCore.SIGNAL("open_project"), self.on_open_project) elif ki == 'welcome': welcomePage = BrowserPane( self, self, initial_page="file://%s" % settings.html_pages_path().absoluteFilePath("welcome.html"), compact=True) self.mainTabWidget.addTab(welcomePage, Icon(Ico.Arduino), "Welcome") if idx: self.mainTabWidget.setCurrentIndex(idx)
def on_view_size_clicked(self, butt): #print "on_view_size_clicked", butt for bu in self.viewSizeButtonGroup.buttons(): bu.setChecked(False) bu.setIcon(Icon(Ico.Yellow if bu.isChecked() else Ico.Black)) if butt.property("size") == 'Small': siz = 100 elif butt.text() == 'Medium': siz = 300 else: siz = 500 self.setFixedHeight(siz)
def __init__(self, parent, main): QtGui.QDialog.__init__(self, parent) self.main = main self.setWindowTitle("Boot Loaders") self.setWindowIcon(Icon(Ico.BootLoaders)) self.setMinimumWidth(500) self.setMinimumHeight(400) mainLayout = QtGui.QVBoxLayout() m = 0 mainLayout.setContentsMargins(m, 10, m, m) mainLayout.setSpacing(0) self.setLayout(mainLayout) tabWidget = QtGui.QTabWidget() mainLayout.addWidget(tabWidget) ####################################### ## Tree Tab self.tree = QtGui.QTreeWidget() tabWidget.addTab(self.tree, "Tree View") self.connect( self.tree, QtCore.SIGNAL("itemDoubleClicked (QTreeWidgetItem *,int)"), self.on_tree_double_clicked) self.connect(self.tree, QtCore.SIGNAL("itemClicked (QTreeWidgetItem *,int)"), self.on_tree_clicked) self.tree.setAnimated(True) self.tree.setRootIsDecorated(True) self.tree.setAlternatingRowColors(False) self.tree.header().setStretchLastSection(True) self.tree.headerItem().setText(0, "") self.tree.headerItem().setText(1, "Property") self.tree.headerItem().setText(2, "Value") self.tree.setColumnWidth(0, 100) self.tree.setColumnWidth(1, 150) ####################################### ## Editor Tab self.editor = EditorWidget(self, self.main) tabWidget.addTab(self.editor, "programmers.txt") ####################################### ## Status Bar self.statusBar = QtGui.QStatusBar() mainLayout.addWidget(self.statusBar) self.load_file()
def load_list(self): self.tree.model().removeRows(0, self.tree.model().rowCount()) xlist = self.main.api.list() for entry_type, file_path, entry, ico in xlist: #print entry_type, entry ## the entry type is also filter keys, html, function, keywords if self.filterButtons[entry_type].isChecked(): row_idx = self.model.rowCount() item = QtGui.QStandardItem(entry) item.setIcon(Icon(ico)) item.setEditable(False) self.model.setItem(row_idx, 0, item) itemki = item = QtGui.QStandardItem(entry_type) self.model.setItem(row_idx, 1, itemki) self.tree.sortByColumn(0, QtCore.Qt.AscendingOrder) self.tree.setColumnHidden(1, True)
def walk_dir(self, sub_dir, folder, parentItem): for file_entry in sub_dir.entryInfoList(QtCore.QDir.Files | QtCore.QDir.NoDotAndDotDot): if file_entry.suffix() == 'yaml': self.add_yaml_function_node(file_entry, folder, parentItem) for folder_entry in sub_dir.entryInfoList(QtCore.QDir.Dirs | QtCore.QDir.NoDotAndDotDot): n_folder = folder + folder_entry.fileName() + "/" dirItem = QtGui.QTreeWidgetItem(parentItem) dirItem.setText(self.COLS.icon, folder_entry.fileName()) dirItem.setText(self.COLS.folder, n_folder) dirItem.setIcon(self.COLS.icon, Icon(Ico.Folder)) dirItem.setData(self.COLS.icon, QtCore.Qt.UserRole, QtCore.QVariant(folder_entry.filePath())) dirItem.setFirstColumnSpanned(False) self.tree.setItemExpanded(dirItem, True) self.walk_dir(QtCore.QDir(folder_entry.filePath()), n_folder, dirItem) self.paths.append( str(n_folder) )
def __init__(self, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main self.process = QtCore.QProcess(self) self.current_file_path = None layout = QtGui.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(0) layout.addLayout(hbox) self.textWidget = QtGui.QPlainTextEdit() layout.addWidget(self.textWidget) self.textWidget.setDocumentTitle("Foo") self.textWidget.setStyleSheet("color: white; background-color: black;") hbox = QtGui.QHBoxLayout() layout.addLayout(hbox) self.actionIcon = QtGui.QPushButton() self.actionIcon.setFlat(True) self.actionIcon.setIcon(Icon(Ico.Black)) hbox.addWidget(self.actionIcon, 1) #elf.statusBar.showMessage("ssssssssssssssss-") self.statusLabel = QtGui.QLabel("Terminal Output") hbox.addWidget(self.statusLabel, 20) self.progress = QtGui.QProgressBar() self.progress.setRange(0, 3) self.progress.setFixedHeight(15) #self.progress.hide() hbox.addWidget(self.progress)
def load_file(self): self.editor.load_file( settings.hardware_path().absoluteFilePath("boards.txt")) ## Loop the boards boards = self.main.boards.all() for board in boards: boardItem = QtGui.QTreeWidgetItem() self.tree.addTopLevelItem(boardItem) boardItem.setIcon(0, Icon(Ico.Board)) boardItem.setText(0, boards[board]['name']) font = boardItem.font(0) font.setBold(True) boardItem.setFont(0, font) boardItem.setFirstColumnSpanned(True) ## loop each section andn ignore 'name' for section in boards[board]: if section == 'name': pass else: sectionItem = QtGui.QTreeWidgetItem(boardItem) sectionItem.setText(0, section) sectionItem.setFirstColumnSpanned(True) ## loops dic properties if isinstance(boards[board][section], dict): for prop in boards[board][section]: propItem = QtGui.QTreeWidgetItem(sectionItem) propItem.setText(1, prop) propItem.setText(2, boards[board][section][prop]) for i in range(1, 3): self.tree.resizeColumnToContents(i) self.tree.sortByColumn(0, QtCore.Qt.AscendingOrder) self.statusBar.showMessage("%s boards" % self.tree.invisibleRootItem().childCount())
def __init__(self, parent, b_type): QtGui.QPushButton.__init__(self, parent) self.parent = parent self.setText(b_type) self.setIcon(Icon(Ico.Cancel)) self.connect(self, QtCore.SIGNAL("clicked()"), parent.on_cancel)
def __init__(self, title, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main if title == "Examples": ## TODO sody path to view self.dir_to_browse = settings.examples_path() else: self.dir_to_browse = settings.sketches_path() mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) headLabel = GenericWidgets.HeaderLabel(self, self.main, icon=Ico.Projects, title=title, color="black", wash_to="#456D91") mainLayout.addWidget(headLabel) self.statusWidget = GenericWidgets.StatusWidget(self) ## redundant listings tree of bookmaarks.. maybe later if 1 == 0: self.treePlaces = QtGui.QTreeWidget() mainLayout.addWidget(self.treePlaces, 1) self.treePlaces.headerItem().setText(0, "Location") self.treePlaces.headerItem().setText(1, "Path") self.treePlaces.header().hide() self.treePlaces.setColumnHidden(1, True) self.treePlaces.setRootIsDecorated(False) self.treePlaces.setAlternatingRowColors(True) self.connect(self.treePlaces, QtCore.SIGNAL("itemClicked (QTreeWidgetItem *,int)"), self.on_tree_place_clicked) for panel in [["Examples", settings.examples_path()], ["Sketches", settings.sketchbooks_path()]]: item = QtGui.QTreeWidgetItem() self.treePlaces.addTopLevelItem(item) item.setText(0, panel[0]) font = item.font(0) font.setBold(True) item.setFont(0, font) item.setIcon(0, Icon(Ico.Folder)) if panel[1]: item.setText(1, panel[1]) self.dir_to_browse = None toolbar = QtGui.QToolBar(self) toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) mainLayout.addWidget(toolbar) self.toolButtonGroup = QtGui.QButtonGroup(self) self.toolButtonGroup.setExclusive(True) self.connect(self.toolButtonGroup, QtCore.SIGNAL("buttonClicked(QAbstractButton *)"), self.on_view_selected) listButton = QtGui.QToolButton() listButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) listButton.setText("Tree") listButton.setIcon(Icon(Ico.Black)) listButton.setStyleSheet("padding: 0px; margin: 0px;") listButton.setCheckable(True) listButton.setChecked(True) toolbar.addWidget(listButton) self.toolButtonGroup.addButton(listButton, 0) listButton = QtGui.QToolButton() listButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) listButton.setText("List") listButton.setIcon(Icon(Ico.Yellow)) listButton.setStyleSheet("padding: 0px; margin: 0px;") listButton.setCheckable(True) toolbar.addWidget(listButton) self.toolButtonGroup.addButton(listButton, 1) ####################################### ## Tree ####################################### self.tree = QtGui.QTreeWidget() mainLayout.addWidget(self.tree, 10) self.tree.setSortingEnabled(True) self.tree.setRootIsDecorated(True) self.tree.setAlternatingRowColors(False) self.tree.headerItem().setText(0, "Files") self.connect( self.tree, QtCore.SIGNAL("itemDoubleClicked (QTreeWidgetItem *,int)"), self.on_tree_double_clicked) self.connect(self.tree, QtCore.SIGNAL("itemClicked (QTreeWidgetItem *,int)"), self.on_tree_clicked) self.load_list()
def __init__(self, parent, main, arduino_mode=False): QtGui.QWidget.__init__(self) self.main = main self.current_file_path = None self.board = "board_name" self.port = "Sanderman" mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) ############################################################## ### File Info Bar at the top ############################################################## fileInfoBox = QtGui.QHBoxLayout() mainLayout.addLayout(fileInfoBox, 0) self.lblFileName = QtGui.QLabel(self) self.lblFileName.setText("Filename") style_grad = "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #efefef, stop: 1 %s);" % "#6A7885" style_grad += "font-weight: bold; border: 1px outset #41484E; padding: 3px;" self.lblFileName.setStyleSheet(style_grad) fileInfoBox.addWidget(self.lblFileName, 4) ######################################### ## Save Button self.buttonSave = QtGui.QPushButton(self) self.buttonSave.setText("Save") self.buttonSave.setIcon(Icon(Ico.Save)) fileInfoBox.addWidget(self.buttonSave) self.connect(self.buttonSave, QtCore.SIGNAL("clicked()"), self.on_save_button_clicked) ########################################### ## Actions button with dropdown menu buttActions = QtGui.QPushButton(self) buttActions.setText("Actions") buttActions.setIcon(Icon(Ico.Green)) fileInfoBox.addWidget(buttActions) fileActionsMenu = QtGui.QMenu(buttActions) buttActions.setMenu(fileActionsMenu) self.fileActionsGroup = QtGui.QActionGroup(self) self.connect(self.fileActionsGroup, QtCore.SIGNAL("triggered(QAction*)"), self.on_file_action) for act in [['rename', 'Rename'], ['copy', 'Copy'], ['commit', 'Commit']]: nuAction = fileActionsMenu.addAction(act[1]) nuAction.setProperty('action_name', act[0]) # TODO - maybe this should be in button group #################################################### ## Scintilla Editor #################################################### self.editor = QsciScintilla(self) self.editor.setUtf8(True) self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.editor.setMarginLineNumbers(1, True) self.editor.setMarginWidth(1, 30) self.editor.setAutoIndent(True) mainLayout.addWidget(self.editor, 200) bottomStatusBar = QtGui.QStatusBar(self) mainLayout.addWidget(bottomStatusBar, 0) ######################################### ## File Size and Modified info self.lblFileSize = GenericWidgets.StatusLabel(self, "Size") bottomStatusBar.addPermanentWidget(self.lblFileSize) self.lblFileModified = GenericWidgets.StatusLabel(self, "Modified") bottomStatusBar.addPermanentWidget(self.lblFileModified) ############################################################## ### Arduino Compiler With compile and board selector ############################################################## """if arduino_mode:
def __init__(self, parent, main, function_file, path, paths): QtGui.QDialog.__init__(self, parent) self.main = main self.function_file = function_file self.path = path self.paths = paths self.dic = None #print function_file, path, paths self.setMinimumWidth(1100) self.setMinimumHeight(800) mainLayout = QtGui.QVBoxLayout() self.setLayout(mainLayout) gridLayout = QtGui.QGridLayout() mainLayout.addLayout(gridLayout) row = 0 ## Function gridLayout.addWidget(QtGui.QLabel("Function:"), row, 0, QtCore.Qt.AlignRight) self.txtFunction = QtGui.QLineEdit() gridLayout.addWidget(self.txtFunction, row, 1) gridLayout.addWidget(QtGui.QLabel("Name eg digitialFilter (no brackets)"), row, 2) self.connect(self.txtFunction, QtCore.SIGNAL("textChanged(const QString&)"), self.on_function_text_changed) ## Lib row += 1 gridLayout.addWidget(QtGui.QLabel("Lib:"), row, 0, QtCore.Qt.AlignRight) self.comboLib = QtGui.QComboBox() for pth in paths: newIdx = self.comboLib.count() self.comboLib.insertItem(newIdx, pth) print pth, self.path if pth == self.path: self.comboLib.setCurrentIndex(newIdx) gridLayout.addWidget(self.comboLib, row, 1) gridLayout.addWidget(QtGui.QLabel("Lib eg arduino"), row, 2) ## Section row += 1 gridLayout.addWidget(QtGui.QLabel("Section:"), row, 0, QtCore.Qt.AlignRight) self.txtSection = QtGui.QLineEdit() gridLayout.addWidget(self.txtSection, row, 1) gridLayout.addWidget(QtGui.QLabel("Nav section eg math or digtital IO"), row, 2) ## Syntax """ row += 1 gridLayout.addWidget(QtGui.QLabel("Syntax:"), row, 0, QtCore.Qt.AlignRight) self.txtSyntax = QtGui.QLineEdit() self.txtSyntax.setReadOnly(True) gridLayout.addWidget(self.txtSyntax, row, 1) gridLayout.addWidget(QtGui.QLabel(""), row, 2) """ ## Summary row += 1 gridLayout.addWidget(QtGui.QLabel("Summary:"), row, 0, QtCore.Qt.AlignRight) self.txtSummary = QtGui.QLineEdit() gridLayout.addWidget(self.txtSummary, row, 1, 1, 2) #gridLayout.addWidget(QtGui.QLabel("Brief popup description"), row, 2) ## Parameters Widgets tree row += 1 grpBox = QtGui.QGroupBox("Parameters") gridLayout.addWidget(grpBox, row, 0, 1, 3) grpLayout = QtGui.QVBoxLayout() grpLayout.setSpacing(0) grpBox.setLayout(grpLayout) toolbar = QtGui.QToolBar() toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) grpLayout.addWidget(toolbar) self.radioFixed = QtGui.QRadioButton("Fixed params", self) toolbar.addWidget(self.radioFixed) self.radioFixed.hide() self.radioVariable = QtGui.QRadioButton("Variable params", self) self.radioVariable.hide() toolbar.addWidget(self.radioVariable) toolbar.addSeparator() toolbar.addAction(Icon(Ico.Add), "Add Syntax", self.on_add_syntax) toolbar.addAction(Icon(Ico.Remove), "Remove", self.on_remove_parameter) toolbar.addSeparator() toolbar.addAction(Icon(Ico.Up), "Up", self.on_move_up) toolbar.addAction(Icon(Ico.Down), "Down", self.on_move_down) self.tree = QtGui.QTreeWidget() self.tree.setRootIsDecorated(False) self.tree.headerItem().setText(0, "Parameter") self.tree.headerItem().setText(1, "Description") grpLayout.addWidget(self.tree) self.connect(self.tree, QtCore.SIGNAL("itemChanged(QTreeWidgetItem *,int)"), self.on_tree_changed) ## Returns row += 1 self.chkReturn = QtGui.QCheckBox("Return") self.connect(self.chkReturn, QtCore.SIGNAL("toggled(bool)"), self.on_chk_return) gridLayout.addWidget(self.chkReturn, row, 0, QtCore.Qt.AlignRight) self.txtReturn = QtGui.QLineEdit() gridLayout.addWidget(self.txtReturn, row, 1, 1, 2) #gridLayout.addWidget(QtGui.QLabel("eg milliseconds elapsed"), row, 2) ## Description row += 1 grpBox = QtGui.QGroupBox("Description") gridLayout.addWidget(grpBox, row, 0, 1, 3) grpLayout = QtGui.QVBoxLayout() grpBox.setLayout(grpLayout) self.txtDescription = QtGui.QPlainTextEdit() grpLayout.addWidget(self.txtDescription) ## Example #row += 1 grpBox = QtGui.QGroupBox("Example") gridLayout.addWidget(grpBox, 0, 3, 7, 1) grpLayout = QtGui.QVBoxLayout() grpBox.setLayout(grpLayout) self.txtExample = QtGui.QPlainTextEdit() grpLayout.addWidget(self.txtExample) gridLayout.setColumnStretch(0, 0) gridLayout.setColumnStretch(1, 2) gridLayout.setColumnStretch(2, 0) gridLayout.setColumnStretch(3, 3) ############################################ ## Bottom Buttons bbox = QtGui.QHBoxLayout() mainLayout.addLayout(bbox) bbox.addStretch(20) cancelButton = GenericWidgets.CancelButton(self, "Cancel") bbox.addWidget(cancelButton, 1) self.saveButton = GenericWidgets.SaveButton(self) bbox.addWidget(self.saveButton, 1) self.statusBar = QtGui.QStatusBar(self) mainLayout.addWidget(self.statusBar) if self.function_file: self.load_file()
def add_yaml_function_node(self, sub_entry, folder, parentNode): api = app.utils.load_yaml(sub_entry.filePath()) #print api ## TODO Qtify if 'section' in api and api['section']: section = api['section'] else: section = "#" #print api is_fixed = 'parameters_type' in api and api['parameters_type'] == 'fixed' if not is_fixed: #print "foo" s = api['function'] + "(*)" funkFileItem = QtGui.QTreeWidgetItem(parentNode) funkFileItem.setIcon(self.COLS.icon, Icon(Ico.Function)) funkFileItem.setData(self.COLS.icon, QtCore.Qt.UserRole, sub_entry.fileName()) funkFileItem.setText(self.COLS.folder, folder) font = funkFileItem.font(self.COLS.icon) font.setBold(True) funkFileItem.setFont(self.COLS.icon, font) funkFileItem.setText(self.COLS.icon, s) funkFileItem.setText(self.COLS.function, api['function']) if len(api['parameters']) > 0: #p_list = [] for ap in api['parameters']: paraSyntax = QtGui.QTreeWidgetItem(funkFileItem) paraSyntax.setIcon(self.COLS.icon, Icon(Ico.FunctionSub)) paraSyntax.setData(self.COLS.icon, QtCore.Qt.UserRole, sub_entry.fileName()) font = funkFileItem.font(self.COLS.icon) font.setBold(True) paraSyntax.setFont(self.COLS.icon, font) func_name = api['function'] if ap.keys()[0] == '': s = func_name + "()" else: s = func_name + "( " + ap.keys()[0] + " )" paraSyntax.setText(self.COLS.icon, s) paraSyntax.setText(self.COLS.description, ap.values()[0]) paraSyntax.setText(self.COLS.function, api['function']) paraSyntax.setText(self.COLS.folder, folder) else: funkFileItem = QtGui.QTreeWidgetItem(parentNode) funkFileItem.setIcon(self.COLS.icon, Icon(Ico.Function)) #funkFileItem.setText(self.COLS.icon, sub_entry.fileName()) font = funkFileItem.font(self.COLS.icon) font.setBold(True) funkFileItem.setFont(self.COLS.icon, font) #if 'syntax' in api: # funkFileItem.setText(self.COLS.icon, api['syntax']) ss = "<b><font color=#176087 >%s</font></b>" % api['function'] s = api['function'] if len(api['parameters']) > 0: p_list = [] for ap in api['parameters']: #sss = "<font color=blue><b>%s</b></font>" % ap.keys()[0] sss = ap.keys()[0] p_list.append(sss) s += "( " + ", ".join(p_list)+ " )" #kidd = QtGui.QTreeWidgetItem(funkFileItem) #kidd.setIcon(self.COLS.icon, Icon(Ico.Green)) else: s += "()" #s += " - <small>%s</small>" % api['summary'] funkFileItem.setText(self.COLS.icon, s) #lbl = QtGui.QLabel(s, self.tree) #lbl.setAutoFillBackground(True) #self.tree.setItemWidget(funkFileItem, self.COLS.icon, lbl) #kidd.setText(self.COLS.description, ap.values()[0]) #kidd.setData(self.COLS.icon, QtCore.Qt.UserRole, QtCore.QVariant(sub_entry.filePath())) funkFileItem.setText(self.COLS.description, api['summary']) funkFileItem.setText(self.COLS.function, api['function']) funkFileItem.setText(self.COLS.folder, folder) #funkFileItem.setText(self.COLS.section, section) funkFileItem.setData(self.COLS.icon, QtCore.Qt.UserRole, QtCore.QVariant(sub_entry.filePath())) #self.tree.setItemExpanded(funkFileItem, True) #print api['parameters'] if 1 == 0: if len(api['parameters']) > 0: ##TODO Qt'ify python code if 'parameters_type' in api and api['parameters_type'] =='fixed': for ap in api['parameters']: kidd = QtGui.QTreeWidgetItem(funkFileItem) kidd.setIcon(self.COLS.icon, Icon(Ico.FunctionParam)) kidd.setText(self.COLS.icon, ap.keys()[0]) kidd.setText(self.COLS.description, ap.values()[0]) kidd.setData(self.COLS.icon, QtCore.Qt.UserRole, QtCore.QVariant(sub_entry.filePath())) if 'return' in api and api['return'] != '': kidd = QtGui.QTreeWidgetItem(funkFileItem) kidd.setIcon(self.COLS.icon, Icon(Ico.FunctionReturn)) lbl = QtCore.QString("Return: ").append(api['return']) kidd.setText(self.COLS.icon, lbl) kidd.setData(self.COLS.icon, QtCore.Qt.UserRole, QtCore.QVariant(sub_entry.filePath())) kidd.setFirstColumnSpanned(True)
def __init__(self, parent, main, function_name=None): QtGui.QWidget.__init__(self, parent) self.main = main self.function_name = function_name mainLayout = QtGui.QVBoxLayout() self.setLayout(mainLayout) gridLayout = QtGui.QGridLayout() mainLayout.addLayout(gridLayout) row = 0 ## Function gridLayout.addWidget(QtGui.QLabel("Function:"), row, 0, QtCore.Qt.AlignRight) self.txtFunction = QtGui.QLineEdit() gridLayout.addWidget(self.txtFunction, row, 1) gridLayout.addWidget(QtGui.QLabel("Name eg digitialFilter()"), row, 2) ## Lib row += 1 gridLayout.addWidget(QtGui.QLabel("Lib:"), row, 0, QtCore.Qt.AlignRight) self.txtLib = QtGui.QLineEdit() #self.cmbLib.addItem("arduino") #self.cmbLib.addItem("servo") #self.cmbLib.addItem("stepper") gridLayout.addWidget(self.txtLib, row, 1) gridLayout.addWidget(QtGui.QLabel("Lib eg arduino"), row, 2) ## Section row += 1 gridLayout.addWidget(QtGui.QLabel("Section:"), row, 0, QtCore.Qt.AlignRight) self.txtSection = QtGui.QLineEdit() gridLayout.addWidget(self.txtSection, row, 1) gridLayout.addWidget( QtGui.QLabel("Nav section eg math or digtital IO"), row, 2) ## Syntax row += 1 gridLayout.addWidget(QtGui.QLabel("Syntax:"), row, 0, QtCore.Qt.AlignRight) self.txtSyntax = QtGui.QLineEdit() gridLayout.addWidget(self.txtSyntax, row, 1) gridLayout.addWidget(QtGui.QLabel("eg digitalWrite(pin, value)"), row, 2) ## Tooltip row += 1 gridLayout.addWidget(QtGui.QLabel("Summary:"), row, 0, QtCore.Qt.AlignRight) self.txtSummary = QtGui.QLineEdit() gridLayout.addWidget(self.txtSummary, row, 1) gridLayout.addWidget(QtGui.QLabel("Brief popup description"), row, 2) ## Parameters Widgets tree row += 1 grpBox = QtGui.QGroupBox("Parameters") gridLayout.addWidget(grpBox, row, 0, 1, 3) grpLayout = QtGui.QVBoxLayout() grpLayout.setSpacing(0) grpBox.setLayout(grpLayout) toolbar = QtGui.QToolBar() toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) grpLayout.addWidget(toolbar) toolbar.addAction(Icon(Ico.Add), "Add", self.on_add_parameter) toolbar.addAction(Icon(Ico.Remove), "Remove", self.on_remove_parameter) toolbar.addSeparator() toolbar.addAction(Icon(Ico.Up), "Up", self.on_move_up) toolbar.addAction(Icon(Ico.Down), "Down", self.on_move_down) self.tree = QtGui.QTreeWidget() self.tree.setRootIsDecorated(False) self.tree.headerItem().setText(0, "Parameter") self.tree.headerItem().setText(1, "Description") grpLayout.addWidget(self.tree) ## Description row += 1 grpBox = QtGui.QGroupBox("Description") gridLayout.addWidget(grpBox, row, 0, 1, 3) grpLayout = QtGui.QVBoxLayout() grpBox.setLayout(grpLayout) self.txtDescription = QtGui.QPlainTextEdit() grpLayout.addWidget(self.txtDescription) ## Example #row += 1 grpBox = QtGui.QGroupBox("Example") gridLayout.addWidget(grpBox, 0, 3, 7, 1) grpLayout = QtGui.QVBoxLayout() grpBox.setLayout(grpLayout) self.txtExample = QtGui.QPlainTextEdit() grpLayout.addWidget(self.txtExample) gridLayout.setColumnStretch(0, 0) gridLayout.setColumnStretch(1, 2) gridLayout.setColumnStretch(2, 0) gridLayout.setColumnStretch(3, 3) ############################################ ## Bottom Buttons bbox = QtGui.QHBoxLayout() mainLayout.addLayout(bbox) bbox.addStretch(20) cancelButton = GenericWidgets.CancelButton(self, "Cancel") bbox.addWidget(cancelButton, 1) self.saveButton = GenericWidgets.SaveButton(self) bbox.addWidget(self.saveButton, 1) if self.function_name: self.load_file()