Python

QThread

PyQtに実装されてある非同期処理です。 import sys from PyQt4 import QtCore from PyQt4 import QtGui class Worker(QtCore.QThread): mutex = QtCore.QMutex() def __init__(self, name = "", parent = None): QtCore.QThread.__init__(self, parent) self…

threading.semaphore

semaphore排他オブジェクトです。 threading.Semaphoreとthreading.BoundedSemaphoreがあります。 import time import thread import threading import random counter = 0 counter = 0 def semaphore_func(semaphore): with semaphore: thread_func() globa…

threading.Condition

Conditionという排他オブジェクトです。 import time import threading class MyThread(threading.Thread): lock = threading.Lock() def __init__(self, name, lifetime, condition): threading.Thread.__init__(self) self.lifetime = lifetime self.condi…

threading.Event

1回書いたのに記事が消えてしまった・・・ソースだけ貼って寝よう import time import thread import threading end_count = 3 def thread_func(event, counter): time.sleep(2) while len(counter) < end_count: while not event.isSet(): print "wait result:…

threading.Lock

うちの64bitパチコンだとpyscripterの挙動がおかしいよ。結構まえからいろいろおかしかったのでインストールし直したけどなんかダイアログ出てきて開けなくなったので(前はどうにかして開けるようにした)、めんどくさいので諦めて、Spyderで書いてます。thre…

QProgressBar

import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() # create layout self.vbox = QtGui.QVBoxLayout(self) # #self.vbox.setSizeConstraint(QtGui.QLayout.SetMaximumSize) #…

QCheckBox

import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.cb = QtGui.QCheckBox('&Show title', self) self.cb.move(20, 20) # 状態を3つに増やす self.cb.setTristate() # s…

QSlider

import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() # mainlayout hbox = QtGui.QVBoxLayout(self) # background self.bgColor = QtGui.QColor(0, 0, 0) self.bg = QtGui.QFra…

QAbstractSlider

import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() # create components self.lcd = QtGui.QLCDNumber(self) self.lcd.setBaseSize(100, 100) self.sldh = QtGui.QSlider(QtC…

PyScripter exceptions.AttributeError

自動補完機能が付いてる便利なPythonIDE PyScripterを使っててエラーが出た。 PyQt4のクラスを補完してくれるようにパスを通そうとしてたところ、 Ctrl+Spaceでリストボックス出すと Traceback (most recent call last): File "D:\Python27\Lib\inspect.py",…

IDLE便利

Pythonインストールしたときに付属して付いてくるIDLEというエディタ形開発環境があるのだが、 これは便利。 F5押せば実行結果が別ウィンドウで確認できるし、対話型モードもその別ウィンドウ上ですぐ実行できる。 使い方のドキュメントなど読まなくてもすぐ…

Python始めてみます

インタプリタ言語あるいはダイナミック言語っていうのかな? コンパイルなどしないで気軽にデータを作成したり、編集したりできる。 ゲーム開発を行うときに、様々な外部データを扱いやすくしたものをこういった言語で作成したりするので、 何か覚えておこう…