def getContent(path): file = QFile(path) if not file.open(QIODevice.ReadOnly | QIODevice.Text): return ts = QTextStream(file) ts.setCodec("UTF-8") res = ts.readAll() return res
def testConstruction(self): '''QTextStream construction''' obj = QTextStream() self.assertEqual(obj.codec(), QTextCodec.codecForLocale()) self.assertEqual(obj.device(), None) self.assertEqual(obj.string(), None) self.assertTrue(obj.atEnd()) self.assertEqual(obj.readAll(), '')
def testConstruction(self): """QTextStream construction""" obj = QTextStream() self.assertEqual(obj.codec(), QTextCodec.codecForLocale()) self.assertEqual(obj.device(), None) self.assertEqual(obj.string(), None) self.assertTrue(obj.atEnd()) self.assertEqual(obj.readAll(), "")
def javaInclude(context, engine): fileName = context.argument(0).toString() scriptFile = QFile("commands/" + fileName) if not scriptFile.open(QIODevice.ReadOnly): return -1 stream = QTextStream(scriptFile) s = stream.readAll() # QString scriptFile.close() parent = context.parentContext() # QScriptContext* if parent != 0: context.setActivationObject(context.parentContext().activationObject()) context.setThisObject(context.parentContext().thisObject()) result = engine.evaluate(s) #TODO/PORT/FIXME# what's this for? return 0
def javaInclude(context, engine): fileName = context.argument(0).toString() scriptFile = QFile("commands/" + fileName) if not scriptFile.open(QIODevice.ReadOnly): return -1 stream = QTextStream(scriptFile) s = stream.readAll() # QString scriptFile.close() parent = context.parentContext() # QScriptContext* if parent != 0: context.setActivationObject(context.parentContext().activationObject()) context.setThisObject(context.parentContext().thisObject()) result = engine.evaluate(s) #TODO/PORT/FIXME# what's this for? return 0
def load_stylesheet(pyside=True): f = QFile(":petfactoryStyle/style.qss") if not f.exists(): pass else: f.open(QFile.ReadOnly | QFile.Text) ts = QTextStream(f) stylesheet = ts.readAll() if platform.system().lower() == 'darwin': # see issue #12 on github mac_fix = ''' QDockWidget::title { background-color: #353434; text-align: center; height: 12px; } ''' stylesheet += mac_fix return stylesheet
def load_stylesheet(theme, pyside=True): """ Loads the stylesheet. Takes care of importing the rc module. :param pyside: True to load the pyside rc file, False to load the PyQt rc file :return the stylesheet string """ if theme == 'darkstyle': import themes.darkstyle.pyside_style_rc elif theme == 'robotstyle': import themes.robotstyle.pyside_style_rc from PySide.QtCore import QFile, QTextStream basedir = os.path.abspath(os.path.dirname(__file__)) localPath = "%s/style.qss" % theme f = QFile( os.path.join(basedir, localPath)) if not f.exists(): _logger().error("Unable to load stylesheet, file not found in " "resources") return "" else: f.open(QFile.ReadOnly | QFile.Text) ts = QTextStream(f) stylesheet = ts.readAll() # if platform.system().lower() == 'darwin': # see issue #12 on github # mac_fix = ''' # QDockWidget::title # { # background-color: #353434; # text-align: center; # height: 10px; # } # ''' # stylesheet += mac_fix return stylesheet