2018년 11월 21일 수요일

[QGIS3] QCalendarWidget

# -*- 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()

[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()

docker redmine 설치

docker-composer.yml version: '3.1' services:      redmine:           image: redmine           restart: always           container_na...