def restoreWindowState(self): # GUI settings history = util.readConfigString(GeneralConfig, "Url History", '')\ .split(',') self.characterCombo.insertItems(history) self.historyLength = util.readConfigInt(GeneralConfig, "History Length", 20) self.autoLookup = util.readConfigString(GeneralConfig, "Auto-Lookup clipboard", str(False)) != "False" self.autoLookupAction.setChecked(self.autoLookup) self.onlyAutoLookupCJKCharacters = util.readConfigString(GeneralConfig, "Auto-Lookup only Chinese characters", str(False)) != "False" self.splitterFrame.restoreState(QByteArray.fromBase64( str(util.readConfigString(GeneralConfig, "Splitter", "")))) self.splitterSizes = [int(i) for i \ in util.readConfigString(GeneralConfig, "Splitter sizes", "220,426").split(',')] self.toolbarOriginalState = QByteArray.fromBase64( str(util.readConfigString(GeneralConfig, "Toolbar original state", ""))) self.restoreState(self.toolbarOriginalState) self.menuBar().setVisible(True) self.characterChooser.setCurrentIndex(util.readConfigInt(GeneralConfig, "Toolbox current", 0)) visible = GeneralConfig.readEntry("Toolbox visibile", str(True)) if visible == "False": self.characterChooserOriginalVisibility = False else: self.splitterFrame.setSizes(self.splitterSizes) self.characterChooserOriginalVisibility = True self.characterChooser.setVisible( self.characterChooserOriginalVisibility) self.toggleToolboxAction.setChecked( self.characterChooserOriginalVisibility) w = util.readConfigInt(GeneralConfig, "Width", 640) h = util.readConfigInt(GeneralConfig, "Height", 420) self.defaultWindowSize = QSize(w, h) x = util.readConfigInt(GeneralConfig, "LastX", 0) y = util.readConfigInt(GeneralConfig, "LastY", 0) mini_w = util.readConfigInt(GeneralConfig, "Mini-mode Width", 400) mini_h = util.readConfigInt(GeneralConfig, "Mini-mode Height", 200) self.miniModeWindowSize = QSize(mini_w, mini_h) self.setGeometry(x, y, w, h)
def __init__(self): QWidget.__init__(self) self.tray = Tray(self) self.setMinimumSize(QSize(320, 200)) self.setWindowFlags(Qt.Popup|Qt.FramelessWindowHint) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setMargin(1) self.text = QTextBrowser(self) self.text.setReadOnly(True) self.text.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.text.setOpenExternalLinks(True) self.verticalLayout.addWidget(self.text) self.text.textChanged.connect(self.on_text_changed) self.notify = Notify(self) self.movie = QMovie() dev = QBuffer() dev.setData(QByteArray.fromBase64(CHECK_IMAGE)) dev.open(QBuffer.ReadOnly) dev.setParent(self.movie) self.movie.setDevice(dev) self.movie.frameChanged.connect(self.on_frame_changed) self.realized = False self.show()
def get_icon(data): image = QImage() bytearr = QByteArray.fromBase64(data) image.loadFromData(bytearr, "PNG") pixmap = QPixmap.fromImage(image) icon = QIcon() icon.addPixmap(pixmap) return icon
def load_pixmap(path, apply_mask=False): if image_data != None: data = QByteArray.fromBase64(image_data[path][1]) pixmap = QPixmap() pixmap.loadFromData(data, image_data[path][0]) else: absolute_path = os.path.join(get_resources_path(), path) pixmap = QPixmap(absolute_path) return pixmap
def readPicture(self, tree): """ Ließt das Charakterbild aus. """ pictureElement = tree.find("picture") if pictureElement is not None: imageData = QByteArray.fromBase64(str(pictureElement.text)) image = QPixmap() image.loadFromData(imageData, Config.CHARACTER_PIC_FORMAT) self.__character.picture = image
def setvalue(self, value): if self.savetofile and isinstance(value, basestring): self.filename = value if isinstance(value, QPixmap): self.widget.loadImage(value, fromfile=self.savetofile) return if self.tobase64 and value: value = QByteArray.fromBase64(value) self.widget.loadImage(value, fromfile=self.savetofile)
def try_image(value): _, extension = os.path.splitext(value) if extension[1:].lower() in supportedformats: if not os.path.exists(value): value = os.path.join(kwargs.get('imagepath', ''), value) return image_handler(key, value, imagetype='file') base64 = QByteArray.fromBase64(value) image = QPixmap() loaded = image.loadFromData(base64) if loaded: return image_handler(key, base64, imagetype='base64')
def bmp_to_pixmap(path): if image_data is not None: data = QByteArray.fromBase64(image_data[path][1]) pixmap = QPixmap() pixmap.loadFromData(data, image_data[path][0]) else: absolute_path = os.path.join(get_program_path(), path) pixmap = QPixmap(absolute_path) mask1 = pixmap.createMaskFromColor(QColor(0xFF, 0x00, 0xF0), Qt.MaskInColor) pixmap.setMask(mask1) return pixmap
def string_handler(key, value): global supportedformats if not supportedformats: supportedformats = [f.data() for f in QImageReader.supportedImageFormats()] base64 = QByteArray.fromBase64(value) image = QPixmap() loaded = image.loadFromData(base64) if loaded: return image_handler(key, base64, imagetype='base64') _, extension = os.path.splitext(value) if extension[1:] in supportedformats: return image_handler(key, value, imagetype='file') return value
def endSaveDocument(self, dataAsBaseSixFourString): self.documentData = QByteArray.fromBase64(dataAsBaseSixFourString) self.documentDataChanged.emit()
def leftSplitterState(): """ Resonable default for splitter state with primary widget on the left. @return QByteArray suitable for use with QSplitter.restoreState """ return QByteArray.fromBase64('AAAA/wAAAAAAAAACAAADQwAAAaUBAAAABgEAAAAB')
newFile.open(QIODevice.WriteOnly) newFile.write(reply.readAll()) newFile.close() print("done") reply.deleteLater() def read_data(reply): messageBuffer += reply.readAll() # ---- Main ---------------------------------------------------- # print(dir(manager)) #manager.finished.connect( handle_download ) # with a simple web page #url = "https://www.nextinpact.com/news/103770-google-annonce-android-o-liste-nouveautes-developer-preview-disponible.htm" #request_download(manager, url) # with an authenticated API request req_token = ask_for_token(api_id, api_secret) token_reply = manager.post(req_token[0], req_token[1]) #token_reply.finished.connect( # partial(self.handle_token, answer=token_reply)) token_reply.finished.connect( partial(self.handle_token, answer=token_reply)) bytarray = token_reply.readAll() print("bbibit", bytarray, dir(bytarray)) content = str(bytarray) parsed_content = json.loads(QByteArray.fromBase64(bytarray)) print(parsed_content)
def __init__(self, name, l, uid, new=False, parent=None): super(EditDialog, self).__init__(parent) self.name = name self.uid = uid self.l = l self.error = False self.image = None try: res = l.search_s( "uid={l:s},{dn:s}".format(l=uid, dn=ldap_dn), ldap.SCOPE_SUBTREE, "objectclass=*", ) edit_form = [] keys = res[0][1].keys() keys.sort() for key in keys: is_editable = True if key == jpegPhoto: jpeg = res[0][1][key][0] jpba = QByteArray.fromBase64(jpeg) self.image = QImage.fromData(jpba, "JPG") for not_edit in not_editable: if key == not_edit: is_editable = False edit_form.append((key+":", key, res[0][1][key], is_editable)) frameLayout = QVBoxLayout() editLayout = QHBoxLayout() iconLayout = QHBoxLayout() self.iconLabel = QLabel() if self.image is not None: self.iconLabel.setPixmap(QPixmap.fromImage(self.image)) buttonText = _("Change picture") else: buttonText = _("Insert picture") self.iconButton = QPushButton(buttonText) self.iconButton.setFocusPolicy(Qt.NoFocus) self.connect(self.iconButton, SIGNAL("clicked()"), self.editImage) iconLayout.addStretch() iconLayout.addWidget(self.iconLabel) iconLayout.addWidget(self.iconButton) iconLayout.addStretch() frameLayout.addLayout(iconLayout) width = 4 rowLayout = [] for i in range(width): rowLayout.append(QVBoxLayout()) editLayout.addLayout(rowLayout[i]) i = 0 self.result = [] for labeltext, key, text, is_editable in edit_form: if is_editable: is_single = False for single in single_value: if key == single: is_single = True if not is_single: text.append("") for t in text: leLayout = QHBoxLayout() label = QLabel(labeltext) edit = QLineEdit(t) leLayout.addWidget(label) leLayout.addWidget(edit) rowLayout[i].addLayout(leLayout) i += 1 if i == width: i = 0 self.result.append((key, edit, True)) else: self.result.append((key, text, False)) for i in range(width): rowLayout[i].addStretch() button2Layout = QHBoxLayout() button2Layout.addStretch() for text, slot, icon in ((_("Save"), self.close, "dialog-ok-apply.png"), (_("Cancel"), self.cancel, "dialog-cancel.png"), ): button = QPushButton(text) button.setFocusPolicy(Qt.NoFocus) if icon != "": button.setIcon(QIcon(os.path.join(imagespath,icon))) button2Layout.addWidget(button) self.connect(button, SIGNAL("clicked()"), slot) button2Layout.addStretch() frameLayout.addLayout(editLayout) layout = QVBoxLayout() layout.addLayout(frameLayout) layout.addLayout(button2Layout) self.setLayout(layout) self.setWindowTitle(self.name) except ldap.LDAPError, e: error_msg(self, _("LDAP Error"), e)
newFile.open(QIODevice.WriteOnly) newFile.write(reply.readAll()) newFile.close() print("done") reply.deleteLater() def read_data(reply): messageBuffer += reply.readAll() # ---- Main ---------------------------------------------------- # print(dir(manager)) #manager.finished.connect( handle_download ) # with a simple web page #url = "https://www.nextinpact.com/news/103770-google-annonce-android-o-liste-nouveautes-developer-preview-disponible.htm" #request_download(manager, url) # with an authenticated API request req_token = ask_for_token(api_id, api_secret) token_reply = manager.post(req_token[0], req_token[1]) #token_reply.finished.connect( # partial(self.handle_token, answer=token_reply)) token_reply.finished.connect(partial(self.handle_token, answer=token_reply)) bytarray = token_reply.readAll() print("bbibit", bytarray, dir(bytarray)) content = str(bytarray) parsed_content = json.loads(QByteArray.fromBase64(bytarray)) print(parsed_content)
def setvalue(self, value): if self.tobase64 and value and not isinstance(value, QPixmap): value = QByteArray.fromBase64(value) self.widget.loadImage(value)
def setvalue(self, value): if self.tobase64 and value: value = QByteArray.fromBase64(value) self.widget.loadImage(value)
def __init__(self, mainWindow, renderThread, pluginConfig=None): QWidget.__init__(self, mainWindow) self.mainWindow = mainWindow self.renderThread = renderThread self.pluginConfig = pluginConfig # set up UI self.setupUi(self) self.databaseUrl = None if self.pluginConfig: self.includeSimilar = util.readConfigString(self.pluginConfig, "Component include similar", str(True)) != "False" self.includeVariants = util.readConfigString(self.pluginConfig, "Component include variants", str(True)) != "False" self.databaseUrl = util.readConfigString(self.pluginConfig, "Update database url", None) splitterState = util.readConfigString(self.pluginConfig, "Component splitter", "") self.componentSplitter.restoreState(QByteArray.fromBase64( str(splitterState))) else: self.includeSimilar = True self.includeVariants = True if not self.databaseUrl: self.databaseUrl = unicode('sqlite:///' + util.getLocalData('dictionaries.db')) self.includeSimilarButton.setChecked(self.includeSimilar) self.includeVariantsButton.setChecked(self.includeVariants) self.componentViewScroll = 0 self.selectedComponents = [] self.language = None self.characterDomain = None # connect to main window self.connect(self.mainWindow, SIGNAL("settingsChanged()"), self.slotSettingsChanged) self.connect(self.mainWindow, SIGNAL("writeSettings()"), self.writeSettings) self.connect(self.renderThread, SIGNAL("jobFinished"), self.contentRendered) # connect to the widgets self.connect(self.includeVariantsButton, SIGNAL("clicked(bool)"), self.componentIncludeVariants) self.connect(self.includeSimilarButton, SIGNAL("clicked(bool)"), self.componentIncludeSimilar) self.connect(self.componentView, SIGNAL("linkClicked(const QUrl &)"), self.componentClicked) self.connect(self.componentView, SIGNAL("loadFinished(bool)"), self.componentViewLoaded) self.connect(self.componentResultView, SIGNAL("linkClicked(const QUrl &)"), self.componentResultClicked) self.connect(self.componentEdit, SIGNAL("textChanged(const QString &)"), self.componentEditChanged) self.componentView.page().setLinkDelegationPolicy( QWebPage.DelegateAllLinks) self.componentResultView.page().setLinkDelegationPolicy( QWebPage.DelegateAllLinks) self.initialised = False