def setArrow(self): arrowSize = SETLEVEL["ARROW_SIZE"] levelImageOffTop = 300 coordX, coordY = self.width / 2, levelImageOffTop self.rArrow = ImageButton(self.arrowImgRight, (arrowSize, arrowSize), (coordX + 80, coordY - 10)) self.lArrow = ImageButton( pygame.transform.flip(self.arrowImgRight, True, True), (arrowSize, arrowSize), (coordX - 80, coordY - 10))
def setupUi(self): self.resize(300, 200) self.setStyleSheet("background-color: #424242;") self.pixmap = QPixmap("./pixmap.png") self.pixmap_hover = QPixmap("pixmap_hover.png") self.pixmap_pressed = QPixmap("pixmap_pressed.png") self.text="My Text" self.btn= ImageButton(self.pixmap,self.pixmap_hover,self.pixmap_pressed,self) self.btn.setText(self.text) self.btn.clicked.connect(self.myclick) self.btn.setSize(10, 10, 150, 30)
def add_picture(self, picture_path): # Create new picture button im = ImageButton(source=picture_path) # Old pictures layout management self.nb_pictures = self.nb_pictures + 1 if self.nb_pictures > max_pictures_in_bottom_layout: self.layout_bottom.remove_widget( self.layout_bottom.children[len(self.layout_bottom.children) - 1]) # Connecting on_press signal im.bind(on_press=self.display_picture_on_popup) # Adding new widget in old pictures layout self.layout_bottom.add_widget(im)
def display_picture_on_popup(self, instance): # Main popup layout layout_popup = BoxLayout(orientation='vertical', spacing=5) # Create popup layout content back_to_main_button = Button(text='<-', size_hint=(.2, .2)) # Adding contents into popup layout layout_popup.add_widget(back_to_main_button) layout_popup.add_widget(ImageButton(source=instance.source)) # Create popup popup = Popup(title='', separator_height=0, content=layout_popup) # Bind the on_press event of the button to the dismiss function back_to_main_button.bind(on_press=popup.dismiss) # Open popup popup.open()
def build(self): self.nb_pictures = 0 # PROPOSAL 1 self.layout = BoxLayout(orientation='horizontal') ######################################## # LAYOUT PHOTOS ######################################## # Main photos layout for pictures display layout_photos = BoxLayout(orientation='vertical', spacing=5) # Last photo layout declaration self.last_photo = ImageButton(source='small_pictures/last_photo.jpg') # Connecting on_press signal self.last_photo.bind(on_press=self.display_picture_on_popup) # Layout containing max_pictures_in_bottom_layout pictures cols = int(max_pictures_in_bottom_layout / max_row_number_for_old_photos) self.layout_bottom = GridLayout(cols=cols, spacing=(5, 5)) # Adding sublayouts/widgets in the layout_photos layout_photos.add_widget(self.last_photo) layout_photos.add_widget(self.layout_bottom) ######################################## # LAYOUT BUTTONS ######################################## # Main button layout for pictures manipulations layout_buttons = BoxLayout(orientation='vertical', size_hint_x=.33) # Shortcut layout declaration one_photo_default_picture = ImageButton( source='small_pictures/default_1.jpg') one_photo_button = Button(text='Prendre 1 photo', size_hint=(1, .3)) four_photo_default_picture = ImageButton( source='small_pictures/default_2.jpg') four_photo_button = Button(text='Prendre 4 photos', size_hint=(1, .3)) # Adding widgets in the layout_photos layout_buttons.add_widget(one_photo_default_picture) layout_buttons.add_widget(one_photo_button) layout_buttons.add_widget(four_photo_default_picture) layout_buttons.add_widget(four_photo_button) # Shorcuts buttons clicked connections one_photo_default_picture.bind(on_press=self.take1) one_photo_button.bind(on_press=self.take1) four_photo_default_picture.bind(on_press=self.take4) four_photo_button.bind(on_press=self.take4) ######################################## # GENERAL ######################################## # Adding photos layout in the main layout self.layout.add_widget(layout_buttons) # Adding photos layout in the main layout self.layout.add_widget(layout_photos) ######################################## # APP ######################################## # Load application self.load() return self.layout
def __init__(self,parent): super(ImageViewerWidget, self).__init__(parent) self.parent=parent self.capture_image=None self.iscapture_image=False self.camera_fps= 0.5 self.fittowindow= False self.printer = QPrinter() self.scaleFactor = 0.0 self.isplay= False self.ispreview=False self.isexit=False self.scaleFactor = 1.0 self.imageLabel = QLabel(self) self.imageLabel.setBackgroundRole(QPalette.Base) self.imageLabel.setSizePolicy(QSizePolicy.Ignored,QSizePolicy.Ignored) self.imageLabel.setScaledContents(True) self.scrollArea = QScrollArea(self) self.scrollArea.setHorizontalScrollBarPolicy( Qt.ScrollBarAlwaysOff ) self.scrollArea.setVerticalScrollBarPolicy( Qt.ScrollBarAlwaysOff ) self.scrollArea.setBackgroundRole(QPalette.Dark) self.scrollArea.setWidget(self.imageLabel) self.layout_widget= QWidget(self) self.zoom_in= ImageButton(self.parent.zoom_in2,self.parent.zoom_in1,self.parent.zoom_in2,40,30,self.layout_widget) self.zoom_in.setText("") self.zoom_in.clicked.connect(self.zoomIn) self.zoom_in.setGeometry(QtCore.QRect(0, 0, 40, 30)) self.zoom_out= ImageButton(self.parent.zoom_out2,self.parent.zoom_out1,self.parent.zoom_out2,40,30,self.layout_widget) self.zoom_out.setText("") self.zoom_out.clicked.connect(self.zoomOut) self.zoom_out.setGeometry(QtCore.QRect(42, 0, 40, 30)) self.btn_play_pause= ImageButton(self.parent.play2,self.parent.play1,self.parent.play2,40,30,self.layout_widget) self.btn_play_pause.setText("") self.btn_play_pause.clicked.connect(self.play_pause) self.btn_play_pause.setGeometry(QtCore.QRect(84, 0, 40, 30)) self.btn_capture= ImageButton(self.parent.foto_capture2,self.parent.foto_capture1,self.parent.foto_capture2,40,30,self.layout_widget) self.btn_capture.setText("") self.btn_capture.clicked.connect(self.start_capture) self.btn_capture.setGeometry(QtCore.QRect(126, 0, 40, 30)) # self.galery_btn= ImageButton(self.parent.galery_btn2,self.parent.galery_btn1,self.parent.galery_btn2,40,30,self.layout_widget) # self.galery_btn.setText("") # self.galery_btn.clicked.connect(self.open_galery) # self.galery_btn.setGeometry(QtCore.QRect(170, 0, 40, 30)) camreaspeed_LayoutWidget = QtGui.QWidget(self) camreaspeed_LayoutWidget.setGeometry(QtCore.QRect(4, 4, 170, 40)) self.fps_comboBox = QtGui.QComboBox(camreaspeed_LayoutWidget) self.fps_comboBox.setGeometry(QtCore.QRect(4, 1, 80, 30)) self.fps_comboBox.setObjectName("fps_comboBox") self.fps_comboBox.setStyleSheet("""QComboBox::drop-down {border-width: 0px;} QComboBox::down-arrow {image: url(noimg); border-width: 0px; text-align: center;} #fps_comboBox{color:#FFFFFF; padding:2px; border: 1px solid #FFFFFF;border-radius: 10px;background-color:#424242;}""") self.fps_comboBox.setEditable(True) self.fps_comboBox.lineEdit().setAlignment(QtCore.Qt.AlignCenter) self.fps_comboBox.lineEdit().setReadOnly(True) self.fps_comboBox.addItem("2 fps") self.fps_comboBox.addItem("4 fps") self.fps_comboBox.addItem("8 fps") self.fps_comboBox.addItem("12 fps") self.fps_comboBox.addItem("16 fps") # self.fps_comboBox.addItem("20 fps") self.fps_comboBox.currentIndexChanged.connect(self.setcamera_fps) self.pixmap = QtGui.QPixmap() self.img = QImage() # self.start() self.connect(self, QtCore.SIGNAL("show_preview()"), self.show_preview) threading.Timer(self.camera_fps, self.signalemit).start()