Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
 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()
Beispiel #6
0
class SetLevel(Div, object):
    """set level frame"""
    def __init__(self, width, height):
        # super(SetLevel, self).__init__()
        Div.__init__(self, (width, height))
        self.initAttr(width, height)

    def initAttr(self, width, height):
        self.justClicked = SETLEVEL["JUST_CLICKED"]
        # 默认 level
        self.loadResouce()
        self.setArrow()
        self.setLevel()

        self.background = Background((self.width, self.height))

        titleOffTop = 150

        self.titleText = CenteredText(SETLEVEL["TITLE_FONTS"], SETLEVEL["TITLE_CONTENT"], (self.width / 2, titleOffTop))

        offSet = 50
        self.beginButton = TextButton(SETLEVEL["BEGIN_FONTS"], SETLEVEL["BEGIN_CONTENT"], (self.width - offSet, self.height - offSet), (255, 255, 255))
        self.returnButton = TextButton(SETLEVEL["EXIT_FONTS"], SETLEVEL["EXIT_CONTENT"], (offSet, self.height - offSet), (255, 255, 255))

    def loadResouce(self):
        self.arrowImgRight = pygame.image.load(getFilePath("arrow.png"))

    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 setLevel(self, level = SETLEVEL["DEFAULT_LEVEL"]):
        if not isinstance(level, int):
            level = level[0]
        if (level > SETLEVEL["MAX_LEVEL"]):
            level = SETLEVEL["MAX_LEVEL"]
        if (level < SETLEVEL["MIN_LEVEL"]):
            level = SETLEVEL["MIN_LEVEL"]
        self.level = level
        levelTextOffTop = 300
        coordX, coordY = self.width / 2, levelTextOffTop
        self.levelText = CenteredText(SETLEVEL["LEVEL_FONTS"], str(self.level), (coordX, coordY))
        
    def drawLevelSet(self, screen):
        self.rArrow.draw(screen)
        self.levelText.draw(screen)
        self.lArrow.draw(screen)

    def draw(self, screen):
        self.background.draw(screen)
        self.titleText.draw(screen)
        self.drawLevelSet(screen)
        self.beginButton.draw(screen)
        self.returnButton.draw(screen)
        ret = self.beginButton.click(lambda *args : self.level)
        if ret != None:
            return ret
        ret = self.returnButton.click(lambda *args : STATE.menu)
        if ret != None:
            return ret
        self.rArrow.click(self.setLevel, self.level + 1)
        self.lArrow.click(self.setLevel, self.level - 1)
        return STATE.setLevel

        
        
Beispiel #7
0
class SetLevel(Div, object):
    """set level frame"""
    def __init__(self, width, height):
        # super(SetLevel, self).__init__()
        Div.__init__(self, (width, height))
        self.initAttr(width, height)

    def initAttr(self, width, height):
        self.justClicked = SETLEVEL["JUST_CLICKED"]
        # 默认 level
        self.loadResouce()
        self.setArrow()
        self.setLevel()

        self.background = Background((self.width, self.height))

        titleOffTop = 150

        self.titleText = CenteredText(SETLEVEL["TITLE_FONTS"],
                                      SETLEVEL["TITLE_CONTENT"],
                                      (self.width / 2, titleOffTop))

        offSet = 50
        self.beginButton = TextButton(
            SETLEVEL["BEGIN_FONTS"], SETLEVEL["BEGIN_CONTENT"],
            (self.width - offSet, self.height - offSet), (255, 255, 255))
        self.returnButton = TextButton(SETLEVEL["EXIT_FONTS"],
                                       SETLEVEL["EXIT_CONTENT"],
                                       (offSet, self.height - offSet),
                                       (255, 255, 255))

    def loadResouce(self):
        self.arrowImgRight = pygame.image.load(getFilePath("arrow.png"))

    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 setLevel(self, level=SETLEVEL["DEFAULT_LEVEL"]):
        if not isinstance(level, int):
            level = level[0]
        if (level > SETLEVEL["MAX_LEVEL"]):
            level = SETLEVEL["MAX_LEVEL"]
        if (level < SETLEVEL["MIN_LEVEL"]):
            level = SETLEVEL["MIN_LEVEL"]
        self.level = level
        levelTextOffTop = 300
        coordX, coordY = self.width / 2, levelTextOffTop
        self.levelText = CenteredText(SETLEVEL["LEVEL_FONTS"], str(self.level),
                                      (coordX, coordY))

    def drawLevelSet(self, screen):
        self.rArrow.draw(screen)
        self.levelText.draw(screen)
        self.lArrow.draw(screen)

    def draw(self, screen):
        self.background.draw(screen)
        self.titleText.draw(screen)
        self.drawLevelSet(screen)
        self.beginButton.draw(screen)
        self.returnButton.draw(screen)
        ret = self.beginButton.click(lambda *args: self.level)
        if ret != None:
            return ret
        ret = self.returnButton.click(lambda *args: STATE.menu)
        if ret != None:
            return ret
        self.rArrow.click(self.setLevel, self.level + 1)
        self.lArrow.click(self.setLevel, self.level - 1)
        return STATE.setLevel
    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
