Answer the question
In order to leave comments, you need to log in
Why does PyQt5 hang on Ubuntu 14.04?
Welcome all.
There are several homemade progs on PyQt5. Everything was fine under gentoo , but the computer broke down and I had to transfer to my wife's machine, where ubuntu 14.04 . I put all the modules and ... And none of my programs work.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
import warnings
import os
import lxml.etree as et
from PyQt5 import (QtCore, QtGui, uic, QtWidgets)
from PyQt5.QtWidgets import (QMainWindow, QTextEdit, QAction, QFileDialog, QApplication, QProgressBar)
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import *
warnings.filterwarnings("ignore")
cwd = os.path.expanduser('~')
filename = 'converter.ui'
filename = cwd + "/codding/Convert-fb2/" + filename
Form, Base = uic.loadUiType(filename)
class MyWindow(QtWidgets.QWidget, Form):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Form()
self.ui.setupUi(self)
self.timer = QBasicTimer()
self.step = 0
self.ui.btnQuit.clicked.connect(QCoreApplication.instance().quit)
self.ui.showd.clicked.connect(self.getfiles)
self.ui.btnConv.clicked.connect(self.convertfiles)
def getfiles(self):
fname = QFileDialog.getOpenFileName(self, "Open fb2", "/home/", "FictionBook Files (*.fb2)")[0]
if fname == '':
QFileDialog(self, quit())
with open(fname, 'r') as data:
data = data.read()
self.ui.textIn.setText(data)
self.ui.mylabel.setText('Input file: ' + fname)
global fout
fout = re.sub(r'\.fb2', '', fname)
fout = fout + '.txt'
with open(fname, 'rb') as f_in, open(fout, 'w') as f_out:
check = f_in.read()
tree = et.fromstring(check)
ns = {'ns': "http://www.gribuser.ru/xml/fictionbook/2.0"}
for bin_eb in tree.xpath('//ns:binary', namespaces=ns):
bin_eb.getparent().remove(bin_eb)
for bin_ed in tree.xpath('//ns:description', namespaces=ns):
bin_ed.getparent().remove(bin_ed)
global cleart, cleart2
cleart = et.tounicode(tree)
cleart = re.sub(r'\<[^>]*\>', '', cleart)
self.ui.textOut.setText(cleart)
def convertfiles(self):
if self.ui.textOut.toPlainText() == '' or self.ui.textIn.toPlainText() == '':
self.ui.textOut.setText('ОТКРОЙ ФАЙЛ!')
else:
cleart2 = self.ui.textOut.toPlainText()
self.ui.mylabel.setText('')
with open(fout, 'w') as f_out:
f_out.write(cleart2)
self.ui.mylabel.setText('Saved file: ' + fout)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.setWindowTitle("Ковертер Fb2 > Txt")
window.setWindowIcon(
QtGui.QIcon(cwd + "/codding/Convert-fb2/" + 'icon.png'))
window.show()
sys.exit(app.exec_())
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
import re
import sys
import warnings
import lxml.etree as et
from PyQt4 import (QtCore, QtGui, uic)
from PyQt4.QtGui import QIcon
from PyQt4.QtGui import QFileDialog
from PyQt4.QtCore import *
warnings.filterwarnings("ignore")
Form, Base = uic.loadUiType("/home/fil/codding/Convert-fb2/converter.ui")
class MyWindow(QtGui.QWidget, Form):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Form()
self.ui.setupUi(self)
self.timer = QBasicTimer()
self.step = 0
self.ui.btnQuit.clicked.connect(QCoreApplication.instance().quit)
self.ui.showd.clicked.connect(self.getfiles)
self.ui.btnConv.clicked.connect(self.convertfiles)
self.setGeometry(400, 200, 1000, 420)
def getfiles(self):
fname = QtGui.QFileDialog.getOpenFileName(self, "Open fb2", "/home/fil/", "FictionBook Files (*.fb2)")
print (fname)
with open(fname, 'r') as data:
data = data.read()
self.ui.textIn.setText(data)
self.ui.mylabel.setText('Input file: ' + fname)
global fout
fout = re.sub(r'\.fb2', '', fname)
fout = fout + '.txt'
with open(fname, 'rb') as f_in, open(fout, 'w') as f_out:
check = f_in.read()
tree = et.fromstring(check)
ns = {'ns': "http://www.gribuser.ru/xml/fictionbook/2.0"}
for bin_eb in tree.xpath('//ns:binary', namespaces=ns):
bin_eb.getparent().remove(bin_eb)
for bin_ed in tree.xpath('//ns:description', namespaces=ns):
bin_ed.getparent().remove(bin_ed)
global cleart, cleart2
cleart = et.tounicode(tree)
cleart = re.sub(r'\<[^>]*\>', '', cleart)
self.ui.textOut.setText(cleart)
def convertfiles(self):
cleart2 = self.ui.textOut.toPlainText()
self.ui.mylabel.setText('')
with open(fout, 'w') as f_out:
f_out.write(cleart2)
self.ui.mylabel.setText('Saved file: ' + fout)
print(fout)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
window = MyWindow()
window.setWindowTitle("Ковертер Fb2 > Txt")
window.setWindowIcon(
QtGui.QIcon('skull.png'))
window.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question