SOL4Py Sample: LabeledComboBox

SOL4Py Samples



#******************************************************************************
#
#  Copyright (c) 2018-2019 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#******************************************************************************

 
# 2018/05/01

# encodig: utf-8

import sys
import os
import traceback

import cv2
import errno

from PyQt5.QtWidgets import *
from PyQt5.QtGui     import *
from PyQt5.QtCore    import *

sys.path.append('../')

from SOL4Py.ZLabeledComboBox   import ZLabeledComboBox

# MainView class for Unit Test
  
class MainView(QMainWindow):
  def __init__(self, title, parent=None):
    super(MainView, self).__init__(parent)
    self.setWindowTitle(title)

    
    self.vbox = QWidget(self)
    self.vlayout = QVBoxLayout(self.vbox)
    self.vlayout.setAlignment(Qt.AlignTop)
    
    # Create labeled combobox in vbox.
    self.labeled_combobox = ZLabeledComboBox(self.vbox, "LabeledComboBox" )
    self.vlayout.addWidget(self.labeled_combobox)
  
    #self.vbox.setLayout(self.vlayout)
    self.labeled_combobox.setGeometry(0, 0, 160, 60)

    self.labeled_combobox.add_activated_callback(self.combobox_activated)
      
    self.labeled_combobox.set_label("Months")
    items = ["January", "Februaty", "March", "April", "May", "June", "July", 
             "August",  "September", "October", "November", "December"]
             
    self.labeled_combobox.add_items(items)
    
    self.setCentralWidget(self.vbox)
    self.show()

  def get_labeled_combobox(self):
    return self.labeled_combobox
    
  # comobobox activated callback. 
  def combobox_activated(self, text):
    print("MainView.combobox_activated:{}".format(text))
 
if __name__ == "__main__":   
  try:
    program = sys.argv[0]
    applet = QApplication(sys.argv)
    mainv = MainView(program)
    mainv.setGeometry(40, 40, 400, 200)
    mainv.show()
    
    applet.exec_()
  except:
    traceback.print_exc()
               

Last modified:28 Apr. 2019