class МойПервыйТаймерНаQt(QtCore.QObject):
def __init__(self):
super().__init__()
self.basictimer = QtCore.QBasicTimer()
self.basictimer.start(2000, self) # задержка в миллисекундах. 2000 для примера потому что 10 сек мне долго.
def timerEvent(self, QTimerEvent):
get_docs(self) # вы конечно можете создать обьект sched.scheduler и передавать его, но зачем?
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main_window = main_cl()
мой_первый_таймер_на_Qt = МойПервыйТаймерНаQt()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>373</height>
</rect>
</property>
<property name="windowTitle">
<string>Threading Demo</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_log_list">
<property name="text">
<string>Отчёт:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="list_log"/>
</item>
<item>
<widget class="QProgressBar" name="progress_bar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="buttons_layout">
<item>
<widget class="QPushButton" name="btn_stop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Стоп</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_start">
<property name="text">
<string>Старт</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
from PyQt4 import QtGui, uic
from PyQt4.QtCore import QThread, SIGNAL
import sys
import time
class xmlParserThread(QThread):
def __init__(self, xml):
QThread.__init__(self)
self.xml = xml
def __del__(self):
self.wait()
def run(self):
for x in range(25):
self.emit(SIGNAL('notify_progress(QString)'), str(x))
self.sleep(1)
class ThreadingDemo(QtGui.QMainWindow):
def __init__(self):
super(self.__class__, self).__init__()
uic.loadUi('design.ui', self)
self.btn_start.clicked.connect(self.start_getting_top_posts)
def start_getting_top_posts(self):
self.progress_bar.setMaximum(25)
self.progress_bar.setValue(0)
self.xml_parser_thread = xmlParserThread('some.xml')
self.connect(self.xml_parser_thread, SIGNAL("notify_progress(QString)"), self.notify_progress)
self.connect(self.xml_parser_thread, SIGNAL("finished()"), self.done)
self.xml_parser_thread.start()
self.btn_stop.setEnabled(True)
self.btn_stop.clicked.connect(self.xml_parser_thread.terminate)
self.btn_start.setEnabled(False)
def notify_progress(self, counter):
self.list_log.addItem(counter)
self.progress_bar.setValue(self.progress_bar.value() + 1)
def done(self):
self.btn_stop.setEnabled(False)
self.btn_start.setEnabled(True)
self.progress_bar.setValue(0)
QtGui.QMessageBox.information(self, "Done!", "Done parsing XML!")
def main():
app = QtGui.QApplication(sys.argv)
form = ThreadingDemo()
form.show()
app.exec_()
if __name__ == '__main__':
main()
>>> a = [('1', 'a', 'b', 'c'), ('2', 'x', 'y', 'z'), ('3', 'x', 'y', 'z')]
>>> b = [('a', 'b', 'c', 'd'), ('x', 'y', 'z', 'w'), ('x', 'y', 'z', 'w'), ('u', 'o', 'n', 'm')]
>>> new_list = lambda x, y: [i for i in x] + [i for i in y if i not in x]
>>> new_result = list(map(new_list, a, b))
>>> new_result
[['1', 'a', 'b', 'c', 'd'], ['2', 'x', 'y', 'z', 'w'], ['3', 'x', 'y', 'z', 'w']]
a = ['maz/2/arini', 'ya/16/streb', 'lovel/5/as']
max([int(''.join([c for c in i if c.isdigit()])) for i in a])
import string
translation = str.maketrans(string.digits, string.digits, string.ascii_letters + string.punctuation)
max([int(i.translate(translation)) for i in a])
import re
a = ['текст/1/текст', 'текст/3/текст', 'текст/2/текст']
maxi = 0
s = ''
for i in a:
u = int(re.findall(r'\d', i)[0])
if maxi < u:
maxi = u
s = i
print(s)
>>> a = [1,2,3,4,5]
>>> b = [str(i) for i in a]
>>> print(b)
['1', '2', '3', '4', '5']
query_a = "INSERT INTO table_a (value1, value2, value 3) VALUES (?, ?, ?)"
cur.execute(query_a, a[0])
last_id = cur.lastrowid
query_a = "INSERT INTO table_a (value1, value2, value 3) VALUES (?, ?, ?)"
cur.executemany(query_a, a)
cur.execute('SELECT last_insert_rowid()')
last_id = cur.fetchone()[0]
#Значения строки, столбца
row = mod_inx.row()
column = mod_inx.column()
#Значение id из dbtable_2
id_search = main_window.tableView_1.model().index(row, 2).data()
нужно поставить в начало функции а не в конец...query = "SELECT * FROM dbtable_2 WHERE id = " + str(id_search)
result_model.setQuery(query)
new_window = None
def new_form():
global new_window
new_window = uic.loadUi("interface2.ui")
new_window.setWindowTitle("New form")
new_window.show()
мой_список_окон = []
def new_form():
global мой_список_окон
new_window = uic.loadUi("interface2.ui")
new_window.setWindowTitle("New form")
new_window.show()
мой_список_окон.append(new_window)
def new_form(parent):
new_window = uic.loadUi("interface2.ui")
new_window.setWindowTitle("New form")
new_window.show()
new_window.setParent(parent)
import test2
main_window.pushButton.clicked.connect(lambda: test2.new_form(main_window))
def new_form(parent):
parent.new_window = uic.loadUi("interface2.ui")
parent.new_window.setWindowTitle("New form")
parent.new_window.show()
import test2
main_window.pushButton.clicked.connect(lambda: test2.new_form(main_window))
from itertools import chain
a = [('1',), ('2',)]
chain(*a) # Вернёт генератор, без необходимости выделять память под весь список
list(chain(*a)) # Если очень нужен список (скорее всего, это не так)