Skip to content

Instantly share code, notes, and snippets.

@nagos
Created August 28, 2010 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagos/555559 to your computer and use it in GitHub Desktop.
Save nagos/555559 to your computer and use it in GitHub Desktop.
Простой todo на PyQT4
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
item_count=10
class Todo(QtGui.QWidget):
'''Новый виджет Todo'''
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.items = []
self.checks = []
self.setGeometry(300, 300, 250, item_count*30+20)
for i in range(item_count):
self.items.append(QtGui.QLineEdit('Done this %d' % i, self))
self.checks.append(QtGui.QCheckBox('', self))
self.move_line(i,i)
self.connect(self.checks[i], QtCore.SIGNAL('stateChanged(int)'),
self.change_state)
def move_line(self, index, screen_index):
'''Сдвигает QCheckBox и QLineEdit в нужную позицию'''
self.items[index].move(40, 30*screen_index+10)
self.checks[index].move(10, 30*screen_index+15)
def change_state(self, value):
'''Обновляет позиции кнопок'''
screen_index = 0
for checked in (False,True):
for i in range(item_count):
if (self.checks[i].isChecked()==checked):
self.move_line(i, screen_index)
screen_index+=1
app = QtGui.QApplication(sys.argv)
todo = Todo()
todo.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment