def H_loadLayout(widgetApp, editor, aDefautPathMgr, nameLayout): if nameLayout == "": log.info("not layout file specified") widgetApp.resize(500, 500) widgetApp.move(100, 100) return afile = editor.layout_file(nameLayout) if not DiskUtils.is_file_exist(afile): afile = aDefautPathMgr.getDefaultLayoutFile() if not DiskUtils.is_file_exist(afile): log.debug("cannot find the layout file %s" % afile) widgetApp.resize(500, 500) widgetApp.move(100, 100) return settings = QtT.QtCore.QSettings(afile, QtT.QtCore.QSettings.IniFormat, None) if DO_PYQT4: widgetApp.resize(settings.value('MainWindow/size').toSize()) widgetApp.move(settings.value('MainWindow/pos').toPoint()) widgets = list( map(str, settings.value('MainWindow/widgets').toStringList())) for w in widgets: className = str(settings.value('%s/className' % w).toString()) widgetApp.toolInstanciate(className, w) widgetApp.restoreState( settings.value('MainWindow/state').toByteArray()) for w in widgets: if w in widgetApp._docksWidget: widgetApp._docksWidget[w].getCustomWidget().resize( settings.value('%s/size' % w).toSize()) isFloating = settings.value('%s/floating' % w).toBool() if isFloating: widgetApp._docksWidget[w].getCustomWidget().move( settings.value('%s/pos' % w).toPoint()) else: widgetApp.resize(settings.value('MainWindow/size')) widgetApp.move(settings.value('MainWindow/pos')) widgets = settings.value('MainWindow/widgets') if widgets != None: for w in widgets: className = str(settings.value('%s/className' % w)) widgetApp.toolInstanciate(className, w) widgetApp.restoreState(settings.value('MainWindow/state')) for w in widgets: if w in widgetApp._docksWidget: widgetApp._docksWidget[w].getCustomWidget().resize( settings.value('%s/size' % w)) isFloating = settings.value('%s/floating' % w) if isFloating: widgetApp._docksWidget[w].getCustomWidget().move( settings.value('%s/pos' % w))
def getChildByName(self, key): """ from a name find a node in the task node ... the result is cache for futher query """ if key in self.__Cache: return self.__Cache[key] for cn in self.getChildren(): if cn.getName() == key: self.__Cache[key] = cn return cn log.debug("getChildByName: node %r not found" % key) return None
def send_mail(sendFrom, sendTo, subject, text, files=[], sendCc=[], sendBcc=[], authName=None, authPass=None): """ quick and easy utility function to send email from any system via a python interface. """ import mimetypes import smtplib import os from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.Utils import formatdate from email import Encoders import getpass assert type(sendTo) == list assert type(sendCc) == list assert type(sendBcc) == list assert type(files) == list addressEmailSuffix = initDefault.EMAIL_SUFFIX if '@' not in sendFrom: sendFrom += addressEmailSuffix for i in range(len(sendTo)): if '@' not in sendTo[i]: sendTo[i] += addressEmailSuffix for i in range(len(sendCc)): if '@' not in sendCc[i]: sendCc[i] += addressEmailSuffix for i in range(len(sendBcc)): if '@' not in sendBcc[i]: sendBcc[i] += addressEmailSuffix msg = MIMEMultipart() msg['From'] = sendFrom msg['To'] = ', '.join(sendTo) if len(sendCc) > 0: msg['Cc'] = ', '.join(sendCc) if len(sendBcc) > 0: msg['Bcc'] = ', '.join(sendBcc) msg['Date'] = formatdate(localtime=True) msg['Realname'] = getpass.getuser() msg['Subject'] = subject msg.attach(MIMEText(text)) # attach files as mime parts for f in files: if DiskUtils.is_file_exist(f): ftxt = f.replace(".log", ".txt") mimeType = mimetypes.guess_type(ftxt)[0] mimeTuple = ('application', 'octet-stream') if mimeType is not None: mimeTuple = tuple(mimeType.split('/')) part = MIMEBase(mimeTuple[0], mimeTuple[1]) part.set_payload(open(f, "rb").read()) Encoders.encode_base64(part) part.add_header( 'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) msg.attach(part) log.debug("sending email from %s to %s" % (sendFrom, sendTo)) smtp = smtplib.SMTP(initDefault.SERVER_EMAIL_NAME) if authName is not None and authPass is not None: smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login(authName, authPass) smtp.sendmail(sendFrom, sendTo + sendCc + sendBcc, msg.as_string()) smtp.close()