예제 #1
0
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 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
예제 #3
0
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 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