# -*- coding:utf-8 -*- import sys from PyQt5 import QtCore from PyQt5.QtWidgets import QCalendarWidget, QLabel, QDialog class CalendarDialog(QDialog): def __init__(self, _parent): super(CalendarDialog, self).__init__(_parent) self.setModal(True) self.cal = QCalendarWidget(self) self.initUI() self.adjustSize() self.setFixedSize(self.width(), self.height()) self.selectedDate = None def initUI(self): self.cal.setGridVisible(True) self.cal.move(20, 20) self.cal.clicked[QtCore.QDate].connect(self.showDate) self.lbl = QLabel(self) date = self.cal.selectedDate() self.lbl.setText(date.toString()) self.lbl.move(20, 200) self.setWindowTitle('Calendar') self.show() def showDate(self, date): self.lbl.setText(date.toString()) self.close() def main(): app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()
2018년 11월 21일 수요일
[QGIS3] QCalendarWidget
[PyQt5] QWidgetAction sample
# -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QWidgetAction, QMenu class Example(QMainWindow): def __init__(self): super().__init__() self.toolbar = self.addToolBar('Toolbar') self.widgetAction = QWidgetAction(self.toolbar) self.menu = QMenu(self.toolbar) self.action1 = self.menu.addAction('action1') self.action2 = self.menu.addAction('action2') self.widgetAction.setText('demo') self.widgetAction.setMenu(self.menu) self.toolbar.addAction(self.widgetAction) self.action1.triggered.connect(self.onAction1) self.action2.triggered.connect(self.onAction2) self.widgetAction.triggered.connect(self.triggered) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('Toolbar') def triggered(self, e): if self.widgetAction.text() == 'onAction1': self.action1.trigger() elif self.widgetAction.text() == 'onAction2': self.action2.trigger() def onAction1(self): print('onAction1') self.widgetAction.setText('onAction1') def onAction2(self): print('onAction2') self.widgetAction.setText('onAction2') if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() ex.show() sys.exit(app.exec_())
2018년 11월 14일 수요일
[PyQt5] QListWidget demo
# !-*- coding:utf-8 -*- import os import sys from PyQt5 import uic from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog, QApplication, QListWidgetItem # ui 파일명과 소스 파일명 동일하게 저장(_name, _ext) = os.path.splitext(os.path.basename(__file__)) _ui_path = os.path.join('./', _name + '.ui') FORM_CLASS, _ = uic.loadUiType(_ui_path) class DemoListWidget(QDialog, FORM_CLASS): """ https://doc.qt.io/qt-5/qlistwidget.html https://doc.qt.io/qt-5/qlistwidgetitem.html """ def __init__(self): super().__init__() self.setupUi(self) # ListWidget 에 데이터 추가. self._init_data() self.listWidget.currentItemChanged.connect(self.cb_currentItemChanged) self.listWidget.currentRowChanged.connect(self.cb_currentRowChanged) self.listWidget.currentTextChanged.connect(self.cb_currentTextChanged) self.listWidget.itemActivated.connect(self.cb_itemActivated) self.listWidget.itemChanged.connect(self.cb_itemChanged) self.listWidget.itemClicked.connect(self.cb_itemClicked) def _init_data(self): _item = QListWidgetItem() _item.setData(Qt.DisplayRole, 'hello') _item.setData(Qt.UserRole, 'world') # checkbox 플래그 설정. _item.setFlags(_item.flags() | Qt.ItemIsUserCheckable) # checkbox 초기값 설정 Qt.Unchecked : 0, Qt.PartiallyChecked : 1, Qt.Checked : 2 _item.setCheckState(Qt.Unchecked) # 위젯에 아이템 추가. self.listWidget.addItem(_item) def cb_currentItemChanged(self, _current, _previous): print('cb_currentItemChanged') def cb_currentRowChanged(self, _currentRow): print('cb_currentRowChanged') def cb_currentTextChanged(self, _currentText): print('cb_currentTextChanged') def cb_itemActivated(self, _item): print('cb_itemActivated') def cb_itemChanged(self, _item): """ 체크박스를 체크, 해제 했을 때 호출됨. :param _item: :return: """ # hello 출력 print(_item.text()) # hello 출력 print(_item.data(Qt.DisplayRole)) # world 출력 print(_item.data(Qt.UserRole)) # 체크 해제 : 0, 체크 : 1 print(_item.checkState()) # 아이템의 row num _row = self.listWidget.row(_item) print(_row) # 아이템 수 print(self.listWidget.count()) # 아이템 제거. _taken_item = self.listWidget.takeItem(_row) # 아이템 수 print(self.listWidget.count()) def cb_itemClicked(self, _item): print('cb_itemClicked') def main(): app = QApplication(sys.argv) dialog = DemoListWidget() dialog.show() app.exec_() if __name__ == '__main__': main()
2018년 11월 5일 월요일
2018년 10월 26일 금요일
[QGIS3] 컨텍스트 메뉴 비활성화
iface.mainWindow().setContextMenuPolicy(0)
[QGIS3] SHP -> PostgreSQL
type(l)
<class 'qgis._core.QgsVectorLayer'>
for _f in l.fields():
type(l)
for _cnt, i in enumerate(l.getFeatures()):
print(_cnt, i, i.gemetry())
g = QgsGeometry()
g.asWkb()
2018년 10월 25일 목요일
[PyQt5] QToolButton example
#!/usr/bin/env python# -*- coding:utf-8 -*-import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidgetAction, QAction, QToolButton
FORM_CLASS, _ = uic.loadUiType('./ui/main.ui')
class MainForm(QMainWindow, FORM_CLASS):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.toolbar = self.addToolBar(u'툴바')
self._ac1 = QAction(u'액숀1', self)
self._ac1.triggered.connect(self._action_01)
self._ac2 = QAction(u'액숀2', self)
self._ac2.triggered.connect(self._action_02)
self._tb1 = QToolButton(self)
self._tb1.addAction(self._ac1)
self._tb1.addAction(self._ac2)
self._tb1.setPopupMode(QToolButton.InstantPopup)
self._tb1.setDefaultAction(self._ac1)
self.toolbar.addWidget(self._tb1)
def _action_01(self):
self._tb1.setDefaultAction(self._ac1)
def _action_02(self):
self._tb1.setDefaultAction(self._ac2)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainForm()
w.show()
sys.exit(app.exec())
2018년 10월 17일 수요일
[QGIS3] geom to geometry
wkb = bytes.fromhex("010100000000000000000045400000000000001440")
g.fromWkb(wkb)
g.get().x()
42.0
g.get().y()
5.0
2018년 10월 16일 화요일
[QGIS3] 모든 레이어 조회
_layer = _temp.layer()
2018년 7월 9일 월요일
[Python] Python 에서 java 호출
#!/usr/bin/env python# -*- coding:utf-8 -*- import jpype if __name__ == '__main__': classpath = './jar/whoareyou.jar' jpype.startJVM(jpype.getDefaultJVMPath(), '-ea', "-Djava.class.path=%s" % classpath) WhoAreYou = jpype.JClass("kr.co.demo.WhoAreYou") obj = WhoAreYou() ret = obj.whatyourname('hello') print ret WhoAreYou2 = jpype.JPackage("kr").co.demo.WhoAreYou obj2 = WhoAreYou() ret = obj.whatyourname('world') print ret jpype.shutdownJVM()
2018년 6월 21일 목요일
python logging
import logging
logger = logging.getLogger('tornado.general')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter([%(levelname)s | %(asctime)s | %(filename):%(lineno)04s | %(message)s")
fileHandler = logging.handlers.RotatingFileHandler(filename='', maxBytes=1, backupCount=1)
fileHandler.setFormatter(formatter)
fileHandler.set_name('myname')
logger.addHandler(fileHandler)
logger = logging.getLogger('tornado.general')
hs = logger.handlers[:]
for x in hs:
if x.name == 'myname':
logger.handlers.remove(x)
2018년 6월 20일 수요일
python decode mime
import email
import base64
def decode_mime(_msg, _result=[]):
def _decode(msg, result):
if msg.is_multipart():
for item in msg.get_payload():
_decode(item, result)
else:
if 'content-type' in msg:
_content_type = msg['content-type']
if 'text/html' in _content_type:
decoded_text = base64.decodestring(msg.get_payload())
result.append(decoded_text)
_decode(_msg, _result)
decode_mime(email.message_from_string(_message), result=[])
python HTMLParser
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init(self)
self.result = list()
def handle_date(self, data):
if data is not None:
self.result.append(data)
obj = MyHTMLParser()
obj.feed(html)
print ' '.join(obj.result)
2018년 5월 28일 월요일
Tornado 에서 static 파일 (javascript, css) 경로 설정
Tornado
|- static
|- script (javascript)
|- styles (css)
|- templates
|- index.html
========= python 소스 ====================================
import os
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
(r"/(.*)", tornado.web.StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), 'static')}),
],
template_path=os.path.join(os.path.dirname(__file__), "templates"))
if __name__ == '__main__':
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
========= index.html ====================================
docker redmine 설치
docker-composer.yml version: '3.1' services: redmine: image: redmine restart: always container_na...
-
용량이 큰 파일 업로드 시 net::ERR_CONNECTION_RESET 오류 발생할 경우. http_server = tornado.httpserver.HTTPServer(app, max_buffer_size=10485760000) upload_for...
-
docker-composer.yml version: '3.1' services: redmine: image: redmine restart: always container_na...
-
# !-*- coding:utf-8 -*- import os import sys from PyQt5 import uic from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog , QAppl...