본문 바로가기
Python

python singleton instance with qwindow

by GGoris 2018. 6. 6.
반응형

단일 창을 활용하고 싶을 때,


싱클턴 클래스 작성

class SingletonInstance:
__instance = None

@classmethod
def get_Instance(self):
return self.__instance

@classmethod
def instance(self):
print("instance")
if self.__instance ==None:
self.__instance = self()
else:
self.instance = self.get_Instance

return self.__instance
class ChartWindow(QMainWindow, SingletonInstance):
def __init__(self):
super().__init__()
self.setupUi(self)
self.kiwoom = KiwoomApi()

def __del__(self):
self.__instance = None
싱클턴 클래스를 상속 받아 활용.



self.chart_window = ChartWindow.instance()













반응형

'Python' 카테고리의 다른 글

정규식  (0) 2015.02.03
파이썬 한글 유니코드 변환 에러  (0) 2014.12.30
파이썬 연산자  (0) 2014.12.29
파이썬 수치자료형  (0) 2014.12.25
파이썬 제어문  (0) 2014.12.23

댓글