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, main): QtGui.QWidget.__init__(self, parent) self.main = main self.project_file_path = None self.project_settings_file = None self.project_settings = None mainLayout = QtGui.QHBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) ######################################### ## Editor/Terminal on left, Compiler Bar on right self.editorCompilerSplitter = QtGui.QSplitter(self) mainLayout.addWidget(self.editorCompilerSplitter, 20) self.editorCompilerSplitter.setOrientation(QtCore.Qt.Horizontal) #################################################### ## Editor at top, Terminal at bottom Splitter self.editorTerminalSplitter = QtGui.QSplitter(self) self.editorTerminalSplitter.setOrientation(QtCore.Qt.Vertical) self.editorCompilerSplitter.addWidget(self.editorTerminalSplitter) ######################################### ## Editor Widget self.editor = EditorWidget(self, self.main) self.editorTerminalSplitter.addWidget(self.editor) ######################################### ## Terminal Widget self.terminalWidget = TerminalWidget(self, self.main) self.editorTerminalSplitter.addWidget(self.terminalWidget) ############################################################## ### Arduino Compiler Bar self.arduinoCompilerBar = ArduinoCompilerBar(self, self.main) self.connect(self.arduinoCompilerBar, QtCore.SIGNAL("compile_action"), self.on_compile_action) self.connect(self.arduinoCompilerBar, QtCore.SIGNAL("project_settings_changed"), self.on_project_settings_changed) self.editorCompilerSplitter.addWidget(self.arduinoCompilerBar) ## Layout tweeks - TODO store thas in project self.editorCompilerSplitter.setStretchFactor(0, 2) self.editorCompilerSplitter.setStretchFactor(1, 0) self.editorTerminalSplitter.setStretchFactor(0, 5) self.editorTerminalSplitter.setStretchFactor(1, 2)
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 __init__(self, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) splitter = QtGui.QSplitter() mainLayout.addWidget(splitter) ################################################### #### Toolbar #toolbar = QtGui.QToolBar(self) ## leftLayout = QtGui.QVBoxLayout() ################################################### #### Tree self.tree = FileSystemTree(self, self.main) self.connect(self.tree, QtCore.SIGNAL("open_file"), self.on_open_file) splitter.addWidget(self.tree) ################################################### #### Editor self.editor = EditorWidget(self, self.main, arduino_mode=False) splitter.addWidget(self.editor) #self.editor.setUtf8(True) #self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) #self.setCentralWidget(self.editor) #self.editor.setMarginLineNumbers(1, True) #self.editor.setAutoIndent(True) splitter.setStretchFactor(0, 1) splitter.setStretchFactor(1, 2)
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()
class FileSystemBrowser(QtGui.QWidget): def __init__(self, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) splitter = QtGui.QSplitter() mainLayout.addWidget(splitter) ################################################### #### Toolbar #toolbar = QtGui.QToolBar(self) ## leftLayout = QtGui.QVBoxLayout() ################################################### #### Tree self.tree = FileSystemTree(self, self.main) self.connect(self.tree, QtCore.SIGNAL("open_file"), self.on_open_file) splitter.addWidget(self.tree) ################################################### #### Editor self.editor = EditorWidget(self, self.main, arduino_mode=False) splitter.addWidget(self.editor) #self.editor.setUtf8(True) #self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) #self.setCentralWidget(self.editor) #self.editor.setMarginLineNumbers(1, True) #self.editor.setAutoIndent(True) splitter.setStretchFactor(0, 1) splitter.setStretchFactor(1, 2) def on_open_file(self, file_path): print "file_path", file_path #file_path = self.model.filePath(modelIndex) self.editor.load_file(file_path) return fileInfo = QtCore.QFileInfo(file_path) ## check for directory if fileInfo.isDir(): self.emit(QtCore.SIGNAL("open_file"), None) self.editor.setText("") return source = self.main.ut.get_file_contents(fileInfo.filePath()) ## Allowed Extension if fileInfo.fileName() == 'Makefile': self.emit(QtCore.SIGNAL("open_file"), fileInfo.filePath()) self.editor.set_source(source, 'Makefile' ) #self.lexer = QsciLexerMakefile() #self.editor.setLexer(self.lexer) return extensions = ['java', 'html', 'py', 'pde', 'txt', 'yaml', 'sh', 'c','h','cpp','cxx', 'pl'] if not fileInfo.suffix() in extensions: self.emit(QtCore.SIGNAL("open_file"), None) self.editor.setText("") print "NOT SUPPORTED" return ## load file txt = self.main.ut.get_file_contents(fileInfo.filePath()) self.emit(QtCore.SIGNAL("open_file"), fileInfo.filePath()) #self.editor.set_source(txt) ## QsciLexerCPP, QsciLexerMakefile, QsciLexerJava, QsciLexerHTML, QsciLexerPerl, QsciLexerPython, QsciLexerYAML ## TODO MAkefile and show images print "YES>>", fileInfo.suffix(), fileInfo.fileName(), fileInfo.filePath() self.editor.set_source( txt, fileInfo.suffix())
class BoardsDialog(QtGui.QDialog): """ A dialog to display the different Arduino boards """ def __init__(self, parent, main): QtGui.QDialog.__init__(self, parent) self.main = main self.setWindowTitle("Boards") self.setWindowIcon(Icon(Ico.Boards)) self.setMinimumWidth(700) self.setMinimumHeight(500) mainLayout = QtGui.QVBoxLayout() m = 0 mainLayout.setContentsMargins(m, 10, m, m) mainLayout.setSpacing(0) self.setLayout(mainLayout) tabWidget = QtGui.QTabWidget() mainLayout.addWidget(tabWidget) ####################################### ## Tree ####################################### 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) self.editor = EditorWidget(self, self.main, arduino_mode=False) tabWidget.addTab(self.editor, "boards.txt") self.statusBar = QtGui.QStatusBar() mainLayout.addWidget(self.statusBar) self.load_file() 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 on_tree_clicked(self, item, col): pass def on_tree_double_clicked(self, item, col): pass
def on_open_project(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.Project), fileInfo.fileName()) self.mainTabWidget.setCurrentIndex(newTab)
class FileSystemBrowser(QtGui.QWidget): def __init__(self, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main mainLayout = QtGui.QVBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) splitter = QtGui.QSplitter() mainLayout.addWidget(splitter) ################################################### #### Toolbar #toolbar = QtGui.QToolBar(self) ## leftLayout = QtGui.QVBoxLayout() ################################################### #### Tree self.tree = FileSystemTree(self, self.main) self.connect(self.tree, QtCore.SIGNAL("open_file"), self.on_open_file) splitter.addWidget(self.tree) ################################################### #### Editor self.editor = EditorWidget(self, self.main, arduino_mode=False) splitter.addWidget(self.editor) #self.editor.setUtf8(True) #self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) #self.setCentralWidget(self.editor) #self.editor.setMarginLineNumbers(1, True) #self.editor.setAutoIndent(True) splitter.setStretchFactor(0, 1) splitter.setStretchFactor(1, 2) def on_open_file(self, file_path): print "file_path", file_path #file_path = self.model.filePath(modelIndex) self.editor.load_file(file_path) return fileInfo = QtCore.QFileInfo(file_path) ## check for directory if fileInfo.isDir(): self.emit(QtCore.SIGNAL("open_file"), None) self.editor.setText("") return source = self.main.ut.get_file_contents(fileInfo.filePath()) ## Allowed Extension if fileInfo.fileName() == 'Makefile': self.emit(QtCore.SIGNAL("open_file"), fileInfo.filePath()) self.editor.set_source(source, 'Makefile') #self.lexer = QsciLexerMakefile() #self.editor.setLexer(self.lexer) return extensions = [ 'java', 'html', 'py', 'pde', 'txt', 'yaml', 'sh', 'c', 'h', 'cpp', 'cxx', 'pl' ] if not fileInfo.suffix() in extensions: self.emit(QtCore.SIGNAL("open_file"), None) self.editor.setText("") print "NOT SUPPORTED" return ## load file txt = self.main.ut.get_file_contents(fileInfo.filePath()) self.emit(QtCore.SIGNAL("open_file"), fileInfo.filePath()) #self.editor.set_source(txt) ## QsciLexerCPP, QsciLexerMakefile, QsciLexerJava, QsciLexerHTML, QsciLexerPerl, QsciLexerPython, QsciLexerYAML ## TODO MAkefile and show images print "YES>>", fileInfo.suffix(), fileInfo.fileName( ), fileInfo.filePath() self.editor.set_source(txt, fileInfo.suffix())
class BoardsDialog(QtGui.QDialog): """ A dialog to display the different Arduino boards """ def __init__(self, parent, main): QtGui.QDialog.__init__(self, parent) self.main = main self.setWindowTitle("Boards") self.setWindowIcon(Icon(Ico.Boards)) self.setMinimumWidth(700) self.setMinimumHeight(500) mainLayout = QtGui.QVBoxLayout() m = 0 mainLayout.setContentsMargins(m, 10, m, m) mainLayout.setSpacing(0) self.setLayout(mainLayout) tabWidget = QtGui.QTabWidget() mainLayout.addWidget(tabWidget) ####################################### ## Tree ####################################### 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) self.editor = EditorWidget(self, self.main, arduino_mode=False) tabWidget.addTab(self.editor, "boards.txt") self.statusBar = QtGui.QStatusBar() mainLayout.addWidget(self.statusBar) self.load_file() 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 on_tree_clicked(self, item, col): pass def on_tree_double_clicked(self, item, col): pass
class BootLoadersDialog(QtGui.QDialog): 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_file(self): file_path = self.main.settings.hardware_path().append("programmers.txt") #source = self.main.ut.get_file_contents(file_path) self.editor.load_file(file_path) boot_loaders = self.main.ut.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 on_tree_clicked(self, item, col): pass def on_tree_double_clicked(self, item, col): pass
class ArduinoEditorWidget(QtGui.QWidget): def __init__(self, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main self.project_file_path = None self.project_settings_file = None self.project_settings = None mainLayout = QtGui.QHBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) ######################################### ## Editor/Terminal on left, Compiler Bar on right self.editorCompilerSplitter = QtGui.QSplitter(self) mainLayout.addWidget(self.editorCompilerSplitter, 20) self.editorCompilerSplitter.setOrientation(QtCore.Qt.Horizontal) #################################################### ## Editor at top, Terminal at bottom Splitter self.editorTerminalSplitter = QtGui.QSplitter(self) self.editorTerminalSplitter.setOrientation(QtCore.Qt.Vertical) self.editorCompilerSplitter.addWidget(self.editorTerminalSplitter) ######################################### ## Editor Widget self.editor = EditorWidget(self, self.main) self.editorTerminalSplitter.addWidget(self.editor) ######################################### ## Terminal Widget self.terminalWidget = TerminalWidget(self, self.main) self.editorTerminalSplitter.addWidget(self.terminalWidget) ############################################################## ### Arduino Compiler Bar self.arduinoCompilerBar = ArduinoCompilerBar(self, self.main) self.connect(self.arduinoCompilerBar, QtCore.SIGNAL("compile_action"), self.on_compile_action) self.connect(self.arduinoCompilerBar, QtCore.SIGNAL("project_settings_changed"), self.on_project_settings_changed) self.editorCompilerSplitter.addWidget(self.arduinoCompilerBar) ## Layout tweeks - TODO store thas in project self.editorCompilerSplitter.setStretchFactor(0, 2) self.editorCompilerSplitter.setStretchFactor(1, 0) self.editorTerminalSplitter.setStretchFactor(0, 5) self.editorTerminalSplitter.setStretchFactor(1, 2) ########################################## ## Load Project ########################################## def load_project(self, project_file_path, tabIndex=None): # checks its a file, then laods editor ## TODO - maybe check for .pde only self.project_file_path = None self.project_settings_file = None self.project_settings = None fileInfo = QtCore.QFileInfo(project_file_path) if fileInfo.isDir(): self.emit(QtCore.SIGNAL("open_file"), None) self.editor.setText("") self.lblFileName.setText("") self.lblFileSize.setText("") self.lblFileModified.setText("") ## TODO throw warning return self.project_file_path = fileInfo.filePath() self.project_settings_file = fileInfo.absolutePath().append( "/project_settings.yaml") self.load_project_settings() self.editor.load_file(self.project_file_path) self.arduinoCompilerBar.set_project(self.project_settings) ########################################## ## Compile Events ########################################## def on_compile_action(self, compile_action): print "on_compile_action", compile_action ## Save file if self.editor.save_file(): ## Set up compiler compiler = app.Compiler.Compiler(self) self.connect(compiler, QtCore.SIGNAL("compile_log"), self.terminalWidget.on_compile_log) dic = self.project_settings.copy( ) ## Dnnt know why, maybe a pass back is them not by red dic['file_path'] = self.project_file_path ## make, and only upload with "uplod_compile" if compile_action == 'compile' or compile_action == 'upload_compile': compiler.arduino_make_project(dic) if compile_action == 'upload' or compile_action == 'upload_compile': compiler.arduino_upload_project(dic) ########################################## ## Project Settings ########################################## def on_project_settings_changed(self, new_project_settings): self.project_settings = new_project_settings self.save_project_settings() def save_project_settings(self): yaml_string = yaml.dump(self.project_settings, Dumper=Dumper, default_flow_style=False) app.utils.write_file(self.project_settings_file, yaml_string) #print "project_settings_saved", self.project_settings, self.project_settings_file def load_project_settings(self): fileInfo = QtCore.QFileInfo(self.project_settings_file) if fileInfo.exists(): self.project_settings = app.utils.load_yaml( self.project_settings_file) else: self.project_settings = None #print "project_settings", self.project_settings
class BootLoadersDialog(QtGui.QDialog): 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_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 on_tree_clicked(self, item, col): pass def on_tree_double_clicked(self, item, col): pass
class ArduinoEditorWidget(QtGui.QWidget): def __init__(self, parent, main): QtGui.QWidget.__init__(self, parent) self.main = main self.project_file_path = None self.project_settings_file = None self.project_settings = None mainLayout = QtGui.QHBoxLayout() mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) self.setLayout(mainLayout) ######################################### ## Editor/Terminal on left, Compiler Bar on right self.editorCompilerSplitter = QtGui.QSplitter(self) mainLayout.addWidget(self.editorCompilerSplitter, 20) self.editorCompilerSplitter.setOrientation(QtCore.Qt.Horizontal) #################################################### ## Editor at top, Terminal at bottom Splitter self.editorTerminalSplitter = QtGui.QSplitter(self) self.editorTerminalSplitter.setOrientation(QtCore.Qt.Vertical) self.editorCompilerSplitter.addWidget(self.editorTerminalSplitter) ######################################### ## Editor Widget self.editor = EditorWidget(self, self.main) self.editorTerminalSplitter.addWidget(self.editor) ######################################### ## Terminal Widget self.terminalWidget = TerminalWidget(self, self.main) self.editorTerminalSplitter.addWidget(self.terminalWidget) ############################################################## ### Arduino Compiler Bar self.arduinoCompilerBar = ArduinoCompilerBar(self, self.main) self.connect(self.arduinoCompilerBar, QtCore.SIGNAL("compile_action"), self.on_compile_action) self.connect(self.arduinoCompilerBar, QtCore.SIGNAL("project_settings_changed"), self.on_project_settings_changed) self.editorCompilerSplitter.addWidget(self.arduinoCompilerBar) ## Layout tweeks - TODO store thas in project self.editorCompilerSplitter.setStretchFactor(0, 2) self.editorCompilerSplitter.setStretchFactor(1, 0) self.editorTerminalSplitter.setStretchFactor(0, 5) self.editorTerminalSplitter.setStretchFactor(1, 2) ########################################## ## Load Project ########################################## def load_project(self, project_file_path, tabIndex=None): # checks its a file, then laods editor ## TODO - maybe check for .pde only self.project_file_path = None self.project_settings_file = None self.project_settings = None fileInfo = QtCore.QFileInfo(project_file_path) if fileInfo.isDir(): self.emit(QtCore.SIGNAL("open_file"), None) self.editor.setText("") self.lblFileName.setText("") self.lblFileSize.setText("") self.lblFileModified.setText("") ## TODO throw warning return self.project_file_path = fileInfo.filePath() self.project_settings_file = fileInfo.absolutePath().append("/project_settings.yaml") self.load_project_settings() self.editor.load_file(self.project_file_path) self.arduinoCompilerBar.set_project(self.project_settings) ########################################## ## Compile Events ########################################## def on_compile_action(self, compile_action): print "on_compile_action", compile_action ## Save file if self.editor.save_file(): ## Set up compiler compiler = app.Compiler.Compiler(self) self.connect(compiler, QtCore.SIGNAL("compile_log"), self.terminalWidget.on_compile_log) dic = self.project_settings.copy() ## Dnnt know why, maybe a pass back is them not by red dic['file_path'] = self.project_file_path ## make, and only upload with "uplod_compile" if compile_action == 'compile' or compile_action == 'upload_compile': compiler.arduino_make_project(dic) if compile_action == 'upload' or compile_action == 'upload_compile': compiler.arduino_upload_project(dic) ########################################## ## Project Settings ########################################## def on_project_settings_changed(self, new_project_settings): self.project_settings = new_project_settings self.save_project_settings() def save_project_settings(self): yaml_string = yaml.dump(self.project_settings, Dumper=Dumper, default_flow_style=False) app.utils.write_file(self.project_settings_file, yaml_string) #print "project_settings_saved", self.project_settings, self.project_settings_file def load_project_settings(self): fileInfo = QtCore.QFileInfo(self.project_settings_file) if fileInfo.exists(): self.project_settings =app.utils.load_yaml(self.project_settings_file) else: self.project_settings = None #print "project_settings", self.project_settings