def redirectOutput(): # If I write code such as sys.stdout = open('stdout.txt', 'w'), # I have to flush the file after writing to it (using "print" for example). # The following class saves the need to flush the file each time. class FlushedFile: """ Provides an output file that is immediately flushed after write """ def __init__(self, filepath): try: self.file = open(filepath, 'w') except Exception: self.file = None def write(self, str): if self.file == None: return self.file.write(str) self.file.flush() # Redirect stdout and stderr sys.stdout = FlushedFile( os.path.join(launchy.getScriptsPath(), 'stdout.txt')) sys.stderr = FlushedFile( os.path.join(launchy.getScriptsPath(), 'stderr.txt')) print "pylaunchy is up and running"
def cb_M_S_CR(self, inputDataList, catItem): """ open the selected item with gvim.exe """ subprocess.Popen('start gvim.exe --remote-tab-silent "%s"' % os.path.join(launchy.getScriptsPath(), "Thruster.py"), shell=True)
def __init__(self): super(LaunchySQLite, self).__init__() self.name = "SQLite" self.hash = launchy.hash(self.name) self.icon = os.path.join(launchy.getIconsPath(), "pysimple.png") script_path = launchy.getScriptsPath() config_filename = os.path.join(script_path, "sqlite_config.json") self.config = read_json(config_filename) self.database_filename = self.config["database"] self.conn = None
def redirectOutput(): # If I write code such as sys.stdout = open('stdout.txt', 'w'), # I have to flush the file after writing to it (using "print" for example). # The following class saves the need to flush the file each time. class FlushedFile: """ Provides an output file that is immediately flushed after write """ def __init__(self, filepath): try: self.file = open(filepath, 'w') except Exception: self.file = None def write(self, str): if self.file == None: return self.file.write(str) self.file.flush() # Redirect stdout and stderr sys.stdout = FlushedFile(os.path.join(launchy.getScriptsPath(), 'stdout.txt')) sys.stderr = FlushedFile(os.path.join(launchy.getScriptsPath(), 'stderr.txt')) print "pylaunchy is up and running"
sys.stdout = FlushedFile(os.path.join(launchy.getScriptsPath(), 'stdout.txt')) sys.stderr = FlushedFile(os.path.join(launchy.getScriptsPath(), 'stderr.txt')) print "pylaunchy is up and running" def setSettingsObject(): # Set the launchy.settings object try: # Based on http://lists.kde.org/?l=pykde&m=108947844203156&w=2 from sip import wrapinstance, unwrapinstance from PyQt4 import QtCore launchy.settings = wrapinstance(launchy.__settings, QtCore.QSettings) except ImportError, inst: print >> sys.stderr, inst except NameError: print >> sys.stderr, "Could not find __settings object" except Exception, inst: print >> sys.stderr, inst redirectOutput() # Add the '<Launchy>\plugins\python' directory to module path sys.path.insert( 0, os.path.realpath( launchy.getScriptsPath() ) ) # Add the '<Launchy>\plugins\python\lib' directory to module path sys.path.insert( 0, os.path.realpath( launchy.getLibPath() ) ) setSettingsObject()
sys.stderr = FlushedFile( os.path.join(launchy.getScriptsPath(), 'stderr.txt')) print "pylaunchy is up and running" def setSettingsObject(): # Set the launchy.settings object try: # Based on http://lists.kde.org/?l=pykde&m=108947844203156&w=2 from sip import wrapinstance, unwrapinstance from PyQt4 import QtCore launchy.settings = wrapinstance(launchy.__settings, QtCore.QSettings) except ImportError, inst: print >> sys.stderr, inst except NameError: print >> sys.stderr, "Could not find __settings object" except Exception, inst: print >> sys.stderr, inst redirectOutput() # Add the '<Launchy>\plugins\python' directory to module path sys.path.insert(0, os.path.realpath(launchy.getScriptsPath())) # Add the '<Launchy>\plugins\python\lib' directory to module path sys.path.insert(0, os.path.realpath(launchy.getLibPath())) setSettingsObject()