class SoPhotoApp(App):
    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 reload(self):
        self.last_photo.reload()

    def load(self):
        pictures_files = glob.glob('small_pictures/*/*.jpg')
        pictures_files.sort(key=os.path.getmtime)
        for picture_path in pictures_files:
            self.add_picture(picture_path)

    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 take1(self, instance):
        print('Take 1 picture')

        # Create Popup Progress
        popup_progress = PopupProgress(title='', separator_height=0)
        popup_progress.bind(on_open=self.start_preview)

        popup_progress.start_progress(3)

        # Connection dismiss signal on take_one_photo_action
        popup_progress.bind(on_dismiss=self.take_one_photo_action)

        # Open Popup Progress
        popup_progress.open()

    def take4(self, instance):
        print('take 4 pictures')

        self.images = []
        popup_progress = PopupProgressFour(title='',
                                           separator_height=0,
                                           photomaton=self)
        popup_progress.bind(on_open=self.start_preview)
        popup_progress.bind(on_dismiss=self.four_photo_assembly)

        popup_progress.start_progress(15)
        popup_progress.open()

    def start_preview(self, instance):
        if faking_it:
            pass
        else:
            photo.start_preview()

    def take_one_photo_action(self, instance):
        if faking_it:
            image = pilImage.open('raw_pictures/default_picture.jpg')
        else:
            image = photo.take_photo()
            photo.stop_preview()

        # Display last picture taken
        self.add_picture(image_editor.apply_big_picture_mask(image))
        self.reload()

    def take_one_of_four_photo_action(self):
        if faking_it:
            image = pilImage.open('raw_pictures/default_picture.jpg')
        else:
            image = photo.take_photo()
        self.images.append(image)

    def four_photo_assembly(self, instance):
        if faking_it:
            pass
        else:
            photo.stop_preview()

        self.add_picture(image_editor.apply_4_pictures_mask(self.images))
        self.reload()

    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 __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()
class ImageViewerWidget(QWidget):



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

    def open_galery(self):
        self.parent.galery.setVisible(True)
        self.parent.galery.galeri_start_emit()
    def open_setings(self):
        self.parent.settings_menu.setVisible(True)
    def signalemit(self):
        if not self.isexit :
            self.emit(QtCore.SIGNAL("show_preview()"))
            threading.Timer(self.camera_fps, self.signalemit).start()

    def show_preview(self):
        
        if(self.parent.canonCemara.isconnec):
            if self.isplay:
                if not self.ispreview :
                    self.ispreview=True
                    try:
                        camera_file = gp.check_result(gp.gp_camera_capture_preview(self.parent.canonCemara.camera))
                        file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
                        image = Image.open(io.BytesIO(file_data))
                        self.pixmap=self.PILimageToQImage(image)
                        self.imageLabel.setPixmap(self.pixmap)
                    except Exception as e:
                        print("Frame Read error")
                    self.ispreview=False
            elif self.iscapture_image:
                self.iscapture_image=False
                self.pixmap=self.PILimageToQImage(self.capture_image)
                self.imageLabel.setPixmap(self.pixmap)


    def addFrame(self,image):
        self.pause_()
        self.pixmap=image
        self.imageLabel.setPixmap(self.pixmap)

    def start_capture(self):
        self.pause_()
        time.sleep(self.camera_fps)
        OK,path=self.parent.canonCemara.capture_image()
        if OK :
            self.capture_image = Image.open(path)
            self.iscapture_image=True
        else :
            self.parent.showMesage("Capture Fail..","..")
    
    def print_(self):
        dialog = QPrintDialog(self.printer, self)
        if dialog.exec_():
            painter = QPainter(self.printer)
            rect = painter.viewport()
            size = self.imageLabel.pixmap().size()
            size.scale(rect.size(), QtCore.Qt.KeepAspectRatio)
            painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
            painter.setWindow(self.imageLabel.pixmap().rect())
            painter.drawPixmap(0, 0, self.imageLabel.pixmap())

    def zoomIn(self):
        self.scaleImage(1.25)

    def zoomOut(self):
        self.scaleImage(0.8)

    def play_pause(self):
        if self.isplay :
            self.pause_()
        else:
            self.play_()

    def play_(self):
        self.isplay=True
        self.btn_play_pause.setBackground(self.parent.pause2,self.parent.pause1,self.parent.pause2)
    def pause_(self):
        self.isplay=False
        self.btn_play_pause.setBackground(self.parent.play2,self.parent.play1,self.parent.play2)

    def fitToWindow(self):
        # fitToWindow = self.fitToWindowAct.isChecked()
        if self.fittowindow :
            self.fittowindow=False
        else:
            self.fittowindow = True
        self.scrollArea.setWidgetResizable(self.fittowindow)
        # if not fitToWindow:
        #     self.normalSize()
 
    def scaleImage(self, factor):
        self.scaleFactor *= factor
        self.imageLabel.resize(self.scaleFactor * self.imageLabel.pixmap().size())

        self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
        self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)


    def adjustScrollBar(self, scrollBar, factor):
        scrollBar.setValue(int(factor * scrollBar.value()
                                + ((factor - 1) * scrollBar.pageStep()/2)))


    def setcamera_fps(self,index):
        if index == 0:
            self.camera_fps=0.5
        elif index==1:
            self.camera_fps=0.25
        elif index==2:
            self.camera_fps=0.12
        elif index == 3:
            self.camera_fps==0.08
        elif index == 4:
            self.camera_fps=0.06
        elif index==5:
            self.camera_fps=0.05

    def setframespeed_dec(self):
        self.parent.framespeed += 0.05
        if self.parent.framespeed >= 0.5:
            self.parent.framespeed = 0.5

        self.framespeed.setText(str(self.parent.framespeed))
    def setframespeed_inc(self):
        self.parent.framespeed -= 0.05
        if(self.parent.framespeed <= 0) :
            self.parent.framespeed = 0

        self.framespeed.setText(str(self.parent.framespeed))
    def PILimageToQImage(self,im):
        im2 = im.convert("RGB")
        data = im2.tobytes("raw", "RGB")
        qim = QtGui.QImage(data, im.size[0], im.size[1], QtGui.QImage.Format_RGB888)
        # qim.save('hehe.png')
        pixmap = QtGui.QPixmap.fromImage(qim)
        return pixmap
    def PILimageToQImage2(self,im):
        im2 = im.convert("RGB")
        data = im2.tobytes("raw", "RGB")
        qim = QtGui.QImage(data, im.size[0], im.size[1], QtGui.QImage.Format_RGB888)
        return qim
    def setImagePath(self,path):
        self.path=path
        image = QImage(self.path)
        self.imageLabel.setPixmap(QPixmap.fromImage(image))
    def exit(self):
        self.isexit=True
        self.iscapture360=False
        self.iscapture360_start=False
    def setSize(self,x,y,w,h):
        self.setGeometry(QtCore.QRect(x, y, w, h))
        self.imageLabel.setGeometry(QtCore.QRect(0, 0, w, h))
        self.scrollArea.setGeometry(QtCore.QRect(0, 0, w, h))
        self.layout_widget.setGeometry(QtCore.QRect((w-250)/2, 4, 250, 40))