Esempio n. 1
0
class ImagePlayer(QWidget):
    def __init__(self, filename, title, parent=None):
        QWidget.__init__(self, parent)

        # Load the file into a QMovie
        self.movie = QMovie(filename, QByteArray(), self)

        size = self.movie.scaledSize()
        self.setGeometry(200, 200, size.width(), size.height())
        self.setWindowTitle(title)

        self.movie_screen = QLabel()
        # Make label fit the gif
        self.movie_screen.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.movie_screen.setAlignment(Qt.AlignCenter)

        # Create the layout
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.movie_screen)

        self.setLayout(main_layout)

        # Add the QMovie object to the label
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.movie.start()
Esempio n. 2
0
class ImagePlayerDialog(QDialog):
    """
        Class to display a loading git inside a Dialog when performing eavy computation
    """
    def __init__(self, filename, parent=None):
        QWidget.__init__(self, parent)

        # Load the file into a QMovie
        self.movie = QMovie(filename, QByteArray(), self)

        size = self.movie.scaledSize()
        self.setGeometry(200, 200, size.width(), size.height())

        self.movie_screen = QLabel()
        # Make label fit the gif
        self.movie_screen.setAlignment(Qt.AlignCenter)

        # Create the layout
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.movie_screen)

        self.setLayout(main_layout)

        # Add the QMovie object to the label
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.movie.start()
Esempio n. 3
0
    def set_widgets(self):
        """Set all widgets on the tab."""
        contacts = Contact.get_rows()

        for contact in contacts:
            contact_name = contact.name
            contact_email = ' - ' + contact.email if contact.email else ''
            contact_phone = ' - ' + contact.phone if contact.phone else ''

            contact_item = QListWidgetItem(contact_name + contact_email +
                                           contact_phone)

            contact_item.setData(Qt.UserRole, contact)
            self.project_contact_list.addItem(contact_item)

        self.project_contact_list.setSelectionMode(
            QAbstractItemView.ExtendedSelection)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_organisations()
        self.organisation_box.setFocus()
        self.project_description_text.setTabChangesFocus(True)
Esempio n. 4
0
    def on_radioButton_clicked(self, checked):
        """
        Slot documentation goes here.
        """
        # TODO: not implemented yet
        global audio, record_t
        movie = QMovie(":/icon/icon/siri.gif")
        self.label_4.setMovie(movie)

        if checked:
            self.label_4.setStyleSheet("")
            movie.start()
            if self.thread_flag == 0:
                print "abcd"
                self.start_flag = 1
                record_t = MyThread(ui.record_wave, (ui, ),
                                    ui.record_wave.__name__)
                record_t.setDaemon(True)
                record_t.start()
                self.thread_flag = 1
        else:
            movie.stop()
            self.label_4.setStyleSheet(
                "border-image: url(:/icon/icon/siri.gif);")
            if self.thread_flag == 1:
                self.start_flag = 0
                self.thread_flag = 0
Esempio n. 5
0
 def __init__(self):
     super(self.__class__, self).__init__()
     movie = QMovie(HERE_PATH + "/spinner.gif")
     movie.setScaledSize(QSize(23, 23))
     movie.setSpeed(200)
     self.setMovie(movie)
     movie.start()
Esempio n. 6
0
 def __init__(self, fileName):
     QLabel.__init__(self)
     thread = Thread(self)
     m = QMovie(fileName)
     m.start()
     self.setMovie(m)
     app.aboutToQuit.connect(thread.stop)
     thread.start()
Esempio n. 7
0
    def visualize(self):
        self.steps = 0
        gdal.UseExceptions()

        si = subprocess.STARTUPINFO()
        si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

        if self.point1.x() > self.point2.x():
            minx = math.floor(self.point2.x())
            maxx = math.ceil(self.point1.x())
        else:
            minx = math.floor(self.point1.x())
            maxx = math.ceil(self.point2.x())

        if self.point1.y() > self.point2.y():
            miny = math.floor(self.point2.y())
            maxy = math.ceil(self.point1.y())
        else:
            miny = math.floor(self.point1.y())
            maxy = math.ceil(self.point2.y())

        dataset_full = gdal.Open(self.dir_path[0] + '/' + self.roofground_file)
        full_array = dataset_full.ReadAsArray().astype(np.float)

        fullsizex = full_array.shape[1]
        fullsizey = full_array.shape[0]

        toplefty = self.yllcorner + fullsizey

        gdalclip_build = 'gdal_translate -a_nodata -9999 -projwin ' + str(minx) + ' ' + str(maxy)\
                         + ' ' + str(maxx) + ' ' + str(miny) + \
                         ' -of GTiff ' + self.dir_path[0] + '/' + self.roofground_file + ' ' \
                         + self.plugin_dir + '/data/temp.tif'

        subprocess.call(gdalclip_build, startupinfo=si)

        dataset = gdal.Open(self.plugin_dir + '/data/temp.tif')
        self.energy_array = dataset.ReadAsArray().astype(np.float)

        sizex = self.energy_array.shape[1]
        sizey = self.energy_array.shape[0]

        gdalclipasc_build = 'gdal_translate -a_nodata -9999 -projwin ' + str(minx) + ' ' + str(maxy) + ' ' + str(maxx) +\
                            ' ' + str(miny) + ' -of GTiff ' + self.dir_path[0] + '/' + self.height_file + ' ' + \
                            self.plugin_dir + '/data/temp_asc.tif'

        subprocess.call(gdalclipasc_build, startupinfo=si)

        dataset = gdal.Open(self.plugin_dir + '/data/temp_asc.tif')
        self.asc_array = dataset.ReadAsArray().astype(np.float)

        movie = QMovie(self.plugin_dir + '/loader.gif')
        self.visDlg.label.setMovie(movie)
        self.visDlg.label.show()
        movie.start()

        self.start_listworker(minx, maxy, sizex, sizey, toplefty)
Esempio n. 8
0
class ImagePlayer(QWidget):
    def __init__(self, filename, title, parent=None):
        QWidget.__init__(self, parent)
 
        # Load the file into a QMovie
        self.movie = QMovie(filename, QByteArray(), self)
        print(filename)
 
        size = self.movie.scaledSize()
        self.setGeometry(200, 200, size.width(), size.height())
        self.setWindowTitle(title)
 
        self.movie_screen = QLabel()
        # Make label fit the gif
        self.movie_screen.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.movie_screen.setAlignment(Qt.AlignCenter)
        self.btn_ex = QPushButton()
        self.btn_ex.setFixedWidth(100)
        self.btn_ex.setFixedHeight(100)
        # self.btn_ex.setIcon(QIcon("image/ex_stu.gif"))
        self.btn_ex.setStyleSheet("background-color: rgba(255,255,255,20);")
        self.btn_ex.setIcon(QIcon("image/smile.png"))
        self.btn_ex.setIconSize(QSize(80,80))
        self.btn_ex.setFlat(True)

        popMenu = QMenu(self)
        entry1 = popMenu.addAction("正确")
        # self.connect(entry1,SIGNAL('triggered()'), lambda item=item[0]: self.answerRight(item))
        entry2 = popMenu.addAction("错误")
        # self.connect(entry2,SIGNAL('triggered()'), lambda item=item[0]: self.answerWrong(item))
        entry3 = popMenu.addAction("替换")
        # self.connect(entry3,SIGNAL('triggered()'), lambda item=item[0]: self.resetStudent(item))
        self.btn_ex.setMenu(popMenu)


 
        # Create the layout
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.movie_screen)
        # main_layout.addWidget(self.btn_ex)
 
        self.setLayout(main_layout)
 
        # Add the QMovie object to the label
        self.movie.setCacheMode(QMovie.CacheAll)
        # self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.movie_screen.setLayout(QHBoxLayout())
        self.movie_screen.layout().addWidget(self.btn_ex)

        popMenu = QMenu(self)
        entry1 = popMenu.addAction("正确")
        # self.movie_screen.setMenu(popMenu)

        self.movie.start()
Esempio n. 9
0
class Loading(QDialog):
    def __init__(self, parent, text=""):
        super(Loading, self).__init__(parent)

        self.setStyleSheet("background-color:white;")
        Gl.Signals["changeLoadingText"].connect(self.change_text)
        Gl.Signals["endLoading"].connect(self.on_end)
        self.setWindowTitle("Please wait")

        # Credit to zegerdon on DeviantArt for his loading gif.
        self.load_gif = QMovie(os.path.join(Gl.Graphics, "loading_by_zegerdon-deviantart.gif"))
        self.load_label = QLabel()
        self.load_label.setMovie(self.load_gif)

        self.text = QLabel(text)
        self.text.setStyleSheet("QLabel { color : black; }")

        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.load_label)
        self.vbox.setAlignment(self.load_label, Qt.AlignCenter)
        self.vbox.addWidget(self.text)
        self.vbox.setAlignment(self.text, Qt.AlignCenter)
        self.vbox.setMargin(20)
        self.vbox.setSpacing(30)

        self.setLayout(self.vbox)

        self.load_gif.start()

        self.end_loading = False

    def change_text(self, string):
        self.text.setText(string)

    def on_end(self):
        """
        Close on signal.

        :return:
        """
        self.end_loading = True
        self.close()

    # noinspection PyArgumentList
    def closeEvent(self, close_event):
        """
        If closed by user, exit program.

        :return:
        """
        if self.end_loading:
            super(Loading, self).close()
        else:
            Gl.Signals["KILL"].emit()
            QApplication.processEvents()
    def set_widgets(self):
        """Set all widgets on the tab."""
        self.project_combo_box.currentIndexChanged.connect(
            self.project_combo_box_changed)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_projects()
        self.project_combo_box.setFocus()
def create_gif_icon(dir_=None):
    icon = QIcon()
    movie = QMovie(dir_)

    def update_icon():
        i = QIcon(movie.currentPixmap())
        icon.swap(i)

    movie.frameChanged.connect(update_icon)
    movie.start()

    return icon
Esempio n. 12
0
 def notifyTimeout(self):
     self.timeoutCount += 1
     if self.timeoutCount == self.notifyCount:
         msg = self.tr(u'No fix for %s since more than %d seconds!') % (self.name, self.timeoutTime * self.timeoutCount / 1000)
         w = self.iface.messageBar().createMessage(self.tr(u'PosiView Attention'), msg)
         l = QLabel(w)
         m = QMovie(':/plugins/PosiView/hand.gif')
         m.setSpeed(75)
         l.setMovie(m)
         m.setParent(l)
         m.start()
         w.layout().addWidget(l)
         self.iface.messageBar().pushWidget(w, QgsMessageBar.CRITICAL, duration=self.notifyDuration)
Esempio n. 13
0
class LoadingItem(QLabel):
    def __init__(self):
        super(LoadingItem, self).__init__()
        self.movie = QMovie(resources.IMAGES["loading"])
        self.setMovie(self.movie)
        self.movie.setScaledSize(QSize(16, 16))
        self.movie.start()

    def add_item_to_tree(self, folder, tree, item_type=None, parent=None):
        if item_type is None:
            item = QTreeWidgetItem()
            item.setText(0, self.tr('       LOADING: "%1"').arg(folder))
        else:
            item = item_type(parent, self.tr('       LOADING: "%1"').arg(folder), folder)
        tree.addTopLevelItem(item)
        tree.setItemWidget(item, 0, self)
        return item
Esempio n. 14
0
 def notifyTimeout(self):
     self.timeoutCount += 1
     if self.timeoutCount == self.notifyCount:
         msg = self.tr(u'No fix for %s since more than %d seconds!') % (
             self.name, self.timeoutTime * self.timeoutCount / 1000)
         w = self.iface.messageBar().createMessage(
             self.tr(u'PosiView Attention'), msg)
         l = QLabel(w)
         m = QMovie(':/plugins/PosiView/hand.gif')
         m.setSpeed(75)
         l.setMovie(m)
         m.setParent(l)
         m.start()
         w.layout().addWidget(l)
         self.iface.messageBar().pushWidget(w,
                                            QgsMessageBar.CRITICAL,
                                            duration=self.notifyDuration)
Esempio n. 15
0
    def __init__(self, parent, text="", isLightTheme=True, onCloseSlot=None, showIP=False):
        QDialog.__init__(self, parent)
        self.onCloseSignal.connect(onCloseSlot)

        # Create connecting image
        connMov = QMovie(utils.getAbsoluteResourcePath('images/' + ('light' if isLightTheme else 'dark') + '/waiting.gif'))
        connMov.start()
        self.connImg = QLabel(self)
        self.connImg.setMovie(connMov)

        # Create connecting and IP address labels
        self.connLabel = QLabel(text, self)
        if showIP:
            self.ipLabel = QLabel(self.ipLabelPrefix + "Getting IP address...", self)
            self.ipHelpLabel = QLabel("Your friend should enter the IP address above as the host to connect to.\n"
                                      "Make sure that port " + str(constants.DEFAULT_PORT) + " is forwarded to "
                                      "this computer. See the help\nfor more info.", self)


        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(self.connImg)
        hbox.addSpacing(10)
        hbox.addWidget(self.connLabel)
        hbox.addStretch(1)

        vbox = QVBoxLayout()
        vbox.addStretch(1)
        vbox.addLayout(hbox)

        if showIP:
            vbox.addSpacing(10)
            vbox.addWidget(QLine())
            vbox.addSpacing(10)
            vbox.addWidget(self.ipLabel)
            vbox.addSpacing(10)
            vbox.addWidget(self.ipHelpLabel)

        vbox.addStretch(1)

        self.setLayout(vbox)

        if showIP:
            # Start the thread to get the IP address and update the IP label when finished
            self.ipThread = qtThreads.GetIPAddressThread(self.__setIPAddress, self.__getIPAddressFailure)
            self.ipThread.start()
class UpdateInstallProgressDialog(QDialog):
    
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        
        self.ui = Ui_UpdateInstallProgressDialog()
        self.ui.setupUi(self)
        
        # Swap out the label with the gif to a movie that will actually display
        # it correctly.
        self.window = self.ui.updateIconLabel
        self.movie = QMovie(':/icons/icons/update-in-progress.gif', QByteArray(), self)
        
        # Run the GIF
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.window.setMovie(self.movie)
        self.movie.start()
Esempio n. 17
0
class Throbber(QLabel):
    """A throbber."""
    def __init__(self):
        super(Throbber, self).__init__()
        self.setAlignment(Qt.AlignCenter)
        fname = multiplatform.get_path("encuentro/ui/media/throbber.gif")
        self._movie = QMovie(fname)
        self.setMovie(self._movie)

    def hide(self):
        """Overload to control the movie."""
        self._movie.stop()
        super(Throbber, self).hide()

    def show(self):
        """Overload to control the movie."""
        self._movie.start()
        super(Throbber, self).show()
Esempio n. 18
0
class LoadingItem(QLabel):
    def __init__(self):
        super(LoadingItem, self).__init__()
        self.movie = QMovie(resources.IMAGES['loading'])
        self.setMovie(self.movie)
        self.movie.setScaledSize(QSize(16, 16))
        self.movie.start()

    def add_item_to_tree(self, folder, tree, item_type=None, parent=None):
        if item_type is None:
            item = QTreeWidgetItem()
            item.setText(0, self.tr('       LOADING: "%s"' % folder))
        else:
            item = item_type(parent, self.tr('       LOADING: "%s"' % folder),
                             folder)
        tree.addTopLevelItem(item)
        tree.setItemWidget(item, 0, self)
        return item
Esempio n. 19
0
    def __init__(self, parent=None):
        """
        
        Constructor
        """
        QDialog.__init__(self, parent)

        label = QLabel(self)
        self.setFixedSize(100, 100)
        #self.setWindowOpacity(0.5)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
        self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.FramelessWindowHint)

        self.connect(self, SIGNAL("finished()"), self.close)
        self.setContentsMargins(0, 0, 0, 0)
        movie = QMovie(':/image/ajax-loader.gif')
        label.setMovie(movie)
        movie.start()
Esempio n. 20
0
    def __init__(self, parent, text=""):
        QDialog.__init__(self, parent)

        # Create waiting image
        waitingImage = QMovie(qtUtils.getAbsoluteImagePath('waiting.gif'))
        waitingImage.start()
        waitingImageLabel = QLabel(self)
        waitingImageLabel.setMovie(waitingImage)

        waitingLabel = QLabel(text, self)

        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(waitingImageLabel)
        hbox.addSpacing(10)
        hbox.addWidget(waitingLabel)
        hbox.addStretch(1)

        self.setLayout(hbox)
Esempio n. 21
0
    def __init__(self, parent, text=""):
        QDialog.__init__(self, parent)

        # Create waiting image
        waitingImage = QMovie(qtUtils.getAbsoluteImagePath('waiting.gif'))
        waitingImage.start()
        waitingImageLabel = QLabel(self)
        waitingImageLabel.setMovie(waitingImage)

        waitingLabel = QLabel(text, self)

        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(waitingImageLabel)
        hbox.addSpacing(10)
        hbox.addWidget(waitingLabel)
        hbox.addStretch(1)

        self.setLayout(hbox)
Esempio n. 22
0
    def setStatus(self,status,message='',tooltip=None):
        '''Sets indicator icon and statusbar message'''
        self.parent.statusbar.showMessage(message)
        self.parent.statusbar.setToolTip(tooltip if tooltip else '')

        #progress
        loc = os.path.abspath(os.path.join(IMG_LOC,self.imgset[status]))
        #loc = os.path.abspath(os.path.join(os.path.dirname(__file__),self.parent.IMG_LOC,self.imgset[status]))
        self.progressbar.setVisible(status in (self.STATUS.BUSY, self.STATUS.CLEAN))
        
        #icon
        anim = QMovie(loc, QByteArray(), self)
        anim.setScaledSize(QSize(self.IMG_WIDTH,self.IMG_HEIGHT))
        anim.setCacheMode(QMovie.CacheAll)
        anim.setSpeed(self.IMG_SPEED)
        self.view.clear()
        self.view.setMovie(anim)
        anim.start()

        self.view.repaint()
        QApplication.processEvents(QEventLoop.AllEvents)
Esempio n. 23
0
    def set_widgets(self):
        """Set all widgets on the tab."""
        self.project_combo_box.currentIndexChanged.connect(
            self.project_combo_box_changed)

        checkbox_checked = get_setting('public_project')
        if checkbox_checked:
            self.public_projects_checkbox.setCheckState(Qt.Checked)
        self.public_projects_checkbox.stateChanged.connect(
            self.public_check_box_changed)

        icon_path = resources_path('images', 'throbber.gif')
        movie = QMovie(icon_path)
        self.throbber_loader.setMovie(movie)
        movie.start()
        self.get_available_projects()
        self.add_contact_label.mousePressEvent = self.add_contact_label_clicked
        self.set_enabled_add_contact_label(False)
        self.project_combo_box.setFocus()
        set_setting('public_project',
                    self.public_projects_checkbox.checkState() == Qt.Checked)
Esempio n. 24
0
    def setStatus(self,status,message='',tooltip=None):
        '''Sets indicator icon and statusbar message'''
        self.parent.statusbar.showMessage(message)
        self.parent.statusbar.setToolTip(tooltip if tooltip else '')

        #progress
        loc = os.path.abspath(os.path.join(IMG_LOC,self.imgset[status]))
        #loc = os.path.abspath(os.path.join(os.path.dirname(__file__),self.parent.IMG_LOC,self.imgset[status]))
        self.progressbar.setVisible(status in (self.STATUS.BUSY, self.STATUS.CLEAN))
        
        #icon
        anim = QMovie(loc, QByteArray(), self)
        anim.setScaledSize(QSize(self.IMG_WIDTH,self.IMG_HEIGHT))
        anim.setCacheMode(QMovie.CacheAll)
        anim.setSpeed(self.IMG_SPEED)
        self.view.clear()
        self.view.setMovie(anim)
        anim.start()

        self.view.repaint()
        QApplication.processEvents(QEventLoop.AllEvents)
Esempio n. 25
0
class MuteButtonLabel(QWidget):

    def __init__(self, parent=None): 
        QWidget.__init__(self, parent) 
        #self.setFixedSize(CustomSize)
        self.movie_screen = QLabel()
        self.movie_screen.setFixedSize(CustomSize)
        self.movie_screen.setAlignment(Qt.AlignLeft)
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.movie_screen)
        self.setLayout(main_layout)
        self.muted = False

        #self.unmute() # this is for testpurpose only

        
    def unmute(self):
        """start animation"""
        self.movie = QMovie(":/unmute.gif", QByteArray(), self)
        self.movie.setScaledSize(CustomSize*0.7)
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.muted = False
        #print("Emitted 'sig_unmute'")
        self.emit(SIGNAL("sig_unmute"))
        self.movie.start()

    def show_unmute(self):
        self.movie = QMovie(":/unmute.gif", QByteArray(), self)
        self.movie.setScaledSize(CustomSize*0.7)
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.muted = False
        self.movie.start()

    def mute(self):
        """stop the animation"""
        self.movie = QMovie(":/mute.gif", QByteArray(), self)
        self.movie.setScaledSize(CustomSize*0.7)
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.muted = True
        #print("Emitted 'sig_mute'")
        self.emit(SIGNAL("sig_mute"))
        self.movie.start()

    def toggleMute(self):
        if self.muted:
            self.unmute()
        else:
            self.mute()

    def mousePressEvent(self, QMouseEvent):

        self.toggleMute()

        QMouseEvent.accept()
Esempio n. 26
0
class MuteButtonLabel(QWidget):

    def __init__(self, parent=None): 
        QWidget.__init__(self, parent) 
        #self.setFixedSize(CustomSize)
        self.movie_screen = QLabel()
        self.movie_screen.setFixedSize(CustomSize)
        self.movie_screen.setAlignment(Qt.AlignLeft)
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.movie_screen)
        self.setLayout(main_layout)
        self.muted = False

        #self.unmute() # this is for testpurpose only

        
    def unmute(self):
        """start animation"""
        self.movie = QMovie(":/unmute.gif", QByteArray(), self)
        self.movie.setScaledSize(CustomSize*0.7)
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.muted = False
        #print("Emitted 'sig_unmute'")
        self.emit(SIGNAL("sig_unmute"))
        self.movie.start()

    def show_unmute(self):
        self.movie = QMovie(":/unmute.gif", QByteArray(), self)
        self.movie.setScaledSize(CustomSize*0.7)
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.muted = False
        self.movie.start()

    def mute(self):
        """stop the animation"""
        self.movie = QMovie(":/mute.gif", QByteArray(), self)
        self.movie.setScaledSize(CustomSize*0.7)
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.muted = True
        #print("Emitted 'sig_mute'")
        self.emit(SIGNAL("sig_mute"))
        self.movie.start()

    def toggleMute(self):
        if self.muted:
            self.unmute()
        else:
            self.mute()

    def mousePressEvent(self, QMouseEvent):

        self.toggleMute()

        QMouseEvent.accept()
Esempio n. 27
0
class QConnectingWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        # Create connecting image
        self.connectingGif = QMovie(
            qtUtils.getAbsoluteImagePath('waiting.gif'))
        self.connectingGif.start()
        self.connetingImageLabel = QLabel(self)
        self.connetingImageLabel.setMovie(self.connectingGif)
        self.connectingLabel = QLabel(self)

        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(self.connetingImageLabel, alignment=Qt.AlignCenter)
        hbox.addSpacing(10)
        hbox.addWidget(self.connectingLabel, alignment=Qt.AlignCenter)
        hbox.addStretch(1)

        self.setLayout(hbox)

    def setConnectingToNick(self, nick):
        self.connectingLabel.setText("Connecting to " + nick + "...")
    def __init__(self, visualization, parent_widget=None):

        QWidget.__init__(self, parent_widget)
        self.inGui = False
        self.visualization = visualization

        size = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.widgetLayout = QGridLayout(self)
        self.setSizePolicy(size)

        self.scroll = QScrollArea()
        file_path = self.visualization.get_file_path()
        self.label = QLabel()

        movie = QMovie(QString(file_path), QByteArray(), self)
        movie.setCacheMode(QMovie.CacheAll)
        self.label.setMovie(movie)
        movie.start()

        self.scroll.setWidget(self.label)
        self.widgetLayout.addWidget(self.scroll)

        self.tabIcon = QIcon(":/Images/Images/map.png")
        self.tabLabel = visualization.table_name
 def animationLabel(self, index, animationFile):
     """
     Public slot to set an animated icon.
     
     @param index tab index (integer)
     @param animationFile name of the file containing the animation (string)
     @return reference to the created label (QLabel)
     """
     if index == -1:
         return None
     
     if hasattr(self.__tabBar, 'setTabButton'):
         side = self.__freeSide()
         animation = QLabel(self)
         if animationFile and not animation.movie():
             movie = QMovie(animationFile, QByteArray(), animation)
             movie.setSpeed(50)
             animation.setMovie(movie)
             movie.start()
         self.__tabBar.setTabButton(index, side, None)
         self.__tabBar.setTabButton(index, side, animation)
         return animation
     else:
         return None
Esempio n. 30
0
    def __init__(self, visualization, parent_widget = None):
        
        QWidget.__init__(self, parent_widget)
        self.inGui = False
        self.visualization = visualization

        size = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.widgetLayout = QGridLayout(self)
        self.setSizePolicy(size)

        self.scroll = QScrollArea()
        file_path = self.visualization.get_file_path()       
        self.label = QLabel()
        
        movie = QMovie(QString(file_path), QByteArray(), self)
        movie.setCacheMode(QMovie.CacheAll)
        self.label.setMovie(movie)
        movie.start() 
        
        self.scroll.setWidget(self.label)
        self.widgetLayout.addWidget(self.scroll)

        self.tabIcon = QIcon(":/Images/Images/map.png")
        self.tabLabel = visualization.table_name
Esempio n. 31
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.searchEdit.textChanged.connect(self.search_text_changed)
        self.ui.show_button.clicked.connect(self.show_episodes)
        self.ui.searchEdit.returnPressed.connect(self.show_episodes)
        self.episodes = None
        self.episode_list = None
        self.number = 0
        self.anime_list = None
        self.ui.download_button.clicked.connect(self.download)
        self.ui.res_list_widget.currentItemChanged.connect(self.episode_change)
        self.com = Comunicate()
        self.com.sig.connect(self.message)
        self.com.img.connect(self.set_image)
        self.ui.anime_list_widget.itemDoubleClicked.connect(self.show_episodes)
        self.setWindowIcon(QIcon(get_file('animes.png')))
        self.ui.anime_list_widget.itemPressed.connect(self.anime_entered)
        Thread(target=self.load_url_items).start()
        #self.load_url_items()
        self.movie = QMovie(get_file('ajax-loader.gif'))
        self.ui.loading_label.setMovie(self.movie)
        self.link = None
        self.main_download_page = None
        self.tray = SystemTrayIcon(
            QIcon(get_file('animes.png')), self.com, self)
        self.com.op.connect(self.show_semard)
        self.ui.action_About_Semard.activated.connect(self.about_semard)
        self.ui.action_Contato.activated.connect(self.show_feedback)
        self.setWindowTitle('Semard - Animes')
        self.browser = None
        self.player = None
        #self.player_window = player_w

    @Slot(str, bool)
    def openVideo(self, filepath, duplicate_mode):
        movie = os.path.expanduser(filepath)
        if 'http://' not in filepath:
            if not os.access(movie, os.R_OK):
                print('Error: %s file is not readable' % movie)
            sys.exit(1)

        split = urlparse.urlsplit(filepath)
        #name = QInputDialog.getText(self, 'Escolha nome do arquivo', 'Nome do arquivo:')
        name = split.path.split("/")[-1]
        #pa = os.path.join(res, name)
        if duplicate_mode:
            try:
                #media = instance.media_new(movie, 'sout=#duplicate{dst=file{dst=%s},dst=display}' % pa)
                pass
            except NameError:
                print ('NameError: % (%s vs Libvlc %s)' % (sys.exc_info()[1],
                                                           vlc.__version__, vlc.libvlc_get_version()))
        else:
            try:
                #media = instance.media_new(movie)
                if sys.platform in 'win32':
                    subprocess.Popen([os.path.join('vlc','vlc'), movie])
                else:
                    subprocess.Popen(['vlc', movie])
            except NameError:
                print ('NameError: % (%s vs Libvlc %s)' % (sys.exc_info()[1],
                                                           vlc.__version__, vlc.libvlc_get_version()))
                QMessageBox.critical(self, 'Erro','problema ao iniciar o vlc')
                # "--sout=#duplicate{dst=file{dst=example.mpg},dst=display}"

        #player = instance.media_player_new()
        #pplayer.set_media(media)
        #self.player_window.setMedia(media)
        #self.player_window.createUI()
        #self.player_window = Player()
        #media.parse()
        #self.player_window.setWindowTitle(media.get_meta(0))
        #self.player_window.show()
        #self.player_window.resize(640, 480)
        #if sys.platform == "linux2":  # for Linux using the X Server
        #    pplayer.set_xwindow(self.player_window.videoframe.winId())
        #elif sys.platform == "win32":  # for Windows
        #    pplayer.set_hwnd(self.player_window.videoframe.winId())
        #elif sys.platform == "darwin":  # for MacOS
        #    pplayer.set_agl(self.player_window.videoframe.windId())
        #pplayer.play()
        #self.player_window.updateUI()

    @Slot(str, str)
    def start_download(self, filepath, path):
        #thread = QThread(self)
        pbar = QtGui.QProgressBar(self.ui.tab_downloads)
        pbar.setMinimum(0)
        pbar.setMaximum(100)
        pbar.setValue(0)
        self.ui.formLayout.addRow(os.path.basename(path), pbar)
        pbar.show()
        dw = Downloader(str(filepath), str(path), pbar)
        dw.finished.connect(self.finished_download)
        dw.progresschanged.connect(self.show_download_progress)
        dw.started.connect(self.started_download)
        Thread(target=dw.download).start()
        #thread.started.connect(dw.download)
        #thread.finished.connect(self.finished_download)
        #dw.moveToThread(thread)
        #thread.start()

    def finished_download(self, pbar, filename):
        self.tray.showMessage(filename, u'Download concluído.')
        pbar.setValue(100)
        pbar.setEnabled(False)

    def started_download(self, filename):
        filename = os.path.basename(filename)
        self.tray.showMessage(filename, u'Download iniciado.')

    @Slot(float, QtGui.QProgressBar)
    def show_download_progress(self, progress, pbar):
        pbar.setValue(progress)

    def show_feedback(self):
        feed = Feedback(self.com)
        feed.exec_()

    def about_semard(self):
        about = QMessageBox.about(self, "Sobre Semard",
                                  u"""<b>Semard</b> v%s
        <p><b>Copyright (C) 2013</b> Ronnie Andrew.</p>
        <p>Todos os direitos reservados de acordo com a licença GNU GPL v3 ou posterior.</p>
        <p><b>Website Oficial:</b> <a href='https://github.com/ROAND/Series-Manager'>GitHub</a></p>
        <p><b>Plataforma: </b>%s</p>
          """ % (__version__, platform.system()))

    def show_semard(self, message):
        self.show()

    def closeEvent(self, event):
        self.hide()
        self.tray.showMessage(u'Semard', u'Semard ainda está em execução.')
        event.ignore()

    @Slot(str)
    def set_image(self, img_str):
        self.ui.image_label.setPixmap(QPixmap(img_str))

    @Slot(str)
    def message(self, message):
        if str(message) in 'ended':
            self.ui.loading_label.hide()
            # self.repaint()
            self.ui.anime_list_widget.setEnabled(True)
            self.ui.show_button.setEnabled(True)
            self.movie.stop()
        if str(message) in 'started':
            self.ui.loading_label.show()
            # self.repaint()
            self.ui.anime_list_widget.setEnabled(False)
            self.ui.show_button.setEnabled(False)
            self.movie.start()

    def anime_entered(self, item):
        pass

    def load_url_items(self):
        self.com.sig.emit('started')
        self.main_download_page = AnimeList('http://www.anbient.net/lista')
        self.number, self.anime_list = self.main_download_page.get_attrs()
        self.ui.avaLabel.setText('%s disponiveis.' % self.number)
        self.add_full_items_animelist()
        self.com.sig.emit('ended')

    def episode_change(self):
        self.com.sig.emit('started')
        self.ui.options_list_widget.clear()

        if self.ui.res_list_widget.currentItem():
            name = self.ui.res_list_widget.currentItem().text()
            episode = self.episode_list[name]
            self.ui.options_list_widget.addItems(episode.links)
            self.com.sig.emit('ended')

    def download(self):
        #name = self.ui.options_list_widget.currentItem().text()
        link = self.ui.options_list_widget.currentItem().text()
        self.com.sig.emit('started')
        msgBox = QMessageBox()
        msgBox.setWindowTitle(u'Informação')
        msgBox.setText(u'Browser padrão')
        msgBox.setInformativeText(
            u'Você deseja abrir este link com o seu browser padrão?')
        msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        msgBox.setDefaultButton(QMessageBox.Yes)
        ret = msgBox.exec_()
        if ret == QMessageBox.Yes:
            if sys.platform in 'win32':
                webbrowser.open(link)
            else:
                webbrowser.open(link)
        else:
            browser.ui.webView.setUrl(link)
            browser.show()
        self.com.sig.emit('ended')

    def keyPressEvent(self, event):
        if isinstance(event, PyQt4.QtGui.QKeyEvent):
            if event.key() == Qt.Key_Down:
                self.ui.anime_list_widget.setCurrentRow(
                    self.ui.anime_list_widget.currentRow() + 1)
            elif event.key() == Qt.Key_Up:
                self.ui.anime_list_widget.setCurrentRow(
                    self.ui.anime_list_widget.currentRow() - 1)

    @staticmethod
    def get_img_link(url):
        page = urllib2.urlopen(url)
        page_string = page.read().decode('utf-8')
        soup = BeautifulSoup(page_string)
        spans = soup.find_all('span', {'id': 'posterspan'})
        link = None
        for chil in spans:
            if isinstance(chil, bs4.element.Tag):
                for img in chil.children:
                    if isinstance(img, bs4.element.Tag):
                        link = img['src']
        return link

    def show_ep_thread(self):
        self.ui.res_list_widget.clear()
        anime_name = self.ui.anime_list_widget.currentItem().text()
        link = self.anime_list[anime_name]
        self.episodes = EpisodeList(link)
        # self.episodes.join()
        self.link = self.get_img_link(link)
        self.episode_list = self.episodes.get_episodes()

        anime_name = self.ui.anime_list_widget.currentItem().text()
        link = self.anime_list[anime_name]
        img_link = self.get_img_link(link)
        file_name = img_link
        if os.path.exists(get_file(file_name)):
            self.com.img.emit(get_file(file_name))
            # self.ui.image_label.setPixmap(QPixmap(get_file(file_name)))
        else:
            if img_link is not None:
                file_name = img_link.replace(
                    'http://www.anbient.net/sites/default/files/imagecache/242x0/imagens/poster/', '')
                urllib.urlretrieve(
                    'http://www.anbient.net/sites/default/files/imagecache/242x0/imagens/poster/%s' % file_name,
                    get_file(file_name))
                self.com.img.emit(get_file(file_name))
                # self.ui.image_label.setPixmap(QPixmap(get_file(file_name)))

        self.ui.label_sinopse.setText(self.episodes.get_sinopse().strip())
        try:
            for name in reversed(sorted(self.episode_list.keys(), key=int)):
                episode = self.episode_list[name]
                name, links = episode.get_attrs()
                self.ui.res_list_widget.addItem(name)
        except:
            for name, episode in reversed(sorted(self.episode_list.items())):
                name, links = episode.get_attrs()
                self.ui.res_list_widget.addItem(name)
        self.com.sig.emit('ended')

    def show_episodes(self):
        Thread(target=self.show_ep_thread).start()
        self.com.sig.emit('started')

    def add_full_items_animelist(self):
        self.ui.anime_list_widget.clear()
        for name, link in sorted(self.anime_list.items()):
            self.ui.anime_list_widget.addItem(name)

    def search_text_changed(self, new_text):
        items = self.ui.anime_list_widget.findItems(new_text, Qt.MatchContains)
        if items:
            self.ui.anime_list_widget.setCurrentItem(items[0])
            self.ui.labelSearch.setText('')
        else:
            self.ui.labelSearch.setText('Not Found!')

    def setBrowser(self, browser_param):
        self.browser = browser_param
        self.browser.start_download.connect(self.start_download)
        self.browser.open_video.connect(self.openVideo)
Esempio n. 32
0
class LearningWizard(QWizard, Ui_Wizard):
    def __init__(self, settings):
        QWizard.__init__(self)
        self.setupUi(self)
        self.settings = settings
        self.wizardPage3.pageCreated.connect(self.showSummary)
        self.wizardPage3.fullfilled = True

        self.wizardPage2.fullfilled = True
        self.errors = 0
        self.steps = 0
        self.delete_images_button.clicked.connect(self.deleteUserImages)
        self.add_files_button.clicked.connect(self.AddFiles)
        self.remove_file_button.clicked.connect(self.removeFile)
        self.save_button.clicked.connect(self.saveImgData)
        self.train_button.clicked.connect(self.trainOCR)
        self.ocr_button.clicked.connect(self.runOCR)
        self.next_button.clicked.connect(self.nextWord)
        self.prev_button.clicked.connect(self.previousWord)
        #self.add_screenshots.clicked.connect(self.AddFiles)
        #self.wizardPage2.pageCreated.connect(self.AnalyzeImg)
        #self.contrast = 0.0
        #self.img_fields = [self.g1,self.g2,self.g3,self.g4,self.g5,self.g6,self.g7,self.g8,self.g9,self.g10,self.g11,self.g12,self.g13,self.g14,self.g15,self.g16,self.g17,self.g18,self.g19,self.g20]
        #self.input_fields = [self.e1,self.e2,self.e3,self.e4,self.e5,self.e6,self.e7,self.e8,self.e9,self.e10,self.e11,self.e12,self.e13,self.e14,self.e15,self.e16,self.e17,self.e18,self.e19,self.e20]
        self.gviews = []
        self.ledits = []
        self.boxlist = []
        self.imglist = []
        self.charlist = []
        self.words = []
        self.boundaries = []
        self.wordcount = 0
        self.current = 0
        self.scene = None
        self.ratio_h = 1.0
        self.ratio_w = 1.0
        self.base = self.loadBase()
        self.user = self.loadUser()
        if not self.base is None:
            self.base_data_label.setText(self.getBaseData())
        if not self.user is None:
            self.delete_images_button.setEnabled(True)
            self.user_data_label.setText(self.getUserData())
        #self.resizeElements()

        #for index,item in zip(range(20), self.input_fields):
        #    item.textEdited.connect(partial(self.changeText, index))
        self.train_button.setEnabled(True)
        #self.grid = QGridLayout()
        #self.field_holder.addLayout(self.grid)

    def deleteUserImages(self):
        self.user = None
        path = self.settings.storage_path + os.sep + "user_training_data.pck"
        remove(path)
        self.user_data_label.setText("-")
        self.delete_images_button.setEnabled(False)

    def showSummary(self):
        summary = ""
        userdata = {}
        characters = [
            "'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z'
        ]
        for word in self.words:
            for letter in word:
                if letter[1] in characters:
                    if letter[1] in userdata:
                        userdata[letter[1]] += 1
                    else:
                        userdata[letter[1]] = 1
        for key in characters:
            if key in userdata:
                summary += '"' + key + '"' + ": " + str(userdata[key]) + ", "

        self.summary_label.setText(summary)

    def trainOCR(self):
        self.train_button.setEnabled(False)
        alldata = self.connectData()
        testnumbers = self.getRandomData(
            alldata,
            [',', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
        testletters = self.getRandomData(alldata, [
            "'", ',', '-', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z'
        ])
        teststation = self.getRandomData(alldata, [
            "'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
            'Y', 'Z'
        ])
        self.movie = QMovie(":/ico/loader.gif")
        self.loader.setMovie(self.movie)
        self.movie.start()
        self.numberstrainerthread = Trainer(self, "numbers", self.base,
                                            self.user, testnumbers,
                                            testletters, teststation)
        self.letterstrainerthread = Trainer(self, "letters", self.base,
                                            self.user, testnumbers,
                                            testletters, teststation)
        self.stationtrainerthread = Trainer(self, "station", self.base,
                                            self.user, testnumbers,
                                            testletters, teststation)
        QObject.connect(self.numberstrainerthread,
                        SIGNAL('finished(QString, int)'), self.stepFinished)
        QObject.connect(self.letterstrainerthread,
                        SIGNAL('finished(QString, int)'), self.stepFinished)
        QObject.connect(self.stationtrainerthread,
                        SIGNAL('finished(QString, int)'), self.stepFinished)
        #QObject.connect(self.trainerthread, SIGNAL('finishedall(int)'), self.trainingFinished)
        self.numberstrainerthread.execute()
        self.letterstrainerthread.execute()
        self.stationtrainerthread.execute()
        self.training_summary.setText("Training in progress")

    def trainingFinished(self):
        if self.errors < 3:
            self.training_summary.setText(
                "The training sucessfully finished. Your OCR accuracy should be very high."
            )
        elif self.errors < 6:
            self.training_summary.setText(
                "The training sucessfully finished. Your OCR accuracy should satisfactory. You might still increase it by repeating this process with other screenshots."
            )
        elif self.errors < 10:
            self.training_summary.setText(
                "The training sucessfully finished. Your OCR accuracy is sufficient but not perfect. You should repeat this process with other screenshots."
            )
        else:
            self.training_summary.setText(
                "The training finished. Your OCR accuracy is not sufficient. You should repeat this process with other screenshots."
            )

    def stepFinished(self, value, error):
        self.steps += 1
        self.details.append(value + "\n")
        self.errors += error
        if self.steps == 3:
            self.trainingFinished()
            self.movie.stop()
            self.loader.clear()

    def connectData(self):
        connected = {}
        characters = [
            "'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z'
        ]

        if self.user is None:
            self.user = {}
        if self.base is None:
            self.base = {}

        for char in characters:
            if char in self.base and char in self.user:
                connected[char] = self.base[char] + self.user[char]
            elif char in self.base:
                connected[char] = self.base[char]
            elif char in self.user:
                connected[char] = self.user[char]
        return connected

    def getRandomData(self, data, characters):
        self.testsamples = {}
        samples = 30

        for char in characters:
            amount = len(data[char]) / 400
            if amount > samples:
                picks = random.sample(range(amount), samples)
            else:
                picks = random.sample(range(amount), amount)

            temp = bitarray()
            for pick in picks:
                temp += data[char][pick * 400:pick * 400 + 400]

            self.testsamples[char] = temp

        return self.testsamples

    def saveImgData(self):
        characters = [
            "'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z'
        ]

        if self.user is None:
            self.user = {}

        for word in self.words:
            for letter in word:
                if letter[1] in characters:
                    data = bitarray()
                    image = cv2.resize(letter[0], (20, 20))
                    ret, image = cv2.threshold(image, 250, 255,
                                               cv2.THRESH_BINARY)
                    for row in image:
                        for cell in row:
                            if cell == 255:
                                data.append(True)
                            else:
                                data.append(False)
                    if letter[1] in self.user:
                        self.user[letter[1]] += data
                    else:
                        self.user[letter[1]] = data

        path = self.settings.storage_path + os.sep + "user_training_data.pck"
        file = gzip.GzipFile(path, 'wb')
        pickle.dump(self.user, file, -1)
        file.close()

        self.save_button.setEnabled(False)
        self.train_button.setEnabled(True)

    def changeText(self, index):
        #print index
        self.words[self.current][index][1] = unicode(self.ledits[index].text())

    def getBaseData(self):
        text = ""
        keys = []
        for key in self.base:
            keys.append(key)
        keys.sort()
        for key in keys:
            text += key + ": " + str(len(self.base[key]) / 400) + ", "
        #print keys
        return text

    def getUserData(self):
        text = ""
        keys = []
        for key in self.user:
            keys.append(key)
        keys.sort()
        for key in keys:
            text += key + ": " + str(len(self.user[key]) / 400) + ", "
        return text

    def loadBase(self):
        try:
            path = self.settings.app_path + os.sep + "trainingdata" + os.sep + "base_training_data.pck"
            file = gzip.GzipFile(path, 'rb')
            letters = pickle.load(file)
            file.close()
            return letters
        except:
            return None

    def loadUser(self):
        try:
            path = self.settings.storage_path + os.sep + "user_training_data.pck"
            file = gzip.GzipFile(path, 'rb')
            letters = pickle.load(file)
            file.close()
            return letters
        except:
            return None

    def removeFile(self):
        item = self.file_list.currentItem()
        self.file_list.takeItem(self.file_list.currentRow())
        del item

    def AddFiles(self):
        if self.settings["native_dialog"]:
            files = QFileDialog.getOpenFileNames(
                self, "Open", self.settings['screenshot_dir'])
        else:
            files = QFileDialog.getOpenFileNames(
                self,
                "Open",
                self.settings['screenshot_dir'],
                options=QFileDialog.DontUseNativeDialog)

        if files == []:
            return
        first_item = None
        counter = 0
        for file in files:
            file1 = unicode(file).encode(sys.getfilesystemencoding())
            item = CustomQListWidgetItem(split(file1)[1], file1, self.settings)
            if first_item == None:
                first_item = item
            self.file_list.addItem(item)
            counter += 1

    """        
    def resizeElements(self):
        fields = self.input_fields
        for field in fields:
            field.setMinimumSize(QSize(0, self.settings['input_size']))
            field.setMaximumSize(QSize(16777215, self.settings['input_size']))
        canvases = self.img_fields
        for canvas in canvases:
            canvas.setMinimumSize(QSize(0, self.settings['snippet_size']))
            canvas.setMaximumSize(QSize(16777215, self.settings['snippet_size']))
    """

    def runOCR(self):
        self.add_files_button.setEnabled(False)
        self.remove_file_button.setEnabled(False)
        self.ocr_button.setEnabled(False)
        self.file_list.setEnabled(False)
        self.repaint()
        self.current_image = 0
        self.results = []
        self.images = []
        self.prev = []
        self.marketoffset = []
        self.stationoffset = []
        files = self.file_list.count()
        for i in xrange(files):
            self.file_list.setCurrentRow(i)
            item = self.file_list.currentItem()
            color_image = item.loadColorImage()
            preview_image = item.addTestImage(color_image)
            self.images.append(color_image)
            self.prev.append(preview_image)
            #cv2.imshow("x", color_image)
            #cv2.waitKey(0)
            #
            #images.append(preview_image)
            #self.setPreviewImage(preview_image)
            #return
            self.stationoffset.append(item.ocr_areas.station_name)
            self.marketoffset.append(item.ocr_areas.market_table)
            current_result = OCR(color_image,
                                 item.ocr_areas,
                                 self.settings["ocr_language"],
                                 item,
                                 levels=False,
                                 levenshtein=False)

            self.results.append(current_result)
        self.allBoxes()
        #print len(self.words)
        #print self.words[1]
        self.next_button.setEnabled(True)
        self.prev_button.setEnabled(False)
        self.showSet()
        self.notifier.setText("You did not check every word yet.")

    def showSet(self):
        #self.snippet_preview

        bound = self.boundaries[self.current]
        #print self.current
        #print bound[1]
        image = self.images[bound[0]][bound[1][1] - 2:bound[1][3] + 3,
                                      bound[1][0] - 2:bound[1][2] + 2]
        self.drawSnippet(self.snippet_preview, image)
        for gview in self.gviews:
            self.grid.removeWidget(gview)
            gview.deleteLater()
            gview = None
        for ledit in self.ledits:
            self.grid.removeWidget(ledit)
            ledit.deleteLater()
            ledit = None
        self.gviews = []
        self.ledits = []
        letters = len(self.words[self.current])
        for i in range(letters):
            gview = QGraphicsView()
            self.grid.addWidget(gview, 0, i)
            self.gviews.append(gview)
            gview.setMaximumSize(50, self.settings['snippet_size'])
            gview.setVerticalScrollBarPolicy(1)
            gview.setHorizontalScrollBarPolicy(1)
            self.drawSnippet(gview, self.words[self.current][i][0])

            ledit = QLineEdit()
            self.grid.addWidget(ledit, 1, i)
            self.ledits.append(ledit)
            ledit.setMaximumSize(50, self.settings['input_size'])
            ledit.setAlignment(Qt.AlignHCenter)
            ledit.setText(self.words[self.current][i][1])

            for index, item in zip(range(50), self.ledits):
                item.textEdited.connect(partial(self.changeText, index))
        self.repaint()
        """
        pictures = len(self.img_fields)
        if pictures < len(self.imglist)-((self.current-1)*20):
            for i in range(20):
                if len(self.imglist) > (self.current*20)+i:
                    self.drawSnippet(self.img_fields[i], self.imglist[(self.current*20)+i])
                    self.input_fields[i].setText(self.charlist[(self.current*20)+i])
                else:
                    self.cleanSnippet(self.img_fields[i])
                    self.input_fields[i].setText("")
                    self.wizardPage2.fullfilled = True
                    self.wizardPage2.completeChanged.emit()
        """

    def previousWord(self):
        if self.current > 0:
            self.current -= 1
            self.showSet()

        self.next_button.setEnabled(True)

        if self.current == 0:
            self.prev_button.setEnabled(False)
        else:
            self.prev_button.setEnabled(True)

    def nextWord(self):
        #print self.maxcount
        if self.current < self.wordcount - 1:
            self.current += 1
            self.showSet()

        self.prev_button.setEnabled(True)

        if self.current == self.wordcount - 1:
            self.next_button.setEnabled(False)
            self.notifier.setText(
                "You checked every word now. If you corrected every letter continue to next page."
            )
        else:
            self.next_button.setEnabled(True)

    def cleanSnippet(self, graphicsview):
        scene = QGraphicsScene()
        graphicsview.setScene(scene)

    def drawOCRPreview(self):
        factor = 1.0
        img = self.prev[0]

        old_h = img.height()
        old_w = img.width()

        pix = img.scaled(
            QSize(self.preview.size().width() * factor,
                  self.preview.size().height() * factor), Qt.KeepAspectRatio,
            Qt.SmoothTransformation)
        #pix = img.scaled(self.preview.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)

        new_h = pix.height()
        new_w = pix.width()

        self.ratio_h = old_h / float(new_h)
        self.ratio_w = old_w / float(new_w)

        self.scene = QGraphicsScene()
        self.scene.addPixmap(pix)
        #self.scene.addPixmap(img)

        self.previewRects = []

        pen = QPen(Qt.yellow)
        redpen = QPen(Qt.red)
        bluepen = QPen(Qt.blue)
        greenpen = QPen(Qt.green)

        #for box in self.boxes():
        #    rect = self.addRect(self.scene, box, ratio_w, ratio_h, pen)
        #    self.previewRects.append(rect)
        rect = self.addRect(self.scene, self.boxlist[0], self.ratio_w,
                            self.ratio_h, pen)
        self.previewRects.append(rect)
        self.previewSetScene(self.scene)

    def drawSnippet(self, graphicsview, snippet):
        """Draw single result item to graphicsview"""
        try:
            h, w = snippet.shape
        except:
            h, w, c = snippet.shape
        if h < 1 or w < 1:
            return
        processedimage = array2qimage(snippet)
        pix = QPixmap()
        pix.convertFromImage(processedimage)
        pix = pix.scaled(graphicsview.width(),
                         graphicsview.height() - 1, Qt.KeepAspectRatio,
                         Qt.SmoothTransformation)
        scene = QGraphicsScene()
        scene.addPixmap(pix)
        graphicsview.setScene(scene)
        graphicsview.show()

    def addRect(self, scene, item, ratio_w, ratio_h, pen):
        """Adds a rectangle to scene and returns it."""
        rect = scene.addRect((item[0]) / ratio_w, (item[2]) / ratio_h,
                             item[1] / ratio_w, item[3] / ratio_h, pen)
        return rect

    def allBoxes(self):
        for i in range(self.file_list.count()):
            self.file_list.setCurrentRow(i)
            current = self.file_list.currentItem()

            res = self.results[i].station.name
            cres = self.results[i]
            self.charlist += list(res.value.replace(" ", "").upper())

            text = res.value.replace(" ", "")
            imgcount = len(self.results[i].station.name.units)
            charcount = len(text)
            word = []

            for j in range(imgcount):
                if j < charcount:
                    char = text[j]
                else:
                    char = ""
                unit = self.results[i].station.name.units[j]
                image = cres.station_img[unit[2]:unit[3] + 1, unit[0]:unit[1]]
                #cv2.imshow("x", image)
                #cv2.waitKey(0)
                h = res.h
                if len(image) > 0:
                    if ((h * 1.0) / len(image[0])) > 3:
                        y1 = res.y1
                        if y1 < 0:
                            y1 = 0
                        image = cres.station_img[y1:unit[3], unit[0]:unit[1]]
                        border = (h - len(image[0])) / 2
                        image = cv2.copyMakeBorder(image,
                                                   0,
                                                   0,
                                                   border,
                                                   border,
                                                   cv2.BORDER_CONSTANT,
                                                   value=(255, 255, 255))

                    if len(image) < h / 2.0:
                        y1 = res.y1
                        if y1 < 0:
                            y1 = 0
                        image = cres.station_img[y1:res.y2, unit[0]:unit[1]]
                        border = (h - len(image[0])) / 2
                        image = cv2.copyMakeBorder(image,
                                                   0,
                                                   0,
                                                   border,
                                                   border,
                                                   cv2.BORDER_CONSTANT,
                                                   value=(255, 255, 255))

                    th, tw = image.shape
                    if th < 1 or tw < 1:
                        image = np.ones((10, 10, 1), dtype=np.uint8) * 255
                    self.imglist.append(image)

                word.append([image, char])

            self.words.append(word)
            self.boundaries.append([
                i,
                [
                    res.box[0] + self.stationoffset[i][0][0],
                    res.box[1] + self.stationoffset[i][0][1],
                    res.box[2] + self.stationoffset[i][0][0],
                    res.box[3] + self.stationoffset[i][0][1]
                ]
            ])

            for line in self.results[i].commodities:
                for item in line.items:
                    if not item is None:
                        text = item.value.replace(" ", "")
                        imgcount = len(item.units)
                        charcount = len(text)
                        word = []

                        self.charlist += list(
                            item.value.replace(" ", "").upper())
                        for j in range(imgcount):
                            if j < charcount:
                                char = text[j]
                            else:
                                char = ""
                            unit = item.units[j]
                            self.boxlist.append([
                                unit[0] + current.market_offset[0],
                                unit[1] - unit[0],
                                unit[2] + current.market_offset[1],
                                unit[3] - unit[2]
                            ])

                            image = cres.commodities_img[unit[2]:unit[3] + 1,
                                                         unit[0]:unit[1]]
                            h = line.h
                            if len(image) > 0:
                                if ((h * 1.0) / len(image[0])) > 3:
                                    y1 = line.y1 if line.y1 >= 0 else 0
                                    if y1 < 0:
                                        y1 = 0
                                    image = cres.commodities_img[
                                        y1:unit[3], unit[0]:unit[1]]
                                    if image.shape[0] > 0 and image.shape[
                                            1] > 0:
                                        border = (h - len(image[0])) / 2
                                        image = cv2.copyMakeBorder(
                                            image,
                                            0,
                                            0,
                                            border,
                                            border,
                                            cv2.BORDER_CONSTANT,
                                            value=(255, 255, 255))

                                if len(image) < h / 2.0:
                                    y1 = line.y1 if line.y1 >= 0 else 0
                                    if y1 < 0:
                                        y1 = 0
                                    image = cres.commodities_img[
                                        y1:line.y2, unit[0]:unit[1]]
                                    if image.shape[0] > 0 and image.shape[
                                            1] > 0:
                                        border = (h - len(image[0])) / 2
                                        image = cv2.copyMakeBorder(
                                            image,
                                            0,
                                            0,
                                            border,
                                            border,
                                            cv2.BORDER_CONSTANT,
                                            value=(255, 255, 255))

                                th, tw = image.shape
                                if th < 1 or tw < 1:
                                    image = np.ones(
                                        (10, 10, 1), dtype=np.uint8) * 255
                                self.imglist.append(image)

                            word.append([image, char])

                        self.words.append(word)
                        self.boundaries.append([
                            i,
                            [
                                item.box[0] + self.marketoffset[i][0][0],
                                item.box[1] + self.marketoffset[i][0][1],
                                item.box[2] + self.marketoffset[i][0][0],
                                item.box[3] + self.marketoffset[i][0][1]
                            ]
                        ])
        self.wordcount = len(self.words)
        #self.maxcount = len(self.imglist)/20

    def setPreviewImage(self, image):
        """Show image in self.preview."""
        #factor = self.factor.value()
        factor = 1.0
        pix = image.scaled(
            QSize(self.preview.size().width() * factor,
                  self.preview.size().height() * factor), Qt.KeepAspectRatio,
            Qt.SmoothTransformation)
        scene = QGraphicsScene()
        scene.addPixmap(pix)
        self.previewSetScene(scene)

    def previewSetScene(self, scene):
        """Shows scene in preview"""
        self.preview.setScene(scene)
        self.preview.show()
Esempio n. 33
0
def setAni(label,path,parent=None):
	pix=QMovie(path,parent=parent)
	label.setMovie(pix)
	pix.start()
Esempio n. 34
0
class Radar(QtGui.QLabel):
    def __init__(self, parent, radar, rect, myname):
        global xscale, yscale
        self.myname = myname
        self.rect = rect
        self.baseurl = self.mapurl(radar, rect, False)
        #print "google map base url: "+self.baseurl
        self.mkurl = self.mapurl(radar, rect, True)
        self.wxurl = self.radarurl(radar, rect)
        QtGui.QLabel.__init__(self, parent)
        self.interval = Config.radar_refresh * 60
        self.lastwx = 0

        self.setObjectName("radar")
        self.setGeometry(rect)
        self.setStyleSheet("#radar { background-color: grey; }")
        self.setAlignment(Qt.AlignCenter)

        self.wwx = QtGui.QLabel(self)
        self.wwx.setObjectName("wx")
        self.wwx.setStyleSheet("#wx { background-color: transparent; }")
        self.wwx.setGeometry(0, 0, rect.width(), rect.height())

        self.wmk = QtGui.QLabel(self)
        self.wmk.setObjectName("mk")
        self.wmk.setStyleSheet("#mk { background-color: transparent; }")
        self.wmk.setGeometry(0, 0, rect.width(), rect.height())

        self.wxmovie = QMovie()

    def mapurl(self, radar, rect, markersonly):
        #'https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid&center='+rcenter.lat+','+rcenter.lng+'&zoom='+rzoom+'&size=300x275'+markersr;
        urlp = []

        if len(ApiKeys.googleapi) > 0: urlp.append('key=' + ApiKeys.googleapi)
        urlp.append('center=' + str(radar['center'].lat) + ',' +
                    str(radar['center'].lng))
        zoom = radar['zoom']
        rsize = rect.size()
        if rsize.width() > 640 or rsize.height() > 640:
            rsize = QtCore.QSize(rsize.width() / 2, rsize.height() / 2)
            zoom -= 1
        urlp.append('zoom=' + str(zoom))
        urlp.append('size=' + str(rsize.width()) + 'x' + str(rsize.height()))
        if markersonly:
            urlp.append('style=visibility:off')
        else:
            urlp.append('maptype=hybrid')
        for marker in radar['markers']:
            marks = []
            for opts in marker:
                if opts != 'location':
                    marks.append(opts + ':' + marker[opts])
            marks.append(
                str(marker['location'].lat) + ',' +
                str(marker['location'].lng))
            urlp.append('markers=' + '|'.join(marks))
        return 'http://maps.googleapis.com/maps/api/staticmap?' + '&'.join(
            urlp)

    def radarurl(self, radar, rect):
        #wuprefix = 'http://api.wunderground.com/api/';
        #wuprefix+wuapi+'/animatedradar/image.gif?maxlat='+rNE.lat+'&maxlon='+rNE.lng+'&minlat='+rSW.lat+'&minlon='+rSW.lng+wuoptionsr;
        #wuoptionsr = '&width=300&height=275&newmaps=0&reproj.automerc=1&num=5&delay=25&timelabel=1&timelabel.y=10&rainsnow=1&smooth=1';
        rr = getCorners(radar['center'], radar['zoom'], rect.width(),
                        rect.height())
        return (
            Config.wuprefix + ApiKeys.wuapi + '/animatedradar/image.gif' +
            '?maxlat=' + str(rr['N']) + '&maxlon=' + str(rr['E']) +
            '&minlat=' + str(rr['S']) + '&minlon=' + str(rr['W']) + '&width=' +
            str(rect.width()) + '&height=' + str(rect.height()) +
            '&newmaps=0&reproj.automerc=1&num=5&delay=25&timelabel=1&timelabel.y=10&rainsnow=1&smooth=1&radar_bitmap=1&xnoclutter=1&xnoclutter_mask=1&cors=1'
        )

    def basefinished(self):
        if self.basereply.error() != QNetworkReply.NoError: return
        self.basepixmap = QPixmap()
        self.basepixmap.loadFromData(self.basereply.readAll())
        if self.basepixmap.size() != self.rect.size():
            self.basepixmap = self.basepixmap.scaled(self.rect.size(),
                                                     Qt.KeepAspectRatio,
                                                     Qt.SmoothTransformation)
        self.setPixmap(self.basepixmap)

    def mkfinished(self):
        if self.mkreply.error() != QNetworkReply.NoError: return
        self.mkpixmap = QPixmap()
        self.mkpixmap.loadFromData(self.mkreply.readAll())
        if self.mkpixmap.size() != self.rect.size():
            self.mkpixmap = self.mkpixmap.scaled(self.rect.size(),
                                                 Qt.KeepAspectRatio,
                                                 Qt.SmoothTransformation)
        self.wmk.setPixmap(self.mkpixmap)

    def wxfinished(self):
        if self.wxreply.error() != QNetworkReply.NoError:
            print "get radar error " + self.myname + ":" + str(
                self.wxreply.error())
            self.lastwx = 0
            return
        print "radar map received:" + self.myname + ":" + time.ctime()
        self.wxmovie.stop()
        self.wxdata = QtCore.QByteArray(self.wxreply.readAll())
        self.wxbuff = QtCore.QBuffer(self.wxdata)
        self.wxbuff.open(QtCore.QIODevice.ReadOnly)
        mov = QMovie(self.wxbuff, 'GIF')
        print "radar map frame count:" + self.myname + ":" + str(
            mov.frameCount())
        if mov.frameCount() > 2:
            self.lastwx = time.time()
        else:
            # radar image retreval failed
            self.lastwx = 0
            # retry in 5 seconds
            QtCore.QTimer.singleShot(5 * 1000, self.getwx)
            return
        self.wxmovie = mov
        self.wwx.setMovie(self.wxmovie)
        if self.parent().isVisible():
            self.wxmovie.start()

    def getwx(self):
        global lastapiget
        i = 0.1
        # making sure there is at least 2 seconds between radar api calls
        lastapiget += 2
        if time.time() > lastapiget: lastapiget = time.time()
        else: i = lastapiget - time.time()
        print "get radar api call spacing oneshot get i=" + str(i)
        QtCore.QTimer.singleShot(i * 1000, self.getwx2)

    def getwx2(self):
        global manager
        try:
            if self.wxreply.isRunning(): return
        except Exception:
            pass
        print "getting radar map " + self.myname + ":" + time.ctime()
        self.wxreq = QNetworkRequest(
            QUrl(self.wxurl + '&rrrand=' + str(time.time())))
        self.wxreply = manager.get(self.wxreq)
        QtCore.QObject.connect(self.wxreply, QtCore.SIGNAL("finished()"),
                               self.wxfinished)

    def getbase(self):
        global manager
        self.basereq = QNetworkRequest(QUrl(self.baseurl))
        self.basereply = manager.get(self.basereq)
        QtCore.QObject.connect(self.basereply, QtCore.SIGNAL("finished()"),
                               self.basefinished)

    def getmk(self):
        global manager
        self.mkreq = QNetworkRequest(QUrl(self.mkurl))
        self.mkreply = manager.get(self.mkreq)
        QtCore.QObject.connect(self.mkreply, QtCore.SIGNAL("finished()"),
                               self.mkfinished)

    def start(self, interval=0):
        if interval > 0: self.interval = interval
        self.getbase()
        self.getmk()
        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"),
                               self.getwx)

    def wxstart(self):
        print "wxstart for " + self.myname
        if (self.lastwx == 0 or (self.lastwx + self.interval) < time.time()):
            self.getwx()
        # random 1 to 10 seconds added to refresh interval to spread the queries over time
        i = (self.interval + random.uniform(1, 10)) * 1000
        self.timer.start(i)
        self.wxmovie.start()
        QtCore.QTimer.singleShot(1000, self.wxmovie.start)

    def wxstop(self):
        print "wxstop for " + self.myname
        self.timer.stop()
        self.wxmovie.stop()

    def stop(self):
        try:
            self.timer.stop()
            self.timer = None
            if self.wxmovie: self.wxmovie.stop()
        except Exception:
            pass
Esempio n. 35
0
 def setMovie(self, gifName):
     m = QMovie(gifName)
     m.start()
     self.movie.setMovie(m)
Esempio n. 36
0
class ServerToolsWindow(base_class, ui_class):
    __metaclass__ = QSingleton

    def __init__(self, model, parent=None):
        super(ServerToolsWindow, self).__init__(parent)
        with Resources.directory:
            self.setupUi(self)
        self.spinner_movie = QMovie(
            Resources.get('icons/servertools-spinner.mng'))
        self.spinner_label.setMovie(self.spinner_movie)
        self.spinner_label.hide()
        self.progress_bar.hide()
        while self.tab_widget.count():
            self.tab_widget.removeTab(0)  # remove the tab(s) added in designer
        self.tab_widget.tabBar().hide()
        self.account_button.setMenu(QMenu(self.account_button))
        self.setWindowTitle('Blink Server Tools')
        self.setWindowIconText('Server Tools')
        self.model = model
        self.tab_widget.addTab(ServerToolsWebView(self), '')
        font = self.account_label.font()
        font.setPointSizeF(self.account_label.fontInfo().pointSizeF() + 2)
        font.setFamily("Sans Serif")
        self.account_label.setFont(font)
        self.model.rowsInserted.connect(self._SH_ModelChanged)
        self.model.rowsRemoved.connect(self._SH_ModelChanged)
        self.account_button.menu().triggered.connect(
            self._SH_AccountButtonMenuTriggered)
        web_view = self.tab_widget.currentWidget()
        web_view.loadStarted.connect(self._SH_WebViewLoadStarted)
        web_view.loadFinished.connect(self._SH_WebViewLoadFinished)
        web_view.loadProgress.connect(self._SH_WebViewLoadProgress)

    def _SH_AccountButtonMenuTriggered(self, action):
        view = self.tab_widget.currentWidget()
        account = action.data()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab=view.tab, task=view.task)

    def _SH_WebViewLoadStarted(self):
        self.spinner_label.show()
        self.spinner_movie.start()
        self.progress_bar.setValue(0)
        #self.progress_bar.show()

    def _SH_WebViewLoadFinished(self, load_ok):
        self.spinner_movie.stop()
        self.spinner_label.hide()
        self.progress_bar.hide()
        if not load_ok:
            web_view = self.tab_widget.currentWidget()
            icon_path = Resources.get('icons/invalid.png')
            error_message = web_view.last_error or 'Unknown error'
            html = """
            <html>
             <head>
              <style>
                .icon    { width: 64px; height: 64px; float: left; }
                .message { margin-left: 74px; line-height: 64px; vertical-align: middle; }
              </style>
             </head>
             <body>
              <img class="icon" src="file:%s" />
              <div class="message">Failed to load web page: <b>%s</b></div>
             </body>
            </html>
            """ % (icon_path, error_message)
            web_view.loadStarted.disconnect(self._SH_WebViewLoadStarted)
            web_view.loadFinished.disconnect(self._SH_WebViewLoadFinished)
            web_view.setHtml(html)
            web_view.loadStarted.connect(self._SH_WebViewLoadStarted)
            web_view.loadFinished.connect(self._SH_WebViewLoadFinished)

    def _SH_WebViewLoadProgress(self, percent):
        self.progress_bar.setValue(percent)

    def _SH_ModelChanged(self, parent_index, start, end):
        menu = self.account_button.menu()
        menu.clear()
        for row in xrange(self.model.rowCount()):
            account_info = self.model.data(self.model.index(row, 0),
                                           Qt.UserRole)
            action = QAction(account_info.name, self)
            action.setData(account_info.account)
            menu.addAction(action)

    def open_settings_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab='settings')
        self.show()

    def open_search_for_people_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab='contacts', task='directory')
        self.show()

    def open_history_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab='calls')
        self.show()
Esempio n. 37
0
class LearningWizard(QWizard, Ui_Wizard):
    def __init__(self, settings):
        QWizard.__init__(self)
        self.setupUi(self)
        self.settings = settings
        self.wizardPage3.pageCreated.connect(self.showSummary)
        self.wizardPage3.fullfilled = True

        self.wizardPage2.fullfilled = True
        self.errors = 0
        self.steps = 0
        self.delete_images_button.clicked.connect(self.deleteUserImages)
        self.add_files_button.clicked.connect(self.AddFiles)
        self.remove_file_button.clicked.connect(self.removeFile)
        self.save_button.clicked.connect(self.saveImgData)
        self.train_button.clicked.connect(self.trainOCR)
        self.ocr_button.clicked.connect(self.runOCR)
        self.next_button.clicked.connect(self.nextWord)
        self.prev_button.clicked.connect(self.previousWord)
        #self.add_screenshots.clicked.connect(self.AddFiles)
        #self.wizardPage2.pageCreated.connect(self.AnalyzeImg)
        #self.contrast = 0.0
        #self.img_fields = [self.g1,self.g2,self.g3,self.g4,self.g5,self.g6,self.g7,self.g8,self.g9,self.g10,self.g11,self.g12,self.g13,self.g14,self.g15,self.g16,self.g17,self.g18,self.g19,self.g20]
        #self.input_fields = [self.e1,self.e2,self.e3,self.e4,self.e5,self.e6,self.e7,self.e8,self.e9,self.e10,self.e11,self.e12,self.e13,self.e14,self.e15,self.e16,self.e17,self.e18,self.e19,self.e20]
        self.gviews = []
        self.ledits = []
        self.boxlist = []
        self.imglist = []
        self.charlist = []
        self.words = []
        self.boundaries = []
        self.wordcount = 0
        self.current = 0
        self.scene = None
        self.ratio_h = 1.0
        self.ratio_w = 1.0
        self.base = self.loadBase()
        self.user = self.loadUser()
        if not self.base is None:
            self.base_data_label.setText(self.getBaseData())
        if not self.user is None:
            self.delete_images_button.setEnabled(True)
            self.user_data_label.setText(self.getUserData())
        #self.resizeElements()
        
        #for index,item in zip(range(20), self.input_fields):
        #    item.textEdited.connect(partial(self.changeText, index))
        self.train_button.setEnabled(True)
        #self.grid = QGridLayout()
        #self.field_holder.addLayout(self.grid)
        
        
    def deleteUserImages(self):
        self.user = None
        path = self.settings.storage_path+os.sep+"user_training_data.pck"
        remove(path)
        self.user_data_label.setText("-")
        self.delete_images_button.setEnabled(False)
    
    def showSummary(self):
        summary = ""
        userdata = {}
        characters = ["'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '*', '+', '#']
        for word in self.words:
            for letter in word:
                if letter[1] in characters:
                    if letter[1] in userdata:
                        userdata[letter[1]] += 1
                    else:
                        userdata[letter[1]] = 1
        for key in characters:
            if key in userdata:
                summary += '"'+key+'"' +": " +str(userdata[key])+", "
                
        self.summary_label.setText(summary)
    
    def trainOCR(self):
        self.train_button.setEnabled(False)
        alldata = self.connectData()
        testnumbers = self.getRandomData(alldata,[',', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
        testletters = self.getRandomData(alldata,["'", ',', '-', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])
        teststation = self.getRandomData(alldata,["'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])
        testlevel   = self.getRandomData(alldata,['*', '+', '#'])
        self.movie = QMovie(":/ico/loader.gif")
        self.loader.setMovie(self.movie)
        self.movie.start()
        self.numberstrainerthread = Trainer(self, "numbers", self.base, self.user, testnumbers, testletters, teststation, testlevel)
        self.letterstrainerthread = Trainer(self, "letters", self.base, self.user, testnumbers, testletters, teststation, testlevel)
        self.stationtrainerthread = Trainer(self, "station", self.base, self.user, testnumbers, testletters, teststation, testlevel)
        self.leveltrainerthread   = Trainer(self, "level"  , self.base, self.user, testnumbers, testletters, teststation, testlevel)
        QObject.connect(self.numberstrainerthread, SIGNAL('finished(QString, int)'), self.stepFinished)
        QObject.connect(self.letterstrainerthread, SIGNAL('finished(QString, int)'), self.stepFinished)
        QObject.connect(self.stationtrainerthread, SIGNAL('finished(QString, int)'), self.stepFinished)
        QObject.connect(self.leveltrainerthread  , SIGNAL('finished(QString, int)'), self.stepFinished)
        #QObject.connect(self.trainerthread, SIGNAL('finishedall(int)'), self.trainingFinished)
        self.numberstrainerthread.execute()
        self.letterstrainerthread.execute()
        self.stationtrainerthread.execute()
        self.leveltrainerthread.execute()
        self.training_summary.setText("Training in progress")

    def trainingFinished(self):
        if self.errors < 3:
            self.training_summary.setText("The training sucessfully finished. Your OCR accuracy should be very high.")
        elif self.errors < 6:
            self.training_summary.setText("The training sucessfully finished. Your OCR accuracy should satisfactory. You might still increase it by repeating this process with other screenshots.")
        elif self.errors < 10:
            self.training_summary.setText("The training sucessfully finished. Your OCR accuracy is sufficient but not perfect. You should repeat this process with other screenshots.")
        else:
            self.training_summary.setText("The training finished. Your OCR accuracy is not sufficient. You should repeat this process with other screenshots.")
        
    def stepFinished(self, value, error):
        self.steps += 1
        self.details.append(value+"\n")
        self.errors += error
        if self.steps == 3:
            self.trainingFinished()
            self.movie.stop()
            self.loader.clear()
    
    def connectData(self):
        connected = {}
        characters = ["'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '*', '+', '#']
        
        if self.user is None:
            self.user = {}
        if self.base is None:
            self.base = {}
            

        for char in characters:
            if char in self.base and char in self.user:
                connected[char] = self.base[char]+self.user[char]
            elif char in self.base:
                connected[char] = self.base[char]
            elif char in self.user:
                connected[char] = self.user[char]
        return connected
        
    def getRandomData(self, data, characters):
        self.testsamples = {}
        samples = 30
        
        for char in characters:
            amount = len(data[char])/400
            if amount > samples:
                picks = random.sample(range(amount), samples)
            else:
                picks = random.sample(range(amount), amount)
                
            temp = bitarray()
            for pick in picks:
                temp += data[char][pick*400:pick*400+400]
                
            self.testsamples[char] = temp
                
        return self.testsamples
    
    def saveImgData(self):
        characters = ["'", ',', '-', '&', '[', ']', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '*', '+', '#']
        
        if self.user is None:
            self.user = {}
            
        for word in self.words:
            for letter in word:
                if letter[1] in characters:
                    data = bitarray()
                    image = cv2.resize(letter[0], (20, 20))
                    ret,image = cv2.threshold(image,250,255,cv2.THRESH_BINARY)
                    for row in image:
                        for cell in row:
                            if cell == 255:
                                data.append(True)
                            else:
                                data.append(False)
                    if letter[1] in self.user:
                        self.user[letter[1]] += data
                    else:
                        self.user[letter[1]] = data
                    
        path = self.settings.storage_path+os.sep+"user_training_data.pck"
        file = gzip.GzipFile(path, 'wb')
        pickle.dump(self.user, file,-1)
        file.close()
        
        self.save_button.setEnabled(False)
        self.train_button.setEnabled(True)
                                
        
    
    def changeText(self, index):
        #print index
        self.words[self.current][index][1] = unicode(self.ledits[index].text())
    
    def getBaseData(self):
        text = ""
        keys = []
        for key in self.base:
            keys.append(key)
        keys.sort()
        for key in keys:
            text += key + ": " + str(len(self.base[key])/400)+", "
        #print keys
        return text
        
    def getUserData(self):
        text = ""
        keys = []
        for key in self.user:
            keys.append(key)
        keys.sort()
        for key in keys:
            text += key + ": " + str(len(self.user[key])/400)+", "
        return text
    
    def loadBase(self):
        try:
            path = self.settings.app_path+os.sep+"trainingdata"+os.sep+"base_training_data.pck"
            file = gzip.GzipFile(path, 'rb')
            letters = pickle.load(file)
            file.close()
            return letters
        except:
            return None
        
    def loadUser(self):
        try:
            path = self.settings.storage_path+os.sep+"user_training_data.pck"
            file = gzip.GzipFile(path, 'rb')
            letters = pickle.load(file)
            file.close()
            return letters
        except:
            return None
    
    def removeFile(self):
        item = self.file_list.currentItem()
        self.file_list.takeItem(self.file_list.currentRow())
        del item
    
    def AddFiles(self):
        if self.settings["native_dialog"]:
                files = QFileDialog.getOpenFileNames(self, "Open", self.settings['screenshot_dir'])
        else:
            files = QFileDialog.getOpenFileNames(self, "Open", self.settings['screenshot_dir'], options = QFileDialog.DontUseNativeDialog)

        if files == []:
            return
        first_item = None
        counter = 0
        for file in files:
            file1 = unicode(file).encode(sys.getfilesystemencoding())
            item = CustomQListWidgetItem(split(file1)[1], file1, self.settings)
            if first_item == None:
                first_item = item
            self.file_list.addItem(item)
            counter+=1
    """        
    def resizeElements(self):
        fields = self.input_fields
        for field in fields:
            field.setMinimumSize(QSize(0, self.settings['input_size']))
            field.setMaximumSize(QSize(16777215, self.settings['input_size']))
        canvases = self.img_fields
        for canvas in canvases:
            canvas.setMinimumSize(QSize(0, self.settings['snippet_size']))
            canvas.setMaximumSize(QSize(16777215, self.settings['snippet_size']))
    """        
    def runOCR(self):
        self.add_files_button.setEnabled(False)
        self.remove_file_button.setEnabled(False)
        self.ocr_button.setEnabled(False)
        self.file_list.setEnabled(False)
        self.repaint()
        self.current_image = 0
        self.results = []
        self.images = []
        self.prev = []
        self.marketoffset = []
        self.stationoffset = []
        files = self.file_list.count()
        for i in xrange(files):
            self.file_list.setCurrentRow(i)
            item = self.file_list.currentItem()
            color_image = item.loadColorImage()
            preview_image = item.addTestImage(color_image)
            self.images.append(color_image)
            self.prev.append(preview_image)
            #cv2.imshow("x", color_image)
            #cv2.waitKey(0)
            #
            #images.append(preview_image)
            #self.setPreviewImage(preview_image)
            #return
            self.stationoffset.append(item.ocr_areas.station_name)
            self.marketoffset.append(item.ocr_areas.market_table)
            current_result = OCR(color_image, item.ocr_areas, self.settings["ocr_language"], item, levels = False, levenshtein = False)
            
            self.results.append(current_result)
        self.allBoxes()
        #print len(self.words)
        #print self.words[1]
        self.next_button.setEnabled(True)
        self.prev_button.setEnabled(False)
        self.showSet()
        self.notifier.setText("You did not check every word yet.")

    
    def showSet(self):
        #self.snippet_preview
        
        bound = self.boundaries[self.current]
        #print self.current
        #print bound[1]
        image = self.images[bound[0]][bound[1][1]-2:bound[1][3]+3,bound[1][0]-2:bound[1][2]+2]
        self.drawSnippet(self.snippet_preview, image)
        for gview in self.gviews:
            self.grid.removeWidget(gview)
            gview.deleteLater()
            gview = None
        for ledit in self.ledits:
            self.grid.removeWidget(ledit)
            ledit.deleteLater()
            ledit = None
        self.gviews = []
        self.ledits = []
        letters = len(self.words[self.current])
        for i in range(letters):
            gview = QGraphicsView()
            self.grid.addWidget(gview,0,i)
            self.gviews.append(gview)
            gview.setMaximumSize(50, self.settings['snippet_size'])
            gview.setVerticalScrollBarPolicy(1)
            gview.setHorizontalScrollBarPolicy(1)
            self.drawSnippet(gview, self.words[self.current][i][0])
            
            ledit = QLineEdit()
            self.grid.addWidget(ledit,1,i)
            self.ledits.append(ledit)
            ledit.setMaximumSize(50, self.settings['input_size'])
            ledit.setAlignment(Qt.AlignHCenter)
            ledit.setText(self.words[self.current][i][1])
            
            for index,item in zip(range(50), self.ledits):
                item.textEdited.connect(partial(self.changeText, index))
        self.repaint()
        """
        pictures = len(self.img_fields)
        if pictures < len(self.imglist)-((self.current-1)*20):
            for i in range(20):
                if len(self.imglist) > (self.current*20)+i:
                    self.drawSnippet(self.img_fields[i], self.imglist[(self.current*20)+i])
                    self.input_fields[i].setText(self.charlist[(self.current*20)+i])
                else:
                    self.cleanSnippet(self.img_fields[i])
                    self.input_fields[i].setText("")
                    self.wizardPage2.fullfilled = True
                    self.wizardPage2.completeChanged.emit()
        """
            
    
    def previousWord(self):
        if self.current > 0:
            self.current -= 1
            self.showSet()
        
        self.next_button.setEnabled(True)
        
        if self.current == 0:
            self.prev_button.setEnabled(False)
        else:
            self.prev_button.setEnabled(True)
       
    def nextWord(self):
        #print self.maxcount
        if self.current < self.wordcount-1:
            self.current += 1
            self.showSet()
            
        self.prev_button.setEnabled(True)
            
        if self.current == self.wordcount-1:
            self.next_button.setEnabled(False)
            self.notifier.setText("You checked every word now. If you corrected every letter continue to next page.")
        else:
            self.next_button.setEnabled(True)
            
    def cleanSnippet(self, graphicsview):
        scene = QGraphicsScene()
        graphicsview.setScene(scene)
        
    def drawOCRPreview(self):
        factor = 1.0
        img = self.prev[0]
        
        old_h = img.height()
        old_w = img.width()
        
        pix = img.scaled(QSize(self.preview.size().width()*factor,self.preview.size().height()*factor), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        #pix = img.scaled(self.preview.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        
        new_h = pix.height()
        new_w = pix.width()
        
        self.ratio_h = old_h/float(new_h)
        self.ratio_w = old_w/float(new_w)
        
        self.scene = QGraphicsScene()
        self.scene.addPixmap(pix)
        #self.scene.addPixmap(img)
        
        self.previewRects = []

        pen = QPen(Qt.yellow)
        redpen = QPen(Qt.red)
        bluepen = QPen(Qt.blue)
        greenpen = QPen(Qt.green)
        
        #for box in self.boxes():
        #    rect = self.addRect(self.scene, box, ratio_w, ratio_h, pen)
        #    self.previewRects.append(rect)
        rect = self.addRect(self.scene, self.boxlist[0], self.ratio_w, self.ratio_h, pen)
        self.previewRects.append(rect)
        self.previewSetScene(self.scene)

    
    def drawSnippet(self, graphicsview, snippet):
        """Draw single result item to graphicsview"""
        try:
            h, w = snippet.shape
        except:
            h, w, c = snippet.shape
        if h < 1 or w <1:
            return
        processedimage = array2qimage(snippet)
        pix = QPixmap()
        pix.convertFromImage(processedimage)
        pix = pix.scaled(graphicsview.width(), graphicsview.height()-1, Qt.KeepAspectRatio, Qt.SmoothTransformation)
        scene = QGraphicsScene()
        scene.addPixmap(pix)
        graphicsview.setScene(scene)
        graphicsview.show()
    
    def addRect(self, scene, item, ratio_w, ratio_h, pen):
        """Adds a rectangle to scene and returns it."""
        rect = scene.addRect((item[0])/ratio_w , (item[2])/ratio_h,
                              item[1]/ratio_w, item[3]/ratio_h, pen)
        return rect
    
    def allBoxes(self):
        for i in range(self.file_list.count()):
            self.file_list.setCurrentRow(i)
            current = self.file_list.currentItem()
            
            res = self.results[i].station.name
            cres = self.results[i]
            self.charlist += list(res.value.replace(" ", "").upper())
            
            text = res.value.replace(" ", "")
            imgcount = len(self.results[i].station.name.units)
            charcount = len(text)
            word = []
            
            for j in range(imgcount):
                if j < charcount:
                    char = text[j]
                else:
                    char = ""
                unit = self.results[i].station.name.units[j]
                image = cres.station_img[unit[2]:unit[3]+1,unit[0]:unit[1]]
                #cv2.imshow("x", image)
                #cv2.waitKey(0)
                h = res.h
                if len(image) > 0:
                    if ((h*1.0)/len(image[0])) > 3:
                        y1 = res.y1
                        if y1 < 0:
                            y1 = 0
                        image = cres.station_img[y1:unit[3], unit[0]:unit[1]]
                        border = (h - len(image[0]))/2
                        image = cv2.copyMakeBorder(image,0,0,border,border,cv2.BORDER_CONSTANT,value=(255,255,255))

                    if len(image) < h/2.0:
                        y1 = res.y1
                        if y1 < 0:
                            y1 = 0
                        image = cres.station_img[y1:res.y2, unit[0]:unit[1]]
                        border = (h - len(image[0]))/2
                        image = cv2.copyMakeBorder(image,0,0,border,border,cv2.BORDER_CONSTANT,value=(255,255,255))
                    
                    th, tw = image.shape
                    if th < 1 or tw < 1:
                        image = np.ones((10,10,1), dtype=np.uint8) * 255
                    self.imglist.append(image)
                    
                word.append([image, char])
                
            self.words.append(word)
            self.boundaries.append([i, [res.box[0]+self.stationoffset[i][0][0],
                                        res.box[1]+self.stationoffset[i][0][1],
                                        res.box[2]+self.stationoffset[i][0][0],
                                        res.box[3]+self.stationoffset[i][0][1]]])

            for line in self.results[i].commodities:
                for item in line.items:
                    if not item is None:
                        text = item.value.replace(" ", "")
                        imgcount = len(item.units)
                        charcount = len(text)
                        word = []
                    
                        self.charlist += list(item.value.replace(" ", "").upper())
                        for j in range(imgcount):
                            if j < charcount:
                                char = text[j]
                            else:
                                char = ""
                            unit = item.units[j]
                            self.boxlist.append([unit[0]+current.market_offset[0],unit[1]-unit[0],
                                            unit[2]+current.market_offset[1],unit[3]-unit[2]])
                                           
                            image = cres.commodities_img[unit[2]:unit[3]+1,unit[0]:unit[1]]
                            h = line.h
                            if len(image) > 0:
                                if ((h*1.0)/len(image[0])) > 3:
                                    y1 = line.y1 if line.y1 >= 0 else 0
                                    if y1 < 0:
                                        y1 = 0
                                    image = cres.commodities_img[y1:unit[3], unit[0]:unit[1]]
                                    if image.shape[0] > 0 and image.shape[1] > 0:
                                        border = (h - len(image[0]))/2
                                        image = cv2.copyMakeBorder(image,0,0,border,border,cv2.BORDER_CONSTANT,value=(255,255,255))

                                if len(image) < h/2.0:
                                    y1 = line.y1 if line.y1 >= 0 else 0
                                    if y1 < 0:
                                        y1 = 0
                                    image = cres.commodities_img[y1:line.y2, unit[0]:unit[1]]
                                    if image.shape[0] > 0 and image.shape[1] > 0:
                                        border = (h - len(image[0]))/2
                                        image = cv2.copyMakeBorder(image,0,0,border,border,cv2.BORDER_CONSTANT,value=(255,255,255))
                                
                                th, tw = image.shape
                                if th < 1 or tw < 1:
                                    image = np.ones((10,10,1), dtype=np.uint8) * 255
                                self.imglist.append(image)
                            
                            word.append([image, char])
                
                        self.words.append(word)
                        self.boundaries.append([i, [item.box[0]+self.marketoffset[i][0][0],
                                                    item.box[1]+self.marketoffset[i][0][1],
                                                    item.box[2]+self.marketoffset[i][0][0],
                                                    item.box[3]+self.marketoffset[i][0][1]]])
        self.wordcount = len(self.words)
        #self.maxcount = len(self.imglist)/20
        
    
    def setPreviewImage(self, image):
        """Show image in self.preview."""
        #factor = self.factor.value()
        factor = 1.0
        pix = image.scaled(QSize(self.preview.size().width()*factor,self.preview.size().height()*factor), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        scene = QGraphicsScene()
        scene.addPixmap(pix)
        self.previewSetScene(scene)
        
    def previewSetScene(self, scene):
        """Shows scene in preview"""
        self.preview.setScene(scene)
        self.preview.show()
Esempio n. 38
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.searchEdit.textChanged.connect(self.search_text_changed)
        self.ui.show_button.clicked.connect(self.show_episodes)
        self.ui.searchEdit.returnPressed.connect(self.show_episodes)
        self.episodes = None
        self.episode_list = None
        self.number = 0
        self.anime_list = None
        self.ui.download_button.clicked.connect(self.download)
        self.ui.res_list_widget.currentItemChanged.connect(self.episode_change)
        self.com = Comunicate()
        self.com.sig.connect(self.message)
        self.com.img.connect(self.set_image)
        self.ui.anime_list_widget.itemDoubleClicked.connect(self.show_episodes)
        self.setWindowIcon(QIcon(get_file('animes.png')))
        self.ui.anime_list_widget.itemPressed.connect(self.anime_entered)
        Thread(target=self.load_url_items).start()
        #self.load_url_items()
        self.movie = QMovie(get_file('ajax-loader.gif'))
        self.ui.loading_label.setMovie(self.movie)
        self.link = None
        self.main_download_page = None
        self.tray = SystemTrayIcon(QIcon(get_file('animes.png')), self.com,
                                   self)
        self.com.op.connect(self.show_semard)
        self.ui.action_About_Semard.activated.connect(self.about_semard)
        self.ui.action_Contato.activated.connect(self.show_feedback)
        self.setWindowTitle('Semard - Animes')
        self.browser = None
        self.player = None
        #self.player_window = player_w

    @Slot(str, bool)
    def openVideo(self, filepath, duplicate_mode):
        movie = os.path.expanduser(filepath)
        if 'http://' not in filepath:
            if not os.access(movie, os.R_OK):
                print('Error: %s file is not readable' % movie)
            sys.exit(1)

        split = urlparse.urlsplit(filepath)
        #name = QInputDialog.getText(self, 'Escolha nome do arquivo', 'Nome do arquivo:')
        name = split.path.split("/")[-1]
        #pa = os.path.join(res, name)
        if duplicate_mode:
            try:
                #media = instance.media_new(movie, 'sout=#duplicate{dst=file{dst=%s},dst=display}' % pa)
                pass
            except NameError:
                print('NameError: % (%s vs Libvlc %s)' %
                      (sys.exc_info()[1], vlc.__version__,
                       vlc.libvlc_get_version()))
        else:
            try:
                #media = instance.media_new(movie)
                if sys.platform in 'win32':
                    subprocess.Popen([os.path.join('vlc', 'vlc'), movie])
                else:
                    subprocess.Popen(['vlc', movie])
            except NameError:
                print('NameError: % (%s vs Libvlc %s)' %
                      (sys.exc_info()[1], vlc.__version__,
                       vlc.libvlc_get_version()))
                QMessageBox.critical(self, 'Erro', 'problema ao iniciar o vlc')
                # "--sout=#duplicate{dst=file{dst=example.mpg},dst=display}"

        #player = instance.media_player_new()
        #pplayer.set_media(media)
        #self.player_window.setMedia(media)
        #self.player_window.createUI()
        #self.player_window = Player()
        #media.parse()
        #self.player_window.setWindowTitle(media.get_meta(0))
        #self.player_window.show()
        #self.player_window.resize(640, 480)
        #if sys.platform == "linux2":  # for Linux using the X Server
        #    pplayer.set_xwindow(self.player_window.videoframe.winId())
        #elif sys.platform == "win32":  # for Windows
        #    pplayer.set_hwnd(self.player_window.videoframe.winId())
        #elif sys.platform == "darwin":  # for MacOS
        #    pplayer.set_agl(self.player_window.videoframe.windId())
        #pplayer.play()
        #self.player_window.updateUI()

    @Slot(str, str)
    def start_download(self, filepath, path):
        #thread = QThread(self)
        pbar = QtGui.QProgressBar(self.ui.tab_downloads)
        pbar.setMinimum(0)
        pbar.setMaximum(100)
        pbar.setValue(0)
        self.ui.formLayout.addRow(os.path.basename(path), pbar)
        pbar.show()
        dw = Downloader(str(filepath), str(path), pbar)
        dw.finished.connect(self.finished_download)
        dw.progresschanged.connect(self.show_download_progress)
        dw.started.connect(self.started_download)
        Thread(target=dw.download).start()
        #thread.started.connect(dw.download)
        #thread.finished.connect(self.finished_download)
        #dw.moveToThread(thread)
        #thread.start()

    def finished_download(self, pbar, filename):
        self.tray.showMessage(filename, u'Download concluído.')
        pbar.setValue(100)
        pbar.setEnabled(False)

    def started_download(self, filename):
        filename = os.path.basename(filename)
        self.tray.showMessage(filename, u'Download iniciado.')

    @Slot(float, QtGui.QProgressBar)
    def show_download_progress(self, progress, pbar):
        pbar.setValue(progress)

    def show_feedback(self):
        feed = Feedback(self.com)
        feed.exec_()

    def about_semard(self):
        about = QMessageBox.about(
            self, "Sobre Semard", u"""<b>Semard</b> v%s
        <p><b>Copyright (C) 2013</b> Ronnie Andrew.</p>
        <p>Todos os direitos reservados de acordo com a licença GNU GPL v3 ou posterior.</p>
        <p><b>Website Oficial:</b> <a href='https://github.com/ROAND/Series-Manager'>GitHub</a></p>
        <p><b>Plataforma: </b>%s</p>
          """ % (__version__, platform.system()))

    def show_semard(self, message):
        self.show()

    def closeEvent(self, event):
        self.hide()
        self.tray.showMessage(u'Semard', u'Semard ainda está em execução.')
        event.ignore()

    @Slot(str)
    def set_image(self, img_str):
        self.ui.image_label.setPixmap(QPixmap(img_str))

    @Slot(str)
    def message(self, message):
        if str(message) in 'ended':
            self.ui.loading_label.hide()
            # self.repaint()
            self.ui.anime_list_widget.setEnabled(True)
            self.ui.show_button.setEnabled(True)
            self.movie.stop()
        if str(message) in 'started':
            self.ui.loading_label.show()
            # self.repaint()
            self.ui.anime_list_widget.setEnabled(False)
            self.ui.show_button.setEnabled(False)
            self.movie.start()

    def anime_entered(self, item):
        pass

    def load_url_items(self):
        self.com.sig.emit('started')
        self.main_download_page = AnimeList('http://www.anbient.net/lista')
        self.number, self.anime_list = self.main_download_page.get_attrs()
        self.ui.avaLabel.setText('%s disponiveis.' % self.number)
        self.add_full_items_animelist()
        self.com.sig.emit('ended')

    def episode_change(self):
        self.com.sig.emit('started')
        self.ui.options_list_widget.clear()

        if self.ui.res_list_widget.currentItem():
            name = self.ui.res_list_widget.currentItem().text()
            episode = self.episode_list[name]
            self.ui.options_list_widget.addItems(episode.links)
            self.com.sig.emit('ended')

    def download(self):
        #name = self.ui.options_list_widget.currentItem().text()
        link = self.ui.options_list_widget.currentItem().text()
        self.com.sig.emit('started')
        msgBox = QMessageBox()
        msgBox.setWindowTitle(u'Informação')
        msgBox.setText(u'Browser padrão')
        msgBox.setInformativeText(
            u'Você deseja abrir este link com o seu browser padrão?')
        msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        msgBox.setDefaultButton(QMessageBox.Yes)
        ret = msgBox.exec_()
        if ret == QMessageBox.Yes:
            if sys.platform in 'win32':
                webbrowser.open(link)
            else:
                webbrowser.open(link)
        else:
            browser.ui.webView.setUrl(link)
            browser.show()
        self.com.sig.emit('ended')

    def keyPressEvent(self, event):
        if isinstance(event, PyQt4.QtGui.QKeyEvent):
            if event.key() == Qt.Key_Down:
                self.ui.anime_list_widget.setCurrentRow(
                    self.ui.anime_list_widget.currentRow() + 1)
            elif event.key() == Qt.Key_Up:
                self.ui.anime_list_widget.setCurrentRow(
                    self.ui.anime_list_widget.currentRow() - 1)

    @staticmethod
    def get_img_link(url):
        page = urllib2.urlopen(url)
        page_string = page.read().decode('utf-8')
        soup = BeautifulSoup(page_string)
        spans = soup.find_all('span', {'id': 'posterspan'})
        link = None
        for chil in spans:
            if isinstance(chil, bs4.element.Tag):
                for img in chil.children:
                    if isinstance(img, bs4.element.Tag):
                        link = img['src']
        return link

    def show_ep_thread(self):
        self.ui.res_list_widget.clear()
        anime_name = self.ui.anime_list_widget.currentItem().text()
        link = self.anime_list[anime_name]
        self.episodes = EpisodeList(link)
        # self.episodes.join()
        self.link = self.get_img_link(link)
        self.episode_list = self.episodes.get_episodes()

        anime_name = self.ui.anime_list_widget.currentItem().text()
        link = self.anime_list[anime_name]
        img_link = self.get_img_link(link)
        file_name = img_link
        if os.path.exists(get_file(file_name)):
            self.com.img.emit(get_file(file_name))
            # self.ui.image_label.setPixmap(QPixmap(get_file(file_name)))
        else:
            if img_link is not None:
                file_name = img_link.replace(
                    'http://www.anbient.net/sites/default/files/imagecache/242x0/imagens/poster/',
                    '')
                urllib.urlretrieve(
                    'http://www.anbient.net/sites/default/files/imagecache/242x0/imagens/poster/%s'
                    % file_name, get_file(file_name))
                self.com.img.emit(get_file(file_name))
                # self.ui.image_label.setPixmap(QPixmap(get_file(file_name)))

        self.ui.label_sinopse.setText(self.episodes.get_sinopse().strip())
        try:
            for name in reversed(sorted(self.episode_list.keys(), key=int)):
                episode = self.episode_list[name]
                name, links = episode.get_attrs()
                self.ui.res_list_widget.addItem(name)
        except:
            for name, episode in reversed(sorted(self.episode_list.items())):
                name, links = episode.get_attrs()
                self.ui.res_list_widget.addItem(name)
        self.com.sig.emit('ended')

    def show_episodes(self):
        Thread(target=self.show_ep_thread).start()
        self.com.sig.emit('started')

    def add_full_items_animelist(self):
        self.ui.anime_list_widget.clear()
        for name, link in sorted(self.anime_list.items()):
            self.ui.anime_list_widget.addItem(name)

    def search_text_changed(self, new_text):
        items = self.ui.anime_list_widget.findItems(new_text, Qt.MatchContains)
        if items:
            self.ui.anime_list_widget.setCurrentItem(items[0])
            self.ui.labelSearch.setText('')
        else:
            self.ui.labelSearch.setText('Not Found!')

    def setBrowser(self, browser_param):
        self.browser = browser_param
        self.browser.start_download.connect(self.start_download)
        self.browser.open_video.connect(self.openVideo)
Esempio n. 39
0
class MainWindow(QtGui.QMainWindow):
    def __init__(self):

        QtGui.QMainWindow.__init__(self)

        #Dimensiones originales
        size_x_Original = 1080
        size_y_Original = 1920

        #Clicked button
        self.p = 1.15
        self.b = 0.95

        #Flags Vista 2
        self.IsChecked = [['Red', False], ['Pink', False], ['Blue', False],
                          ['Black', False], ['Yellow', False]]

        #Direcciones de Imágenes de fondo
        self.MAIN_VIEW = "src/img/ArtesPowerRangers/Pantalla 1/1.jpg"
        self.VIEW_2 = "src/img/ArtesPowerRangers/Pantalla 2/1 Back.jpg"
        self.VIEW_3 = "src/img/ArtesPowerRangers/Pantalla 3/1 Back.jpg"
        self.VIEW_5 = "src/img/ArtesPowerRangers/Pantalla 5/Back5.jpg"
        self.VIEW_6 = "src/img/ArtesPowerRangers/Pantalla 7/Back-7.jpg"

        #Direcciones Caras Vista 3
        self.URL_FACES = [
            "src/img/ArtesPowerRangers/Pantalla 3/3 Rengers/Red.jpg",
            "src/img/ArtesPowerRangers/Pantalla 3/3 Rengers/Pink.jpg",
            "src/img/ArtesPowerRangers/Pantalla 3/3 Rengers/Blue.jpg",
            "src/img/ArtesPowerRangers/Pantalla 3/3 Rengers/Black.jpg",
            "src/img/ArtesPowerRangers/Pantalla 3/3 Rengers/Yellow.jpg"
        ]

        self.RED = "src/img/ArtesPowerRangers/Pantalla 2/Red.jpg"
        self.RED_BLOCK = "src/img/ArtesPowerRangers/Pantalla 2/red_blocked.png"
        self.BLUE = "src/img/ArtesPowerRangers/Pantalla 2/Blue.jpg"
        self.BLUE_BLOCK = "src/img/ArtesPowerRangers/Pantalla 2/azul_blocked.png"
        self.BLACK = "src/img/ArtesPowerRangers/Pantalla 2/black.jpg"
        self.BLACK_BLOCK = "src/img/ArtesPowerRangers/Pantalla 2/black_blocked.png"
        self.PINK = "src/img/ArtesPowerRangers/Pantalla 2/pink.jpg"
        self.PINK_BLOCK = "src/img/ArtesPowerRangers/Pantalla 2/pink_blocked.png"
        self.YELLOW = "src/img/ArtesPowerRangers/Pantalla 2/yellow.jpg"
        self.YELLOW_BLOCK = "src/img/ArtesPowerRangers/Pantalla 2/yellow_blocked.png"

        self.GIF = "src/img/gif_red.gif"

        self.PASS_MAIL = "aradmagol"
        self.MAIL = "*****@*****.**"

        # Se monta la interfaz de usuario para la pantalla principal
        self.ui = uic.loadUi("views/main.ui")

        #Se bloquea el marco superior
        self.ui.setWindowFlags(self.ui.windowFlags()
                               | QtCore.Qt.CustomizeWindowHint)
        self.ui.setWindowFlags(self.ui.windowFlags()
                               & ~QtCore.Qt.WindowMaximizeButtonHint)

        #Full Screen
        self.ui.showFullScreen()
        screen = QtGui.QDesktopWidget().screenGeometry()

        #Dimensiones de la pantalla
        self.size_x = screen.width()
        self.size_y = screen.height()

        #Relación imagen/pantalla
        rel_x = float(self.size_x) / float(size_x_Original)
        rel_y = float(self.size_y) / float(size_y_Original)

        #----------Vista 1---------------
        #Se carga la imagen principal
        palette = QPalette()
        palette.setBrush(
            QPalette.Background,
            QBrush(QPixmap(self.MAIN_VIEW).scaled(self.size_x, self.size_y)))
        self.ui.setPalette(palette)
        #Vista de inicio
        self.ui.setCurrentWidget(self.ui.View1)

        #----------Bóton Inicio-----------
        nx = self.ui.inicio_btn.width() * rel_x
        ny = self.ui.inicio_btn.height() * rel_y

        self.ui.inicio_btn.resize(int(nx), int(ny))
        self.ui.inicio_btn.move(int(self.size_x / 2 - nx / 2),
                                int(7 * self.size_y / 8))
        self.ui.inicio_btn.mousePressEvent = self.pressStartV1
        self.ui.inicio_btn.mouseReleaseEvent = self.releaseStartV1
        #----------------------------------

        #-----------Vista 2----------------
        #-----------Título-----------------
        tx = self.ui.title_v2.width() * rel_x
        ty = self.ui.title_v2.height() * rel_y

        self.ui.title_v2.resize(int(tx), int(ty))
        self.ui.title_v2.move(int(self.size_x / 2 - tx / 2),
                              int(self.size_y / 10))

        #----------Bóton Ranger Azul-------
        y_init = 403 * rel_y

        brx = self.ui.blue_ranger.width() * rel_x
        bry = self.ui.blue_ranger.height() * rel_y

        self.ui.blue_ranger.resize(int(brx), int(bry))
        self.ui.blue_ranger.move(int(self.size_x / 2 - brx / 2), int(y_init))
        self.ui.blue_ranger.mousePressEvent = self.pressBlue

        #----------Bóton Ranger Rosa-----------
        self.ui.pink_ranger.resize(int(brx), int(bry))
        self.ui.pink_ranger.move(int(self.size_x / 2 - brx / 2),
                                 int(y_init + bry))
        self.ui.pink_ranger.mousePressEvent = self.pressPink

        #----------Bóton Ranger Rojo-----------
        self.ui.red_ranger.resize(int(brx), int(bry))
        self.ui.red_ranger.move(int(self.size_x / 2 - brx / 2),
                                int(y_init + 2 * bry))
        self.ui.red_ranger.mousePressEvent = self.pressRed

        #----------Bóton Ranger Amarillo-----------
        self.ui.yellow_ranger.resize(int(brx), int(bry))
        self.ui.yellow_ranger.move(int(self.size_x / 2 - brx / 2),
                                   int(y_init + 3 * bry))
        self.ui.yellow_ranger.mousePressEvent = self.pressYellow

        #----------Bóton Ranger Negro-----------
        self.ui.black_ranger.resize(int(brx), int(bry))
        self.ui.black_ranger.move(int(self.size_x / 2 - brx / 2),
                                  int(y_init + 4 * bry))
        self.ui.black_ranger.mousePressEvent = self.pressBlack

        #----------Botón Continuar-------------
        self.y_init_btn = 1700 * rel_y

        c2x = self.ui.continue_btn.width() * rel_x
        c2y = self.ui.continue_btn.height() * rel_y

        self.ui.continue_btn.resize(int(c2x), int(c2y))
        self.ui.continue_btn.move(int(self.size_x / 2 - c2x / 2),
                                  int(self.y_init_btn))
        self.ui.continue_btn.mousePressEvent = self.pressContinueV2
        self.ui.continue_btn.mouseReleaseEvent = self.releaseContinueV2

        #--------------------------------------
        #Se guarda el tamaño original del botón
        self.x_red = self.ui.red_ranger.width()
        self.y_red = self.ui.red_ranger.height()

        #Se guarda el tamaño original del botón
        self.x_black = self.ui.black_ranger.width()
        self.y_black = self.ui.black_ranger.height()

        #Se guarda el tamaño original del botón
        self.x_pink = self.ui.pink_ranger.width()
        self.y_pink = self.ui.pink_ranger.height()

        #Se guarda el tamaño original del botón
        self.x_blue = self.ui.blue_ranger.width()
        self.y_blue = self.ui.blue_ranger.height()

        #Se guarda el tamaño original del botón
        self.x_yellow = self.ui.yellow_ranger.width()
        self.y_yellow = self.ui.yellow_ranger.height()

        #------------Vista 3--------------
        #-----------Título-----------------
        self.t3x = self.ui.title_v3.width() * rel_x
        t3y = self.ui.title_v3.height() * rel_y

        self.ui.title_v3.resize(int(self.t3x), int(t3y))
        self.ui.title_v3.move(int(self.size_x / 2 - self.t3x / 2),
                              int(self.size_y / 9))

        self.fx = self.ui.photo_ranger.width() * rel_x
        fy = self.ui.photo_ranger.height() * rel_y

        self.ui.photo_ranger.resize(int(self.fx), int(fy))
        self.ui.photo_ranger.move(int(self.size_x / 2 - self.fx / 2),
                                  int(self.size_y / 6))

        self.name_x = self.ui.name_v3.width() * rel_x
        self.name_y = self.ui.name_v3.height() * rel_y

        self.ui.name_v3.resize(int(self.name_x), int(self.name_y))
        self.ui.name_v3.move(int(self.size_x / 2 - self.name_x / 2),
                             int(self.size_y / 2 + 2 * self.name_y))

        #--------------Keyboard-----------
        self.promptTex = ""
        self.ui.keyboard.move(
            int(self.size_x / 2 - self.ui.keyboard.width() / 2),
            int(self.size_y / 2))
        self.ui.key_a.mouseReleaseEvent = self.key_a
        self.ui.key_b.mouseReleaseEvent = self.key_b
        self.ui.key_c.mouseReleaseEvent = self.key_c
        self.ui.key_d.mouseReleaseEvent = self.key_d
        self.ui.key_e.mouseReleaseEvent = self.key_e
        self.ui.key_f.mouseReleaseEvent = self.key_f
        self.ui.key_g.mouseReleaseEvent = self.key_g
        self.ui.key_h.mouseReleaseEvent = self.key_h
        self.ui.key_i.mouseReleaseEvent = self.key_i
        self.ui.key_j.mouseReleaseEvent = self.key_j
        self.ui.key_k.mouseReleaseEvent = self.key_k
        self.ui.key_l.mouseReleaseEvent = self.key_l
        self.ui.key_m.mouseReleaseEvent = self.key_m
        self.ui.key_n.mouseReleaseEvent = self.key_n
        self.ui.key_o.mouseReleaseEvent = self.key_o
        self.ui.key_p.mouseReleaseEvent = self.key_p
        self.ui.key_q.mouseReleaseEvent = self.key_q
        self.ui.key_r.mouseReleaseEvent = self.key_r
        self.ui.key_s.mouseReleaseEvent = self.key_s
        self.ui.key_t.mouseReleaseEvent = self.key_t
        self.ui.key_u.mouseReleaseEvent = self.key_u
        self.ui.key_v.mouseReleaseEvent = self.key_v
        self.ui.key_w.mouseReleaseEvent = self.key_w
        self.ui.key_x.mouseReleaseEvent = self.key_x
        self.ui.key_y.mouseReleaseEvent = self.key_y
        self.ui.key_z.mouseReleaseEvent = self.key_z

        self.ui.key_1.mouseReleaseEvent = self.key_1
        self.ui.key_2.mouseReleaseEvent = self.key_2
        self.ui.key_3.mouseReleaseEvent = self.key_3
        self.ui.key_4.mouseReleaseEvent = self.key_4
        self.ui.key_5.mouseReleaseEvent = self.key_5
        self.ui.key_6.mouseReleaseEvent = self.key_6
        self.ui.key_7.mouseReleaseEvent = self.key_7
        self.ui.key_8.mouseReleaseEvent = self.key_8
        self.ui.key_9.mouseReleaseEvent = self.key_9
        self.ui.key_0.mouseReleaseEvent = self.key_0

        self.ui.key_punto.mouseReleaseEvent = self.key_punto
        self.ui.key_puntocoma.mouseReleaseEvent = self.key_puntocoma
        self.ui.key_coma.mouseReleaseEvent = self.key_coma
        self.ui.key_space.mouseReleaseEvent = self.key_space
        self.ui.key_money.mouseReleaseEvent = self.key_money
        self.ui.key_cs.mouseReleaseEvent = self.key_cs
        self.ui.key_cc.mouseReleaseEvent = self.key_cc
        self.ui.key_guionbajo.mouseReleaseEvent = self.key_guion_bajo
        self.ui.key_guion.mouseReleaseEvent = self.key_guion_alto
        self.ui.key_admirar.mouseReleaseEvent = self.key_admiracion
        self.ui.key_porcentage.mouseReleaseEvent = self.key_porcentaje
        self.ui.key_arroba.mouseReleaseEvent = self.key_arroba
        self.ui.key_number.mouseReleaseEvent = self.key_number

        self.ui.key_delete.mouseReleaseEvent = self.key_delete

        #-------------Continuar-----------
        self.c3x = self.ui.continue_btn_V3.width() * rel_x
        c3y = self.ui.continue_btn_V3.height() * rel_y

        self.ui.continue_btn_V3.resize(int(self.c3x), int(c3y))
        self.ui.continue_btn_V3.move(int(self.size_x / 2 - self.c3x / 2),
                                     int(self.y_init_btn))
        self.ui.continue_btn_V3.mousePressEvent = self.pressContinueV3
        self.ui.continue_btn_V3.mouseReleaseEvent = self.releaseContinueV3

        #--------------Atrás--------------
        self.ax = self.ui.cancelar.width() * rel_x
        ay = self.ui.cancelar.height() * rel_y

        self.ui.cancelar.resize(int(self.ax), int(ay))
        self.ui.cancelar.move(int(self.size_x / 25), int(self.y_init_btn))
        self.ui.cancelar.mousePressEvent = self.pressCancelar
        self.ui.cancelar.mouseReleaseEvent = self.releaseCancelar

        self.firstTime = False

        #--------------Vista 5---------------
        #------------Muestra GIF-------------
        altura_gif = 350 * rel_y
        gif_x = self.ui.the_gif.width() * rel_x
        gif_y = self.ui.the_gif.height() * rel_y

        self.ui.the_gif.resize(int(gif_x), int(gif_y))
        self.ui.the_gif.move(int(self.size_x / 2 - gif_x / 2), int(altura_gif))
        #--------------Marco-----------------
        altura_mark = 1250 * rel_y
        mark_x = self.ui.cuadro.width() * rel_x
        mark_y = self.ui.cuadro.height() * rel_y

        self.ui.cuadro.resize(int(mark_x), int(mark_y))
        self.ui.cuadro.move(int(self.size_x / 2 - mark_x / 2),
                            int(altura_mark))
        #-----------Atrás botón--------------
        altura_atras = 1350 * rel_y
        base_atras = 130 * rel_x

        atras_x = self.ui.atras.width() * rel_x
        atras_y = self.ui.atras.height() * rel_y

        self.ui.atras.resize(int(atras_x), int(atras_y))
        self.ui.atras.move(int(base_atras), int(altura_atras))
        self.ui.atras.mousePressEvent = self.pressAtrasV5
        self.ui.atras.mouseReleaseEvent = self.releaseAtrasV5
        #-----------Continuar botón--------------
        base_con = 575 * rel_x

        con_x = self.ui.continuar_V5.width() * rel_x
        con_y = self.ui.continuar_V5.height() * rel_y

        self.ui.continuar_V5.resize(int(con_x), int(con_y))
        self.ui.continuar_V5.move(int(base_con), int(altura_atras))
        self.ui.continuar_V5.mousePressEvent = self.pressContinueV5
        self.ui.continuar_V5.mouseReleaseEvent = self.releaseContinueV5

        #Posiciones de los botones
        self.positionV2 = self.ui.continue_btn.pos()
        self.positionV3 = self.ui.continue_btn_V3.pos()
        self.positionV5 = self.ui.continuar_V5.pos()
        self.positionAtras = self.ui.atras.pos()
        self.positionCancelar = self.ui.cancelar.pos()

        #------------Vista 6---------------
        #------------Muestra GIF-------------
        self.altura_gif2 = 170 * rel_y
        self.gif2_x = self.ui.the_gif_validate.width() * rel_x
        gif2_y = self.ui.the_gif_validate.height() * rel_y

        self.ui.the_gif_validate.resize(int(self.gif2_x), int(gif2_y))
        self.ui.the_gif_validate.move(int(self.size_x / 2 - self.gif2_x / 2),
                                      int(self.altura_gif2))
        #----------Escribe Correo-------------
        self.altura_mail = 990 * rel_y
        self.mail_x = self.ui.title_V6.width() * rel_x
        mail_y = self.ui.title_V6.height() * rel_y

        self.ui.title_V6.resize(int(self.mail_x), int(mail_y))
        self.ui.title_V6.move(int(self.size_x / 2 - self.mail_x / 2),
                              int(self.altura_mail))

        #----------Acepto?-------------
        self.altura_acepto = 1650 * rel_y
        self.acepto_x = self.ui.acepto.width() * rel_x
        acepto_y = self.ui.acepto.height() * rel_y

        self.ui.acepto.resize(int(self.acepto_x), int(acepto_y))
        self.ui.acepto.move(int(self.size_x / 2 - self.acepto_x / 2),
                            int(self.altura_acepto))

        #Bandera para el uso del teclado :)
        self.flag_Key = 3  #La vista 3 es la original

        #Botón pantalla completa
        self.ui.next_btn.resize(self.size_x, self.size_y)
        self.ui.next_btn.move(0, 0)
        self.ui.next_btn.mousePressEvent = self.restart

        #Nombre
        self.name = ""
        #Correo
        self.email = ""

        self.ui.show()

    def sendMail(self, file):
        #Información de e-mail
        fromMail = self.MAIL
        toMail = self.email  #"*****@*****.**"

        msg = MIMEMultipart()

        msg['From'] = fromMail
        msg['To'] = toMail
        msg['Subject'] = "Power Ranger GIF"

        body = self.name + " Tenemos listo tu GIF!"

        msg.attach(MIMEText(body, 'plain'))

        attachment = open(file, "rb")

        part = MIMEBase('application', 'octet-stream')
        part.set_payload((attachment).read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition',
                        "attachment; filename= %s" % file)

        msg.attach(part)

        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(fromMail, self.PASS_MAIL)
        text = msg.as_string()

        try:
            server.sendmail(fromMail, toMail, text)
        except:
            print "Error al envío!"
        server.quit()

    #-----------KEYBOARD-------------
    def writePrompt(self):
        #self.ui.prompt.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom)
        if self.flag_Key == 3:
            if len(self.promptTex) > 15:
                self.promptTex = self.promptTex[:15]
            self.ui.prompt.setText(self.promptTex)
            self.name = self.promptTex
        else:
            self.ui.prompt.setText(self.promptTex.lower())
            self.mail = self.promptTex.lower()

    def key_delete(self, event):
        self.promptTex = self.promptTex[:-1]
        self.writePrompt()

    def key_a(self, event):
        self.promptTex = self.promptTex + "A"
        self.writePrompt()

    def key_b(self, event):
        self.promptTex = self.promptTex + "B"
        self.writePrompt()

    def key_c(self, event):
        self.promptTex = self.promptTex + "C"
        self.writePrompt()

    def key_d(self, event):
        self.promptTex = self.promptTex + "D"
        self.writePrompt()

    def key_e(self, event):
        self.promptTex = self.promptTex + "E"
        self.writePrompt()

    def key_f(self, event):
        self.promptTex = self.promptTex + "F"
        self.writePrompt()

    def key_g(self, event):
        self.promptTex = self.promptTex + "G"
        self.writePrompt()

    def key_h(self, event):
        self.promptTex = self.promptTex + "H"
        self.writePrompt()

    def key_i(self, event):
        self.promptTex = self.promptTex + "I"
        self.writePrompt()

    def key_j(self, event):
        self.promptTex = self.promptTex + "J"
        self.writePrompt()

    def key_k(self, event):
        self.promptTex = self.promptTex + "K"
        self.writePrompt()

    def key_l(self, event):
        self.promptTex = self.promptTex + "L"
        self.writePrompt()

    def key_m(self, event):
        self.promptTex = self.promptTex + "M"
        self.writePrompt()

    def key_n(self, event):
        self.promptTex = self.promptTex + "N"
        self.writePrompt()

    def key_o(self, event):
        self.promptTex = self.promptTex + "O"
        self.writePrompt()

    def key_p(self, event):
        self.promptTex = self.promptTex + "P"
        self.writePrompt()

    def key_q(self, event):
        self.promptTex = self.promptTex + "Q"
        self.writePrompt()

    def key_r(self, event):
        self.promptTex = self.promptTex + "R"
        self.writePrompt()

    def key_s(self, event):
        self.promptTex = self.promptTex + "S"
        self.writePrompt()

    def key_t(self, event):
        self.promptTex = self.promptTex + "T"
        self.writePrompt()

    def key_u(self, event):
        self.promptTex = self.promptTex + "U"
        self.writePrompt()

    def key_v(self, event):
        self.promptTex = self.promptTex + "V"
        self.writePrompt()

    def key_w(self, event):
        self.promptTex = self.promptTex + "W"
        self.writePrompt()

    def key_x(self, event):
        self.promptTex = self.promptTex + "X"
        self.writePrompt()

    def key_y(self, event):
        self.promptTex = self.promptTex + "Y"
        self.writePrompt()

    def key_z(self, event):
        self.promptTex = self.promptTex + "Z"
        self.writePrompt()

    def key_1(self, event):
        self.promptTex = self.promptTex + "1"
        self.writePrompt()

    def key_2(self, event):
        self.promptTex = self.promptTex + "2"
        self.writePrompt()

    def key_3(self, event):
        self.promptTex = self.promptTex + "3"
        self.writePrompt()

    def key_4(self, event):
        self.promptTex = self.promptTex + "4"
        self.writePrompt()

    def key_5(self, event):
        self.promptTex = self.promptTex + "5"
        self.writePrompt()

    def key_6(self, event):
        self.promptTex = self.promptTex + "6"
        self.writePrompt()

    def key_7(self, event):
        self.promptTex = self.promptTex + "7"
        self.writePrompt()

    def key_8(self, event):
        self.promptTex = self.promptTex + "8"
        self.writePrompt()

    def key_9(self, event):
        self.promptTex = self.promptTex + "9"
        self.writePrompt()

    def key_0(self, event):
        self.promptTex = self.promptTex + "0"
        self.writePrompt()

    def key_punto(self, event):
        self.promptTex = self.promptTex + "."
        self.writePrompt()

    def key_arroba(self, event):
        self.promptTex = self.promptTex + "@"
        self.writePrompt()

    def key_puntocoma(self, event):
        self.promptTex = self.promptTex + ";"
        self.writePrompt()

    def key_coma(self, event):
        self.promptTex = self.promptTex + ","
        self.writePrompt()

    def key_guion_bajo(self, event):
        self.promptTex = self.promptTex + "_"
        self.writePrompt()

    def key_guion_alto(self, event):
        self.promptTex = self.promptTex + "-"
        self.writePrompt()

    def key_porcentaje(self, event):
        self.promptTex = self.promptTex + "%"
        self.writePrompt()

    def key_money(self, event):
        self.promptTex = self.promptTex + "$"
        self.writePrompt()

    def key_admiracion(self, event):
        self.promptTex = self.promptTex + "!"
        self.writePrompt()

    def key_cs(self, event):
        self.promptTex = self.promptTex + "["
        self.writePrompt()

    def key_cc(self, event):
        self.promptTex = self.promptTex + "]"
        self.writePrompt()

    def key_space(self, event):
        self.promptTex = self.promptTex + " "
        self.writePrompt()

    def key_number(self, event):
        self.promptTex = self.promptTex + "#"
        self.writePrompt()

    #---------------------------------

    def checking(self, color):
        for i in range(len(self.IsChecked)):
            if self.IsChecked[i][0] == color:
                self.IsChecked[i][1] = True
            else:
                self.IsChecked[i][1] = False

    def unlock(self):
        for i in range(len(self.IsChecked)):
            if self.IsChecked[i][1] == True:
                if self.IsChecked[i][0] == 'Red':
                    self.releaseRed()
                elif self.IsChecked[i][0] == 'Blue':
                    self.releaseBlue()
                elif self.IsChecked[i][0] == 'Pink':
                    self.releasePink()
                elif self.IsChecked[i][0] == 'Black':
                    self.releaseBlack()
                elif self.IsChecked[i][0] == 'Yellow':
                    self.releaseYellow()

    def isSelected(self):
        k = False
        for i in range(len(self.IsChecked)):
            if self.IsChecked[i][1] == True:
                k = True
        return k

    def pressStartV1(self, event):
        START_BTN_PRESS = "src/img/ArtesPowerRangers/Pantalla 1/inicio_btn.png"

        #Imagen de press button
        startPress = QtGui.QPixmap(START_BTN_PRESS)

        #Se guarda el tamaño original del botón
        self.x_v1b1 = self.ui.inicio_btn.width()
        self.y_v1b1 = self.ui.inicio_btn.height()

        self.ui.inicio_btn.resize(int(self.x_v1b1 * self.b),
                                  int(self.y_v1b1 * self.b))

        position = self.ui.inicio_btn.pos()

        x = position.x()
        y = position.y()
        self.ui.inicio_btn.move(x + ((1 - self.b) * self.x_v1b1) / 2,
                                y + ((1 - self.b) * self.y_v1b1) / 2)
        self.ui.inicio_btn.setPixmap(startPress)

    def releaseStartV1(self, event):
        START_BTN_REL = "src/img/ArtesPowerRangers/Pantalla 1/inicio_btn.png"

        #Imagen de press button
        startRel = QtGui.QPixmap(START_BTN_REL)

        self.ui.inicio_btn.resize(self.x_v1b1, self.y_v1b1)

        position = self.ui.inicio_btn.pos()

        x = position.x()
        y = position.y()
        self.ui.inicio_btn.move(x - ((1 - self.b) * self.x_v1b1) / 2,
                                y - ((1 - self.b) * self.y_v1b1) / 2)
        self.ui.inicio_btn.setPixmap(startRel)

        #Acción Envía Vista 2
        self.View2()

    def View2(self):
        #Cambio de fondo vista 2
        palette = QPalette()
        palette.setBrush(
            QPalette.Background,
            QBrush(QPixmap(self.VIEW_2).scaled(self.size_x, self.size_y)))
        self.ui.setPalette(palette)

        self.ui.setCurrentWidget(self.ui.View2)

    def pressRed(self, event):
        if self.firstTime == False:
            blue_btn = QPixmap(self.BLUE_BLOCK)
            self.ui.blue_ranger.setPixmap(blue_btn)
            black_btn = QPixmap(self.BLACK_BLOCK)
            self.ui.black_ranger.setPixmap(black_btn)
            pink_btn = QPixmap(self.PINK_BLOCK)
            self.ui.pink_ranger.setPixmap(pink_btn)
            yellow_btn = QPixmap(self.YELLOW_BLOCK)
            self.ui.yellow_ranger.setPixmap(yellow_btn)
            self.firstTime = True

        #Red esta activo
        if (self.IsChecked[0][1] == False):
            self.unlock()
            self.checking('Red')

            self.ui.red_ranger.resize(int(self.x_red * self.p),
                                      int(self.y_red * self.p))
            position = self.ui.red_ranger.pos()

            x = position.x()
            y = position.y()
            self.ui.red_ranger.move(x + ((1 - self.p) * self.x_red) / 2,
                                    y + ((1 - self.p) * self.y_red) / 2)
            red_btn = QPixmap(self.RED)
            self.ui.red_ranger.setPixmap(red_btn)
            self.ui.red_ranger.raise_()

    def pressBlack(self, event):
        if self.firstTime == False:
            blue_btn = QPixmap(self.BLUE_BLOCK)
            self.ui.blue_ranger.setPixmap(blue_btn)
            red_btn = QPixmap(self.RED_BLOCK)
            self.ui.red_ranger.setPixmap(red_btn)
            pink_btn = QPixmap(self.PINK_BLOCK)
            self.ui.pink_ranger.setPixmap(pink_btn)
            yellow_btn = QPixmap(self.YELLOW_BLOCK)
            self.ui.yellow_ranger.setPixmap(yellow_btn)
            self.firstTime = True

        #Black esta activo
        if (self.IsChecked[3][1] == False):
            self.unlock()
            self.checking('Black')

            self.ui.black_ranger.resize(int(self.x_black * self.p),
                                        int(self.y_black * self.p))
            position = self.ui.black_ranger.pos()

            x = position.x()
            y = position.y()
            self.ui.black_ranger.move(x + ((1 - self.p) * self.x_black) / 2,
                                      y + ((1 - self.p) * self.y_black) / 2)
            black_btn = QPixmap(self.BLACK)
            self.ui.black_ranger.setPixmap(black_btn)
            self.ui.black_ranger.raise_()

    def pressPink(self, event):
        if self.firstTime == False:
            blue_btn = QPixmap(self.BLUE_BLOCK)
            self.ui.blue_ranger.setPixmap(blue_btn)
            black_btn = QPixmap(self.BLACK_BLOCK)
            self.ui.black_ranger.setPixmap(black_btn)
            red_btn = QPixmap(self.RED_BLOCK)
            self.ui.red_ranger.setPixmap(red_btn)
            yellow_btn = QPixmap(self.YELLOW_BLOCK)
            self.ui.yellow_ranger.setPixmap(yellow_btn)
            self.firstTime = True

        #Pink esta activo
        if (self.IsChecked[1][1] == False):
            self.unlock()
            self.checking('Pink')

            self.ui.pink_ranger.resize(int(self.x_pink * self.p),
                                       int(self.y_pink * self.p))
            position = self.ui.pink_ranger.pos()

            x = position.x()
            y = position.y()
            self.ui.pink_ranger.move(x + ((1 - self.p) * self.x_pink) / 2,
                                     y + ((1 - self.p) * self.y_pink) / 2)
            pink_btn = QPixmap(self.PINK)
            self.ui.pink_ranger.setPixmap(pink_btn)
            self.ui.pink_ranger.raise_()

    def pressBlue(self, event):
        if self.firstTime == False:
            red_btn = QPixmap(self.RED_BLOCK)
            self.ui.red_ranger.setPixmap(red_btn)
            black_btn = QPixmap(self.BLACK_BLOCK)
            self.ui.black_ranger.setPixmap(black_btn)
            pink_btn = QPixmap(self.PINK_BLOCK)
            self.ui.pink_ranger.setPixmap(pink_btn)
            yellow_btn = QPixmap(self.YELLOW_BLOCK)
            self.ui.yellow_ranger.setPixmap(yellow_btn)
            self.firstTime = True

        #Blue esta activo
        if (self.IsChecked[2][1] == False):
            self.unlock()
            self.checking('Blue')

            self.ui.blue_ranger.resize(int(self.x_blue * self.p),
                                       int(self.y_blue * self.p))
            position = self.ui.blue_ranger.pos()

            x = position.x()
            y = position.y()
            self.ui.blue_ranger.move(x + ((1 - self.p) * self.x_blue) / 2,
                                     y + ((1 - self.p) * self.y_blue) / 2)
            blue_btn = QPixmap(self.BLUE)
            self.ui.blue_ranger.setPixmap(blue_btn)
            self.ui.blue_ranger.raise_()

    def pressYellow(self, event):
        if self.firstTime == False:
            blue_btn = QPixmap(self.BLUE_BLOCK)
            self.ui.blue_ranger.setPixmap(blue_btn)
            black_btn = QPixmap(self.BLACK_BLOCK)
            self.ui.black_ranger.setPixmap(black_btn)
            pink_btn = QPixmap(self.PINK_BLOCK)
            self.ui.pink_ranger.setPixmap(pink_btn)
            red_btn = QPixmap(self.RED_BLOCK)
            self.ui.red_ranger.setPixmap(red_btn)
            self.firstTime = True

        #Yellow esta activo
        if (self.IsChecked[4][1] == False):
            self.unlock()
            self.checking('Yellow')

            self.ui.yellow_ranger.resize(int(self.x_yellow * self.p),
                                         int(self.y_yellow * self.p))
            position = self.ui.yellow_ranger.pos()

            x = position.x()
            y = position.y()
            self.ui.yellow_ranger.move(x + ((1 - self.p) * self.x_yellow) / 2,
                                       y + ((1 - self.p) * self.y_yellow) / 2)
            yellow_btn = QPixmap(self.YELLOW)
            self.ui.yellow_ranger.setPixmap(yellow_btn)
            self.ui.yellow_ranger.raise_()

    def pressContinueV2(self, event):
        #Se guarda el tamaño original del botón
        self.x_cV2 = self.ui.continue_btn.width()
        self.y_cV2 = self.ui.continue_btn.height()

        self.ui.continue_btn.resize(int(self.x_cV2 * self.b),
                                    int(self.y_cV2 * self.b))

        position = self.ui.continue_btn.pos()

        x = position.x()
        y = position.y()
        self.ui.continue_btn.move(x + ((1 - self.b) * self.x_cV2) / 2,
                                  y + ((1 - self.b) * self.y_cV2) / 2)
        #self.ui.continue_btn.setPixmap(startPress)

    def pressContinueV3(self, event):
        #Se guarda el tamaño original del botón
        self.x_cV3 = self.ui.continue_btn_V3.width()
        self.y_cV3 = self.ui.continue_btn_V3.height()

        self.ui.continue_btn_V3.resize(int(self.x_cV3 * self.b),
                                       int(self.y_cV3 * self.b))

        position = self.ui.continue_btn_V3.pos()

        x = position.x()
        y = position.y()
        self.ui.continue_btn_V3.move(x + ((1 - self.b) * self.x_cV3) / 2,
                                     y + ((1 - self.b) * self.y_cV3) / 2)
        #self.ui.continue_btn.setPixmap(startPress)

    def pressCancelar(self, event):
        #Se guarda el tamaño original del botón
        self.x_x = self.ui.cancelar.width()
        self.x_y = self.ui.cancelar.height()

        self.ui.cancelar.resize(int(self.x_x * self.b), int(self.x_y * self.b))

        position = self.ui.cancelar.pos()

        x = position.x()
        y = position.y()
        self.ui.cancelar.move(x + ((1 - self.b) * self.x_x) / 2,
                              y + ((1 - self.b) * self.x_y) / 2)
        #self.ui.continue_btn.setPixmap(startPress)

    def releaseRed(self):
        self.ui.red_ranger.resize(self.x_red, self.y_red)
        position = self.ui.red_ranger.pos()

        x = position.x()
        y = position.y()
        self.ui.red_ranger.move(x - ((1 - self.p) * self.x_red) / 2,
                                y - ((1 - self.p) * self.y_red) / 2)
        red_block = QPixmap(self.RED_BLOCK)
        self.ui.red_ranger.setPixmap(red_block)

    def releaseBlue(self):
        self.ui.blue_ranger.resize(self.x_blue, self.y_blue)
        position = self.ui.blue_ranger.pos()

        x = position.x()
        y = position.y()
        self.ui.blue_ranger.move(x - ((1 - self.p) * self.x_blue) / 2,
                                 y - ((1 - self.p) * self.y_blue) / 2)
        blue_block = QPixmap(self.BLUE_BLOCK)
        self.ui.blue_ranger.setPixmap(blue_block)

    def releasePink(self):
        self.ui.pink_ranger.resize(self.x_pink, self.y_pink)
        position = self.ui.pink_ranger.pos()

        x = position.x()
        y = position.y()
        self.ui.pink_ranger.move(x - ((1 - self.p) * self.x_pink) / 2,
                                 y - ((1 - self.p) * self.y_pink) / 2)
        pink_block = QPixmap(self.PINK_BLOCK)
        self.ui.pink_ranger.setPixmap(pink_block)

    def releaseYellow(self):
        self.ui.yellow_ranger.resize(self.x_yellow, self.y_yellow)
        position = self.ui.yellow_ranger.pos()

        x = position.x()
        y = position.y()
        self.ui.yellow_ranger.move(x - ((1 - self.p) * self.x_yellow) / 2,
                                   y - ((1 - self.p) * self.y_yellow) / 2)
        yellow_block = QPixmap(self.YELLOW_BLOCK)
        self.ui.yellow_ranger.setPixmap(yellow_block)

    def releaseBlack(self):
        self.ui.black_ranger.resize(self.x_black, self.y_black)
        position = self.ui.black_ranger.pos()

        x = position.x()
        y = position.y()
        self.ui.black_ranger.move(x - ((1 - self.p) * self.x_black) / 2,
                                  y - ((1 - self.p) * self.y_black) / 2)
        black_block = QPixmap(self.BLACK_BLOCK)
        self.ui.black_ranger.setPixmap(black_block)

    def releaseContinueV2(self, event):
        self.ui.continue_btn.resize(self.x_cV2, self.y_cV2)

        x = self.positionV2.x()
        y = self.positionV2.y()
        self.ui.continue_btn.move(x, y)
        #self.ui.continue_btn.setPixmap(startRel)
        if self.isSelected() == True:
            self.flag_Key = 3
            self.ui.prompt.setText("")
            self.promptTex = ""
            self.View3()

    def releaseCancelar(self, event):
        self.ui.cancelar.resize(self.x_x, self.x_y)

        x = self.positionCancelar.x()
        y = self.positionCancelar.y()
        self.ui.cancelar.move(x, y)

        self.View1()

    def releaseContinueV3(self, event):
        self.ui.continue_btn_V3.resize(self.x_cV3, self.y_cV3)

        if self.flag_Key == 3:
            x = self.positionV3.x()
            y = self.positionV3.y()
            self.ui.continue_btn_V3.move(x, y)

            if self.promptTex != "":
                self.View4()
        else:
            self.ui.continue_btn_V3.move(int(self.size_x / 2),
                                         int(self.y_init_btn))

            if self.promptTex != "" and self.ui.acepto_btn.isChecked() == True:
                self.View6()

    def pressContinueV5(self, event):
        #Se guarda el tamaño original del botón
        self.x_cV5 = self.ui.continuar_V5.width()
        self.y_cV5 = self.ui.continuar_V5.height()

        self.ui.continuar_V5.resize(int(self.x_cV5 * self.b),
                                    int(self.y_cV5 * self.b))

        position = self.ui.continuar_V5.pos()

        x = position.x()
        y = position.y()
        self.ui.continuar_V5.move(x + ((1 - self.b) * self.x_cV5) / 2,
                                  y + ((1 - self.b) * self.y_cV5) / 2)
        #self.ui.continue_btn.setPixmap(startPress)

    def releaseContinueV5(self, event):
        self.ui.continuar_V5.resize(self.x_cV5, self.y_cV5)

        x = self.positionV5.x()
        y = self.positionV5.y()
        self.ui.continuar_V5.move(x, y)
        #Pasamos a la vista 6
        self.flag_Key = 5
        self.ui.prompt.setText("")
        self.promptTex = ""
        self.View3()
        #self.ui.continue_btn.setPixmap(startRel)

    def pressAtrasV5(self, event):
        #Se guarda el tamaño original del botón
        self.x_aV5 = self.ui.atras.width()
        self.y_aV5 = self.ui.atras.height()

        self.ui.atras.resize(int(self.x_aV5 * self.b),
                             int(self.y_aV5 * self.b))

        position = self.ui.atras.pos()

        x = position.x()
        y = position.y()
        self.ui.atras.move(x + ((1 - self.b) * self.x_aV5) / 2,
                           y + ((1 - self.b) * self.y_aV5) / 2)
        #self.ui.continue_btn.setPixmap(startPress)

    def releaseAtrasV5(self, event):
        self.ui.atras.resize(self.x_aV5, self.y_aV5)

        x = self.positionAtras.x()
        y = self.positionAtras.y()
        self.ui.atras.move(x, y)
        self.View4()
        #self.ui.continue_btn.setPixmap(startRel)

    def View1(self):
        #Nueva vista 1
        palette = QPalette()
        palette.setBrush(
            QPalette.Background,
            QBrush(QPixmap(self.MAIN_VIEW).scaled(self.size_x, self.size_y)))
        self.ui.setPalette(palette)

        #Reinicio de las opciones
        self.unlock()
        red_btn = QPixmap(self.RED)
        self.ui.red_ranger.setPixmap(red_btn)
        blue_btn = QPixmap(self.BLUE)
        self.ui.blue_ranger.setPixmap(blue_btn)
        black_btn = QPixmap(self.BLACK)
        self.ui.black_ranger.setPixmap(black_btn)
        pink_btn = QPixmap(self.PINK)
        self.ui.pink_ranger.setPixmap(pink_btn)
        yellow_btn = QPixmap(self.YELLOW)
        self.ui.yellow_ranger.setPixmap(yellow_btn)

        self.firstTime = False

        self.promptTex = ""
        self.flag_Key = 3
        self.IsChecked = [['Red', False], ['Pink', False], ['Blue', False],
                          ['Black', False], ['Yellow', False]]
        self.ui.acepto_btn.setChecked(False)

        self.ui.setCurrentWidget(self.ui.View1)

    def View3(self):
        #Nueva vista 3
        palette = QPalette()
        palette.setBrush(
            QPalette.Background,
            QBrush(QPixmap(self.VIEW_3).scaled(self.size_x, self.size_y)))
        self.ui.setPalette(palette)

        #Acción Envía Vista 3
        self.ui.setCurrentWidget(self.ui.View3)

        if self.flag_Key == 3:
            #Vista 3
            self.ui.title_v3.move(int(self.size_x / 2 - self.t3x / 2),
                                  int(self.size_y / 9))
            self.ui.photo_ranger.move(int(self.size_x / 2 - self.fx / 2),
                                      int(self.size_y / 6))
            self.ui.name_v3.move(int(self.size_x / 2 - self.name_x / 2),
                                 int(self.size_y / 2 + 2 * self.name_y))
            self.ui.continue_btn_V3.move(int(self.size_x / 2 - self.c3x / 2),
                                         int(self.y_init_btn))

            #Vista 6
            self.ui.the_gif_validate.move(self.size_x + 1, self.size_y + 1)
            self.ui.title_V6.move(self.size_x + 1, self.size_y + 1)
            self.ui.acepto.move(self.size_x + 1, self.size_y + 1)
            self.ui.acepto_btn.move(self.size_x + 1, self.size_y + 1)
            self.ui.cancelar.move(self.size_x + 1, self.size_y + 1)

            for i in range(len(self.IsChecked)):
                if self.IsChecked[i][1] == True:
                    face_ranger = QPixmap(self.URL_FACES[i])
                    self.ui.photo_ranger.setPixmap(face_ranger)
                    break

        elif self.flag_Key == 5:
            #Vista 6
            #----------------------
            #Aqui se pone el gif :)
            self.ui.the_gif_validate.setMovie(self.movie)
            self.movie.start()
            #----------------------

            self.ui.the_gif_validate.move(
                int(self.size_x / 2 - self.gif2_x / 2), int(self.altura_gif2))
            self.ui.title_V6.move(int(self.size_x / 2 - self.mail_x / 2),
                                  int(self.altura_mail))
            self.ui.acepto.move(int(self.size_x / 2 - self.acepto_x / 2),
                                int(self.altura_acepto))
            self.ui.acepto_btn.move(int(0.26 * self.size_x),
                                    int(self.altura_acepto + 5))
            self.ui.continue_btn_V3.move(int(self.size_x / 2),
                                         int(self.y_init_btn))
            self.ui.cancelar.move(int(self.size_x / 25), int(self.y_init_btn))

            #Vista 3
            self.ui.title_v3.move(self.size_x + 1, self.size_y + 1)
            self.ui.photo_ranger.move(self.size_x + 1, self.size_y + 1)
            self.ui.name_v3.move(self.size_x + 1, self.size_y + 1)

    def View4(self):
        #Pasamos a vista 4
        #Aquí va lo del GIF
        self.ui.setCurrentWidget(self.ui.View4)
        print "Tomamos la fotito... y pasamos a la otra vista"
        self.View5()

    def View5(self):
        #Pasamos vista 5
        #----------------------
        #Aqui se pone el gif :)
        self.movie = QMovie(self.GIF)
        self.ui.the_gif.setMovie(self.movie)
        self.movie.start()
        #----------------------

        #Te gusta la foto?
        self.ui.setCurrentWidget(self.ui.View5)

    def View6(self):
        #Pasamos a vista 6
        palette = QPalette()
        palette.setBrush(
            QPalette.Background,
            QBrush(QPixmap(self.VIEW_6).scaled(self.size_x, self.size_y)))
        self.ui.setPalette(palette)

        self.ui.setCurrentWidget(self.ui.View6)
        self.sendMail(self.GIF)

    def restart(self, event):
        self.View1()
Esempio n. 40
0
 def set_loading(self):
     movie = QMovie(":/images/loading.gif")
     self.labelLoading.setMovie(movie)
     self.labelLoading.setVisible(False)
     movie.start()
Esempio n. 41
0
 def set_loading(self):
     movie = QMovie(":/images/loading.gif")
     self.labelLoading.setMovie(movie)
     self.labelLoading.setVisible(False)
     movie.start()
Esempio n. 42
0
    def genOneTab(self, tabtitle="", tabbtn="", tabnums="", strwhere = "where studentsn like '03%' "):
        # tabtitle.setFixedHeight(40)
        # tabtitle.setFixedWidth(160)
        tabtitle.setFont(QFont('Courier New', 20))
        tabtitle.setText("随堂提问演板")
        tabtitle.setStyleSheet("border: 3px solid blue;\
            border-radius: 6px; \
            padding: 1px 18px 1px 20px;\
            min-width: 8em;")
        tabtitle.setMinimumHeight(50);
        titleLayout = QHBoxLayout()
        titleLayout.addWidget(tabtitle)
        titleLayout.setAlignment(tabtitle, Qt.AlignCenter)
       
        btnlayout = QGridLayout()
        
        cur = conn.cursor()
        strsql = "select studentsn, studentname from student " + strwhere
        cur.execute(strsql)
     
        tmpnum = 0
        for item in cur.fetchall():
            irow = tmpnum // 7
            icol = tmpnum % 7
            tmpnum += 1
            btnlayout.setRowMinimumHeight(irow, 80)

            tmpbtn = QPushButton(item[1])
            # tmpbtn.setFixedHeight(20)
            tmpbtn.setSizePolicy(QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding))
            # tmpbtn.setStyleSheet("border: 1px solid rgb(255,255,255,0);background-color: rgba(255,255,255,20);font-size:16px;")
            tmpbtn.setFlat(True)

            popMenu = QMenu(self)
            entry1 = popMenu.addAction("正确")
            self.connect(entry1,SIGNAL('triggered()'), lambda item=item[0]: self.answerRight(item))
            entry2 = popMenu.addAction("错误")
            self.connect(entry2,SIGNAL('triggered()'), lambda item=item[0]: self.answerWrong(item))
            entry3 = popMenu.addAction("替换")
            self.connect(entry3,SIGNAL('triggered()'), lambda item=item[0]: self.resetStudent(item))
            tmpbtn.setMenu(popMenu)
            tmpbtn.setAutoDefault(False)
            self.btngroup.addButton(tmpbtn, int(item[0]))

            tmpmovie = QMovie('image/ex_stu.gif', QByteArray(), self)
            tmplabel = QLabel()
            tmplabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
            tmplabel.setAlignment(Qt.AlignCenter)
            tmplabel.setMovie(tmpmovie)
            tmplabel.setScaledContents(True)
            tmplabel.setLayout(QHBoxLayout())
            tmplabel.layout().setContentsMargins(0,0,0,0)
            # tmplabel.setStyleSheet("border: 1px solid rgb(255,255,255,0);background-color: rgba(255,255,255,20);font-size:16px;")
            tmplabel.layout().addWidget(tmpbtn)
            tmpmovie.start()
            tmpmovie.stop()

            btnlayout.addWidget(tmplabel, irow, icol)

        tabbtn.setIcon(QIcon("image/start.png"))
        tabbtn.setStyleSheet("border: 5px solid yellow;")
        tabbtn.setFixedHeight(40)
        tabbtn.setFixedWidth(100)
        tabbtn.setFont(QFont('宋体', 20))
        # tabnums.setFixedHeight(45)
        # tabnums.setFixedWidth(60)
        tabnums.setFont(QFont('Courier New', 20))
        tabnums.setStyleSheet("border: 5px solid blue; color:red;font-weight:bold;font-size:26px;\
            border-radius: 6px; \
            padding: 1px 1px 1px 1px;\
            min-width: 2em; ")
        tabnums.setEditable(True)
        tabnums.lineEdit().setReadOnly(True);
        tabnums.lineEdit().setAlignment(Qt.AlignCenter);

        model = tabnums.model()
        for row in list(range(1, 7)):
            item = QStandardItem(str(row))
            item.setTextAlignment(Qt.AlignCenter)
            item.setForeground(QColor('red'))
            item.setBackground(QColor(0,200,50, 130))
            model.appendRow(item)
        tabnums.setCurrentIndex(2)
        # tabnums.setStyleSheet ("QComboBox::drop-down {border-width: 100px;}")
        # tabnums.setStyleSheet ("QComboBox::down-arrow {image: url(image/downarrow.png);top: 10px;left: 1px;}")

        bottomlayout = QHBoxLayout()
        bottomlayout.setSizeConstraint(QLayout.SetFixedSize)
        bottomlayout.addStretch(10)
        bottomlayout.addWidget(tabbtn)
        bottomlayout.setSpacing(5)
        bottomlayout.addWidget(tabnums)
     
        cur.close()
        return(titleLayout, btnlayout, bottomlayout)
Esempio n. 43
0
class UiController:

    def __init__(self, controller, debug_mode, logger):
        self.controller = controller
        self.datahandler = controller.datahandler
        self.debug_mode = debug_mode
        self.logger = logger

        ### Main Window
        self.main_widget = QMainWindow()
        self.main_widget.setAttribute(Qt.WA_Maemo5StackedWindow)
        self.main_ui = Ui_DropN900Widget()
        self.main_ui.setupUi(self.main_widget)

        # Stacked layout for context switching
        self.stacked_layout = QtGui.QStackedLayout()
        self.main_ui.centralwidget.setLayout(self.stacked_layout)

        # Menu items
        self.action_transfers = QtGui.QAction("Transfers", self.main_widget)
        self.action_settings = QtGui.QAction("Settings", self.main_widget)
        self.action_sync = QtGui.QAction("Synchronize", self.main_widget)
        self.action_sync_photos = QtGui.QAction("Sync Media", self.main_widget)
        self.action_console = QtGui.QAction("Show Log", self.main_widget)
        self.action_about = QtGui.QAction("About", self.main_widget)
        self.action_exit = QtGui.QAction("Exit", self.main_widget)

        self.main_ui.menubar.addAction(self.action_transfers)
        self.main_ui.menubar.addAction(self.action_settings)
        self.main_ui.menubar.addAction(self.action_sync)
        self.main_ui.menubar.addAction(self.action_sync_photos)
        self.main_ui.menubar.addAction(self.action_console)
        self.main_ui.menubar.addAction(self.action_about)
        self.main_ui.menubar.addAction(self.action_exit)

        # Connects
        self.action_transfers.triggered.connect(self.show_transfer_widget)
        self.action_sync.triggered.connect(self.synchronize_now)
        self.action_sync_photos.triggered.connect(self.synchronize_now_photos)
        self.action_settings.triggered.connect(self.show_settings_widget)
        self.action_console.triggered.connect(self.show_console)
        self.action_about.triggered.connect(self.show_about)
        self.action_exit.triggered.connect(self.shut_down)
        
        ### Trusted Login Widget
        self.trusted_login_widget = QWidget()
        self.trusted_login_ui = Ui_TrustedLoginWidget()
        self.trusted_login_ui.setupUi(self.trusted_login_widget)
        self.trusted_login_ui.label_icon.setPixmap(QPixmap(self.datahandler.datapath("ui/images/dropn900_logo.png")).scaled(65,65))

        # Connects
        self.trusted_login_ui.button_auth.clicked.connect(self.try_trusted_login)
        
        ### Manager Widget
        self.manager_widget = QWidget()
        self.manager_ui = Ui_ManagerWidget()
        self.manager_ui.setupUi(self.manager_widget)
        
        # Tree Controller
        tree = self.manager_ui.tree_widget
        self.tree_controller = TreeController(tree, self.manager_ui, self.controller, self.logger)

        # Hide public link elements on start
        self.manager_ui.button_copy_public_link.hide()
        self.manager_ui.button_open_public_link.hide()
        
        # Connects
        self.manager_ui.button_copy_public_link.clicked.connect(self.copy_item_link)
        self.manager_ui.button_open_public_link.clicked.connect(self.open_item_link)
        self.manager_ui.button_download.clicked.connect(self.item_download)
        self.manager_ui.button_upload.clicked.connect(self.item_upload)
        self.manager_ui.button_rename.clicked.connect(self.item_rename)
        self.manager_ui.button_remove.clicked.connect(self.item_remove)
        self.manager_ui.button_new_folder.clicked.connect(self.item_new_folder)
        self.manager_ui.sync_button.clicked.connect(self.synchronize_now)
        self.last_dl_location = None
        self.last_ul_location = None

        ### Console widget
        self.console_widget = QWidget(self.main_widget, Qt.Window)
        self.console_widget.setAttribute(Qt.WA_Maemo5StackedWindow)
        self.console_ui = Ui_ConsoleWidget()
        self.console_ui.setupUi(self.console_widget)
        self.console_ui.button_save.clicked.connect(self.save_log_to_file)
        self.console_ui.button_back.clicked.connect(self.hide_console)
        
        ### Settings widget
        self.settings_widget = None

        ### Fill stacked layout
        self.stacked_layout.addWidget(self.trusted_login_widget)
        self.stacked_layout.addWidget(self.manager_widget)
        self.stacked_layout.setCurrentWidget(self.trusted_login_widget)

        ### Loading Widget
        self.loading_widget = QWidget(self.manager_widget)
        self.loading_ui = Ui_LoadingWidget()
        self.loading_ui.setupUi(self.loading_widget)
        self.manager_ui.action_layout.insertWidget(3, self.loading_widget)
        self.loading_widget.hide()
        
        self.tree_controller.set_loading_ui(self.loading_ui)

        # Init loading animation
        self.loading_animation = QMovie(self.datahandler.datapath("ui/images/loading.gif"), "GIF", self.loading_ui.load_animation_label)
        self.loading_animation.setCacheMode(QMovie.CacheAll)
        self.loading_animation.setSpeed(150)
        self.loading_animation.setScaledSize(QtCore.QSize(48,48))
        self.loading_ui.load_animation_label.setMovie(self.loading_animation)

        # Init hide timer and icons for information messages
        self.information_message_timer = QTimer()
        self.information_message_timer.setSingleShot(True)
        self.information_message_timer.timeout.connect(self.hide_information_message)
        self.information_icon_ok = QPixmap(self.datahandler.datapath("ui/icons/check.png")).scaled(24,24)
        self.information_icon_error = QPixmap(self.datahandler.datapath("ui/icons/cancel.png")).scaled(24,24)
        self.information_icon_queue = QPixmap(self.datahandler.datapath("ui/icons/queue.png")).scaled(24,24)
        
        ### About dialog
        self.about_dialog = AboutDialog(self)
        
        self.set_synching(False)
        
    def set_synching(self, syncing):
        self.manager_ui.sync_button.setVisible(not syncing)
        self.manager_ui.sync_label.setVisible(syncing)

    def set_settings_widget(self, settings_widget):
        self.settings_widget = settings_widget
        
    def set_transfer_widget(self, transfer_widget):
        self.transfer_widget = transfer_widget
        
    def synchronize_now(self):
        self.settings_widget.sync_now_clicked()
        
    def synchronize_now_photos(self):
        self.controller.sync_manager.sync_media()
        
    def show(self):
        # Nokia N900 screen resolution, full screen
        self.main_widget.resize(800, 480) 
        self.main_widget.show()
        self.main_widget.showMaximized()

    def show_settings_widget(self):
        if self.settings_widget != None:
            if not self.settings_widget.isVisible():
                self.settings_widget.show()
                self.settings_widget.check_settings()

    def show_transfer_widget(self):
        if self.settings_widget.isVisible():
            self.settings_widget.hide()
        self.transfer_widget.show()
        
    def show_about(self):
        if not self.about_dialog.isVisible():
            self.about_dialog.show()
        
    def show_note(self, message):
        QMaemo5InformationBox.information(None, QString(message), 0)
        
    def show_banner(self, message, timeout = 5000):
        QMaemo5InformationBox.information(None, QString(message), timeout)
        
    def show_loading_ui(self, message = "", loading = True):
        self.loading_ui.info_label.setText(message)
        self.loading_ui.info_label_icon.hide()
        self.thumb_was_visible = self.manager_ui.thumb_container.isVisible()
        self.manager_ui.thumb_container.hide()
        self.loading_widget.show()

        self.loading_ui.load_animation_label.setVisible(loading)
        if loading:
            self.loading_animation.start()
        else:
            self.loading_animation.stop()

    def show_information_ui(self, message, succesfull, timeout = 4000):
        self.loading_ui.load_animation_label.hide()
        self.thumb_was_visible = self.manager_ui.thumb_container.isVisible()
        if self.thumb_was_visible:
            self.manager_ui.thumb_container.hide()
        self.loading_ui.info_label.setText(message)
        if succesfull == None:
            icon = self.information_icon_queue
        elif succesfull:
            icon = self.information_icon_ok
        else:
            icon = self.information_icon_error
        self.loading_ui.info_label_icon.setPixmap(icon)
        self.loading_ui.info_label_icon.show()
        self.loading_widget.show()
        self.information_message_timer.start(timeout)

    def hide_loading_ui(self):
        if not self.information_message_timer.isActive():
            self.loading_widget.hide()
        if self.loading_animation.state() == QMovie.Running:
            self.loading_animation.stop()

    def hide_information_message(self):
        self.loading_ui.info_label_icon.hide()
        self.hide_loading_ui()
        self.manager_ui.thumb_container.setVisible(self.thumb_was_visible)
            
    def try_trusted_login(self):
        self.trusted_login_ui.label_error.setText("")
        email = self.trusted_login_ui.line_edit_email.text()
        password = self.trusted_login_ui.line_edit_password.text()

        error = None
        if email.isEmpty():
            error = "Email can't be empty!"
        elif email.count("@") != 1:
            error = "Invalid email, check your @ signs!"
        elif email.contains(" "):
            error = "Invalid email, can't have spaces!"
        elif password.isEmpty():
            error = "Password can't be empty!"
            
        if error == None:
            self.show_banner("Authenticating...", 3000)
            self.set_trusted_login_info("Authenticating, please wait...")
            self.truested_email = self.datahandler.to_unicode(str(email.toUtf8()))
            self.trusted_password = self.datahandler.to_unicode(str(password.toUtf8()))
            QTimer.singleShot(100, self.do_trusted_login_networking)
        else:
            self.set_trusted_login_error(error)
            
    def set_trusted_login_error(self, error):
        self.trusted_login_ui.label_error.setStyleSheet("color: #9d1414;")
        self.trusted_login_ui.label_error.setText(error)
        self.truested_email = None
        self.trusted_password = None
        
    def set_trusted_login_info(self, info):
        self.trusted_login_ui.label_error.setStyleSheet("color: #149d2b;")
        self.trusted_login_ui.label_error.setText(info)
        
    def do_trusted_login_networking(self):
        self.controller.end_trusted_auth(self.truested_email.encode("utf-8"), self.trusted_password.encode("utf-8"))
        self.truested_email = None
        self.trusted_password = None
        
    def reset_trusted_login(self):
        self.trusted_login_ui.line_edit_email.clear()
        self.trusted_login_ui.line_edit_password.clear()
        self.trusted_login_ui.label_error.clear()

    def switch_context(self, view = None):
        widget = None
        if view == "trustedlogin":
            widget = self.trusted_login_widget
        if view == "manager":
            widget = self.manager_widget
        if view == "console":
            self.console_widget.show()
        if view == None and self.last_view != None:
            widget = self.last_view
        if widget != None:
            self.last_view = self.stacked_layout.currentWidget()
            self.stacked_layout.setCurrentWidget(widget)

    def get_selected_data(self):
        return self.tree_controller.selected_data
    
    # Signal handlers
            
    def shut_down(self):
        self.main_widget.close()

    def show_console(self):
        if self.console_widget.isVisible() == False:
            self.switch_context("console")
        else:
            self.hide_console()

    def hide_console(self):
        self.console_widget.hide()
                    
    def save_log_to_file(self):
        filename = self.datahandler.get_data_dir_path() + "dropn900.log"
        log_string = str(self.console_ui.text_area.toPlainText())
        try:
            log_file = open(filename, "w")
            log_file.write(log_string)
            log_file.close()
            self.show_banner("Log saved to " + filename)
        except IOError:
            self.logger.error("Could not open " + filename + " to save log")


    def browser_control_clicked(self):
        if self.controller.connected:
            self.switch_context()
        else:
            self.controller.end_auth()
            
    def copy_item_link(self):
        url = self.tree_controller.current_public_link
        if url == None:
            return
        self.datahandler.copy_url_to_clipboard(url)
    
    def open_item_link(self):
        url = self.tree_controller.current_public_link
        if url == None:
            return
        QDesktopServices.openUrl(QtCore.QUrl(url))

    def item_download(self):
        data = self.get_selected_data()
        if data == None:
            return
            
        if self.datahandler.dont_show_dl_dialog == False:
            # This dialog shows sometimes strange stuff on maemo5
            # It's a PyQt4 bug and its the best we got, you can cope with this
            if self.last_dl_location == None:
                self.last_dl_location = self.datahandler.get_data_dir_path()
            local_folder_path = QFileDialog.getExistingDirectory(self.manager_widget, QString("Select Download Folder"), QString(self.last_dl_location), QFileDialog.ShowDirsOnly|QFileDialog.HideNameFilterDetails|QFileDialog.ReadOnly)
            if local_folder_path.isEmpty():
                return
            py_unicode_path = self.datahandler.to_unicode(str(local_folder_path.toUtf8()))
            self.last_dl_location = py_unicode_path
            store_path = py_unicode_path + "/" + data.name
        else:
            dir_check = QDir(self.datahandler.get_data_dir_path())
            if not dir_check.exists():
                self.show_note("Cannot download, destination " + self.datahandler.get_data_dir_path() + " does not exist. Please set a new folder in settings.")
                return
            store_path = self.datahandler.get_data_dir_path() + data.name
        self.controller.connection.get_file(data.path, data.root, store_path, data.get_size(), data.mime_type)
        
    def item_upload(self):
        data = self.get_selected_data()
        if data == None or not data.is_folder():
            return

        # This dialog shows sometimes strange stuff on maemo5
        # It's a PyQt4 bug and its the best we got, you can cope with this
        if self.last_ul_location == None:
            self.last_ul_location = self.datahandler.get_data_dir_path()
        local_file_path = QFileDialog.getOpenFileName(self.manager_widget, QString("Select File for Upload"), QString(self.last_ul_location))
        if local_file_path.isEmpty():
            return
        py_unicode_path = self.datahandler.to_unicode(str(local_file_path.toUtf8()))
        self.last_ul_location = py_unicode_path[0:py_unicode_path.rfind("/")]
        self.controller.connection.upload_file(data.path, data.root, py_unicode_path)
        
    def item_rename(self):
        data = self.get_selected_data()
        if data == None:
            return

        # Get new name from user
        old_name = data.get_name()
        keyword = "file" if not data.is_folder() else "folder"
        new_name, ok = QInputDialog.getText(None, "Renaming " + keyword, "Give new name for " + keyword + " " + old_name, QtGui.QLineEdit.Normal, old_name)
        if not ok:
            return
        # Validate with QString
        if not self.is_name_valid(new_name, keyword):
            return
        # Make QString to python 'unicode'
        new_name = self.datahandler.to_unicode(str(new_name.toUtf8()))
        if old_name == new_name:
            return

        # Extension will be lost, ask user if he wants to leave it
        q_old_name = QtCore.QString(old_name)
        if q_old_name.contains("."):
            if not new_name.contains("."):
                format = old_name[q_old_name.lastIndexOf("."):]
                confirmation = QMessageBox.question(None, "Extension missing", "Do you want to append the original '" + format + "' extensions to the filename '" + new_name + "'?", QMessageBox.Yes, QMessageBox.No)
                if confirmation == QMessageBox.Yes:
                    new_name.append(format)

        # Get final new path and rename
        if data.parent == "/":
            new_name = data.parent + new_name
        else:
            new_name = data.parent + "/" + new_name
        self.controller.connection.rename(data.root, data.path, new_name, data)

    def item_remove(self):
        data = self.get_selected_data()
        if data == None:
            return
        if data.is_folder():
            confirmation = QMessageBox.question(None, "Remove folder verification", "Are you sure you want to remove the entire folder " + data.get_name() +"?", QMessageBox.Yes, QMessageBox.Cancel)
        else:
            confirmation = QMessageBox.question(None, "Remove file verification", "Are you sure you want to remove " + data.get_name() +"?", QMessageBox.Yes, QMessageBox.Cancel)            
        if confirmation == QMessageBox.Yes:
            self.controller.connection.remove_file(data.root, data.path, data.parent, data.is_folder())
        
    def item_new_folder(self):
        data = self.get_selected_data()
        if data == None:
            return
        if not data.is_folder():
            return
        
        full_create_path = data.path + "/"
        new_folder_name, ok = QInputDialog.getText(None, "Give new folder name", "")
        if not ok:
            return
        # Validate QString
        if not self.is_name_valid(new_folder_name, "folder"):
            return
        # Make QString to python unicode
        new_folder_name = self.datahandler.to_unicode(str(new_folder_name.toUtf8()))
        full_create_path = data.path + "/" + new_folder_name
        self.controller.connection.create_folder(data.root, full_create_path, new_folder_name, data.path)

    def is_name_valid(self, name, item_type):
        if name.isEmpty() or name.isNull():
            return False
        if name.contains("/"):
            self.show_information_ui("Cant use / in new " + item_type + " name", False)
            return False
        if name.contains("\\"):
            self.show_information_ui("Cant use \ in new " + item_type + " name", False)
            return False
        if name.startsWith(" "):
            self.show_information_ui("New " + item_type + " name cant start with a space", False)
            return False
        if name.endsWith(" "):
            self.show_information_ui("New " + item_type + " name cant end with a space", False)
            return False
        return True
Esempio n. 44
0
class ServerToolsWindow(base_class, ui_class):
    __metaclass__ = QSingleton

    def __init__(self, model, parent=None):
        super(ServerToolsWindow, self).__init__(parent)
        with Resources.directory:
            self.setupUi(self)
        self.spinner_movie = QMovie(Resources.get("icons/servertools-spinner.mng"))
        self.spinner_label.setMovie(self.spinner_movie)
        self.spinner_label.hide()
        self.progress_bar.hide()
        while self.tab_widget.count():
            self.tab_widget.removeTab(0)  # remove the tab(s) added in designer
        self.tab_widget.tabBar().hide()
        self.account_button.setMenu(QMenu(self.account_button))
        self.setWindowTitle("Blink Server Tools")
        self.setWindowIconText("Server Tools")
        self.model = model
        self.tab_widget.addTab(ServerToolsWebView(self), "")
        font = self.account_label.font()
        font.setPointSizeF(self.account_label.fontInfo().pointSizeF() + 2)
        font.setFamily("Sans Serif")
        self.account_label.setFont(font)
        self.model.rowsInserted.connect(self._SH_ModelChanged)
        self.model.rowsRemoved.connect(self._SH_ModelChanged)
        self.account_button.menu().triggered.connect(self._SH_AccountButtonMenuTriggered)
        web_view = self.tab_widget.currentWidget()
        web_view.loadStarted.connect(self._SH_WebViewLoadStarted)
        web_view.loadFinished.connect(self._SH_WebViewLoadFinished)
        web_view.loadProgress.connect(self._SH_WebViewLoadProgress)

    def _SH_AccountButtonMenuTriggered(self, action):
        view = self.tab_widget.currentWidget()
        account = action.data().toPyObject()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab=view.tab, task=view.task)

    def _SH_WebViewLoadStarted(self):
        self.spinner_label.setMovie(self.spinner_movie)
        self.spinner_label.show()
        self.spinner_movie.start()
        self.progress_bar.setValue(0)
        # self.progress_bar.show()

    def _SH_WebViewLoadFinished(self, load_ok):
        self.spinner_movie.stop()
        self.spinner_label.hide()
        self.progress_bar.hide()
        if not load_ok:
            web_view = self.tab_widget.currentWidget()
            icon_path = Resources.get("icons/invalid.png")
            error_message = web_view.last_error or "Unknown error"
            html = """
            <html>
             <head>
              <style>
                .icon    { width: 64px; height: 64px; float: left; }
                .message { margin-left: 74px; line-height: 64px; vertical-align: middle; }
              </style>
             </head>
             <body>
              <img class="icon" src="file:%s" />
              <div class="message">Failed to load web page: <b>%s</b></div>
             </body>
            </html>
            """ % (
                icon_path,
                error_message,
            )
            web_view.loadStarted.disconnect(self._SH_WebViewLoadStarted)
            web_view.loadFinished.disconnect(self._SH_WebViewLoadFinished)
            web_view.setHtml(html)
            web_view.loadStarted.connect(self._SH_WebViewLoadStarted)
            web_view.loadFinished.connect(self._SH_WebViewLoadFinished)

    def _SH_WebViewLoadProgress(self, percent):
        self.progress_bar.setValue(percent)

    def _SH_ModelChanged(self, parent_index, start, end):
        menu = self.account_button.menu()
        menu.clear()
        for row in xrange(self.model.rowCount()):
            account_info = self.model.data(self.model.index(row, 0), Qt.UserRole).toPyObject()
            action = QAction(account_info.name, self)
            action.setData(QVariant(account_info.account))
            menu.addAction(action)

    def open_settings_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data().toPyObject()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab="settings")
        self.show()

    def open_search_for_people_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data().toPyObject()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab="contacts", task="directory")
        self.show()

    def open_history_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data().toPyObject()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab="calls")
        self.show()

    def open_buy_pstn_access_page(self, account):
        view = self.tab_widget.currentWidget()
        account = account or view.account
        if account is None or account.server.settings_url is None:
            account = self.account_button.menu().actions()[0].data().toPyObject()
        self.account_label.setText(account.id)
        self.tab_widget.setTabText(self.tab_widget.currentIndex(), account.id)
        view.load_account_page(account, tab="payments")
        self.show()
Esempio n. 45
0
 def __init__(self, text, fileName):
     QLabel.__init__(self)
     self._text = text
     m = QMovie(fileName)
     m.start()
     self.setMovie(m)
Esempio n. 46
0
class VisionneurImagePourEKD(QScrollArea):
	''' Classe pour l'affichage des images (avec des barres de
	défilement)'''
	def __init__(self, img=None):
		QScrollArea.__init__(self)

		# Déclaration du drapeau: a-t-on chargé un *.gif
		if img and os.path.splitext(img)[1]!=".gif":
			self.gif = 1
		else:
			self.gif = 0
		
		# Facteur de redimensionnement de l'image à afficher par rapport à la taille réelle de l'image
		self.factor = 1
		
		# Variables de paramètres
		self.modeTransformation=Qt.SmoothTransformation
		#self.modeTransformation=Qt.FastTransformation
		
		# widget qui contiendra l'image
		self.imageLabel = QLabel()
		self.imageLabel.setAlignment(Qt.AlignCenter)
		
		self.setBackgroundRole(QPalette.Dark)
		self.setWidget(self.imageLabel)
		# Indispensable pour ne pas avoir d'images tronquées, lors du chargement de nvll img
		self.setWidgetResizable(True)
		
		# Position du curseur dans le QScrollArea au moment du clic de la souris
		self.positionPresseeSourisIni = QPoint()
		# Position du point haut-gauche du QScrollArea par rapport au QPixMap entier au
		# moment du clic de la souris (par la suite appelée "position de la barre de défilement")
        	self.positionBarrePresseeSourisIni = QPoint()
		
		# Création du menu contextuel
		self.menuZoom=QMenu("Zoom")
		
		# Entrée zoom taille réelle
		self.menuTailleReelle=self.menuZoom.addAction(_(u'&Taille Réelle'))
		self.menuTailleReelle.setIcon(QIcon("Icones" + os.sep + "taillereelle.png"))
		self.connect(self.menuTailleReelle, SIGNAL("triggered()"), self.setTailleReelle)
		
		# Entrée zoom taille fenetre
		self.menuTailleFenetre=self.menuZoom.addAction(_(u'&Adapter à la fenêtre'))
		self.menuTailleFenetre.setIcon(QIcon("Icones" + os.sep + "fenetre.png"))
		self.connect(self.menuTailleFenetre, SIGNAL("triggered()"), self.setTailleFenetre)
	
		# Entrée zoom +
		self.menuZoomPlus=self.menuZoom.addAction(_(u'&Zoom Avant'))
		self.menuZoomPlus.setIcon(QIcon("Icones" + os.sep + "zoomplus.png"))
		self.connect(self.menuZoomPlus, SIGNAL("triggered()"), self.zoomAvant)
		
		# Entrée zoom - 
		self.menuZoomMoins=self.menuZoom.addAction(_(u'&Zoom Arrière'))
		self.menuZoomMoins.setIcon(QIcon("Icones" + os.sep + "zoommoins.png"))
		self.connect(self.menuZoomMoins, SIGNAL("triggered()"), self.zoomArriere)
		
		# Entrée mettre en pause/démarrer l'animation du gif
		self.menuStartPauseGif=self.menuZoom.addAction(_(u"Mettre en pause/démarrer l'animation"))
		self.menuStartPauseGif.setIcon(QIcon("Icones" + os.sep + "player_end.png"))
		self.connect(self.menuStartPauseGif, SIGNAL("triggered()"), self.startPauseGif)
			
		# Entrée mettre en pause/démarrer l'animation du gif
		self.menuStopGif=self.menuZoom.addAction(_(u"Arrêter l'animation"))
		self.menuStopGif.setIcon(QIcon("Icones" + os.sep + "player_stop.png"))
		self.connect(self.menuStopGif, SIGNAL("triggered()"), self.stopGif)
		
		# On cache les 2 menus de *.gif si on ne traite pas ce format
		if not self.gif:
			self.menuStartPauseGif.setVisible(False)
			self.menuStopGif.setVisible(False)
		
		# Si une image est en paramètre de classe, on l'affiche directement
		# sinon on pourra toujours l'afficher plus tard en appelant la
		# méthode setImage(), le moment venu
		if img:
			self.setImage(img)
			self.setToolTip(img)
		else:
			# image par défaut
			self.setImage("Icones" + os.sep + "avant-image.png")
			self.setToolTip(_(u"image d'accueil"))
			self.setTailleReelle()
	
	def mousePressEvent(self, event):
		"Menu contextuel et enregistrement de données préparant le déplacement de l'image par pincement"
		
		# Menu contextuel
		if event.button() == Qt.RightButton: 
			self.menuZoom.popup(event.globalPos())
		
		# On enregistre la position du curseur et de la barre de défilement au moment du clic
		elif event.button() == Qt.LeftButton:
			self.positionPresseeSourisIni = QPoint(event.pos())
			self.positionBarrePresseeSourisIni.setX(self.horizontalScrollBar().value())
			self.positionBarrePresseeSourisIni.setY(self.verticalScrollBar().value())
			if PYQT_VERSION_STR >= "4.1.0": 
				# curseur main fermée
				self.setCursor(Qt.ClosedHandCursor)
			else: self.setCursor(Qt.SizeAllCursor)
			event.accept()
	
	def mouseMoveEvent(self, event):
		"Déplacement de l'image dans le QScrollArea quand la souris est pressée"
		
		if self.positionPresseeSourisIni.isNull():
			event.ignore()
			return
		
		# Nouvelles positions de la barre de défilement (selon x et y)
		self.horizontalScrollBar().setValue(self.positionBarrePresseeSourisIni.x() + (self.positionPresseeSourisIni.x() - event.pos().x()))
		self.verticalScrollBar().setValue(self.positionBarrePresseeSourisIni.y() + (self.positionPresseeSourisIni.y() - event.pos().y()))
		self.horizontalScrollBar().update()
		self.verticalScrollBar().update()
		event.accept()
	
	def mouseReleaseEvent(self, event):
		"Réaffichage du curseur classique de la souris"
		self.setCursor(Qt.ArrowCursor)
		event.accept()
	
	def setScaleMode(self, mode):
		"Choix du mode de redimensionnement"
		# Mise à jour du paramètre
		self.modeTransformation=mode
	
	def setTailleFenetre(self):
		"Affichage taille fenetre"
		
		# Gestion de la taille
		#- Si l'image rentre
		##- Si l'image est trop grande
		# On retaille l'image en gardant le ratio entre 
		# le min (si l'image ne rentre pas dans le cadre), le max (sinon) de :
		#         * La largeur de la fenetre
		#         * La largeur de l'image
		#         * La hauteur de la fenetre
		#         * La hauteur de l'image
		if (self.preview.height() < self.height()) and (self.preview.width() < self.width()):
			width=max(self.preview.width(), self.width())
			height=max(self.preview.height(), self.height())
		else :
			width=min(self.preview.width(), self.width())
			height=min(self.preview.height(), self.height())

		if self.gif:
			self.redimGif(width - 5, height - 5)
		else:
			resultat = self.preview.get_preview().scaled(width - 5, height - 5, Qt.KeepAspectRatio, self.modeTransformation)
			debug(u"Preview : %s, taille : %d, %d" % (self.preview.get_imageName(), self.preview.width(), self.preview.height()))
			self.factor = min(float(self.height())/self.preview.height(), float(self.width())/self.preview.width())
		
		#-- On met l'image et on redimensionne le Label pour les images simples
		if not self.gif:
			self.imageLabel.setPixmap(resultat)


			
	
	def setTailleReelle(self):
		"Fonction d'affichage en taille réelle"
		self.preview.origin()

		width, height = self.preview.width(), self.preview.height()

		# On redimensionne le label à la taille de l'image
		if self.gif:
			self.redimGif(width, height)
		else:
			self.imageLabel.setPixmap(self.preview.get_preview())
		self.factor = 1
	
	def zoomAvant(self):
		"Fonction de zoom avant 25%"
		
		# On redimensionne l'image à 125% de la taille actuelle
		factor = 5/4. * self.factor

		width = int(self.preview.width() * factor)
		height = int(self.preview.height() * factor)

		if self.gif:
			self.redimGif(width, height)
		else:
			image = self.preview.get_preview().scaled(width, height, Qt.KeepAspectRatio)
			self.imageLabel.setPixmap(image)
		self.factor = factor
	
	def zoomArriere(self):
		"Fonction de zoom arrière 25%"
		
		# On redimensionne l'image à 75% de la taille actuelle
		factor = 3/4. * self.factor

		width = int(self.preview.width() * factor)
		height = int(self.preview.height() * factor)

		if self.gif:
			self.redimGif(width, height)
		else:
			image = self.preview.get_preview().scaled(width, height, Qt.KeepAspectRatio)
			self.imageLabel.setPixmap(image)
		self.factor = factor
	
	def startPauseGif(self):
		"Démarrer/mettre en pause l'animation de l'image gif"
		if self.movie.state() == QMovie.NotRunning:
			self.movie.start()
		else:
			self.movie.setPaused(self.movie.state() != QMovie.Paused)
	
	def stopGif(self):
		"Arrêter l'animation de l'image gif"
		if self.movie.state() != QMovie.NotRunning:
			self.movie.stop()
	
	def redimGif(self, width, height):
		"""Changer la taille d'affichage du gif en prenant soin d'arrêter et de
		reprendre l'animation si nécessaire.
		Il y a un petit bogue d'affichage sur la redimension (il disparait en changeant
		d'onglet ou de cadre et en revenant.
		"""
		etatInitial = self.movie.state()
		if etatInitial == QMovie.Running:
			self.movie.stop()
		self.movie.setScaledSize(QSize(width, height))
		if etatInitial == QMovie.Running:
			self.movie.start()
		else:
			# On redémarre le gif sinon l'image n'est pas actualisée et reste à la même taille
			self.movie.start()
			self.movie.stop()
	
	def isGif(self):
		"Indique si l'image affichée est un gif. Le test est effectué sur l'extension du fichier"
		return self.gif
	
	def setImage(self, img=None, fauxChemin=None, anim=False):
		"""Fonction de mise en place de l'image.
		Le faux chemin est utile pour dissocier le chemin que verra l'utilisateur
		du chemin de l'image affichée. Ils sont différents uniquement lorsqu'une image
		composite est affichée (cadres masque alpha 3D et image composite).
		L'argument "anim" dit si une image gif doit être animée.
		"""
		
		if not img:
			img = "Icones" + os.sep + "avant-image.png"
			self.setToolTip(_(u"image d'accueil"))
			self.setTailleReelle()
			return
		elif fauxChemin:
			self.setToolTip(fauxChemin)
		else:
			self.setToolTip(img)
		
		# Chargement du gif le cas échéant
		if isinstance(img, str) or isinstance(img, unicode):
			# En général
			extension = os.path.splitext(img)[1]
		elif isinstance(img, QString):
			# Pour selectWidget.py principalement
			extension = "." + QFileInfo(img).suffix()
		if extension == ".gif":
			self.menuStartPauseGif.setVisible(True)
			self.menuStopGif.setVisible(True)
			self.gif = 1
			self.movie = QMovie(img)
			# On démarre le gif de toute façon sinon l'image n'est pas visible
			self.movie.start()
			if not anim:
				self.movie.stop()
			self.imageLabel.setMovie(self.movie)
		else:
			# Pour des images non-gif, on cache les menus d'animation
			self.menuStartPauseGif.setVisible(False)
			self.menuStopGif.setVisible(False)
			self.gif = 0
		

		# Visiblement sous windows la taille du QScrollArea renvoie 0,
		# on passe par l'Objet à l'intérieur pour obtenir la taille de l'image à créer
		self.preview = EkdPreview(img, self.width(), 0, 10, False, True, True) #(chemin, largeur, qualité, cache?, keepRatio?, magnify? )

		# Par défault on charge en taille fenetre
		self.setTailleFenetre()
Esempio n. 47
0
class Radar(QtGui.QLabel):

    def __init__(self, parent, radar, rect, myname):
        global xscale, yscale
        self.myname = myname
        self.rect = rect
        self.baseurl = self.mapurl(radar, rect, False)
        #print "google map base url: "+self.baseurl
        self.mkurl = self.mapurl(radar, rect, True)
        self.wxurl = self.radarurl(radar, rect)
        QtGui.QLabel.__init__(self, parent)
        self.interval = Config.radar_refresh*60
        self.lastwx = 0
        
        self.setObjectName("radar")
        self.setGeometry(rect)
        self.setStyleSheet("#radar { background-color: grey; }")    
        self.setAlignment(Qt.AlignCenter)

        self.wwx = QtGui.QLabel(self)
        self.wwx.setObjectName("wx")
        self.wwx.setStyleSheet("#wx { background-color: transparent; }")    
        self.wwx.setGeometry(0, 0, rect.width(), rect.height())

        self.wmk = QtGui.QLabel(self)
        self.wmk.setObjectName("mk")
        self.wmk.setStyleSheet("#mk { background-color: transparent; }")    
        self.wmk.setGeometry(0, 0, rect.width(), rect.height()) 

        self.wxmovie = QMovie()

    def mapurl(self, radar,rect,markersonly):
        #'https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid&center='+rcenter.lat+','+rcenter.lng+'&zoom='+rzoom+'&size=300x275'+markersr;
        urlp = [];
        
        if len(ApiKeys.googleapi) > 0: urlp.append('key='+ApiKeys.googleapi)
        urlp.append('center='+str(radar['center'].lat)+','+str(radar['center'].lng))
        zoom = radar['zoom']
        rsize = rect.size()
        if rsize.width() > 640 or rsize.height() > 640:
            rsize = QtCore.QSize(rsize.width()/2,rsize.height()/2)
            zoom -= 1
        urlp.append('zoom='+str(zoom))
        urlp.append('size='+str(rsize.width())+'x'+str(rsize.height()))
        if markersonly:
            urlp.append('style=visibility:off') 
        else:
            urlp.append('maptype=hybrid')
        for marker in radar['markers']:
            marks = []
            for opts in marker:
                if opts != 'location':
                    marks.append(opts + ':' + marker[opts])
            marks.append(str(marker['location'].lat)+','+str(marker['location'].lng))
            urlp.append('markers='+'|'.join(marks))
        return 'http://maps.googleapis.com/maps/api/staticmap?'+'&'.join(urlp)

    def radarurl(self,radar,rect):
        #wuprefix = 'http://api.wunderground.com/api/';
        #wuprefix+wuapi+'/animatedradar/image.gif?maxlat='+rNE.lat+'&maxlon='+rNE.lng+'&minlat='+rSW.lat+'&minlon='+rSW.lng+wuoptionsr;
        #wuoptionsr = '&width=300&height=275&newmaps=0&reproj.automerc=1&num=5&delay=25&timelabel=1&timelabel.y=10&rainsnow=1&smooth=1';
        rr = getCorners(radar['center'],radar['zoom'],rect.width(),rect.height())
        return (Config.wuprefix+ApiKeys.wuapi+'/animatedradar/image.gif'+
                '?maxlat='+str(rr['N'])+
                '&maxlon='+str(rr['E'])+
                '&minlat='+str(rr['S'])+
                '&minlon='+str(rr['W'])+
                '&width='+str(rect.width())+
                '&height='+str(rect.height())+
                '&newmaps=0&reproj.automerc=1&num=5&delay=25&timelabel=1&timelabel.y=10&rainsnow=1&smooth=1&radar_bitmap=1&xnoclutter=1&xnoclutter_mask=1&cors=1'
                )
    
    def basefinished(self):
        if self.basereply.error() != QNetworkReply.NoError: return
        self.basepixmap = QPixmap()
        self.basepixmap.loadFromData(self.basereply.readAll())
        if self.basepixmap.size() != self.rect.size():
            self.basepixmap = self.basepixmap.scaled(self.rect.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.setPixmap(self.basepixmap)
    
    def mkfinished(self):
        if self.mkreply.error() != QNetworkReply.NoError: return
        self.mkpixmap = QPixmap()
        self.mkpixmap.loadFromData(self.mkreply.readAll())
        if self.mkpixmap.size() != self.rect.size():
            self.mkpixmap = self.mkpixmap.scaled(self.rect.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.wmk.setPixmap(self.mkpixmap)

    def wxfinished(self):
        if self.wxreply.error() != QNetworkReply.NoError:
            print "get radar error "+self.myname+":"+str(self.wxreply.error())
            self.lastwx = 0
            return
        print "radar map received:"+self.myname+":"+time.ctime()
	self.wxmovie.stop()
        self.wxdata = QtCore.QByteArray(self.wxreply.readAll())
        self.wxbuff = QtCore.QBuffer(self.wxdata)
        self.wxbuff.open(QtCore.QIODevice.ReadOnly)
        mov = QMovie(self.wxbuff, 'GIF')
        print "radar map frame count:"+self.myname+":"+str(mov.frameCount())
        if mov.frameCount() > 2:
            self.lastwx = time.time()
        else:
            # radar image retreval failed
            self.lastwx = 0
            # retry in 5 seconds
            QtCore.QTimer.singleShot(5*1000, self.getwx)
            return
        self.wxmovie = mov
        self.wwx.setMovie( self.wxmovie)
        if self.parent().isVisible():
            self.wxmovie.start()

    def getwx(self):
        global lastapiget
        i = 0.1
        # making sure there is at least 2 seconds between radar api calls
        lastapiget += 2
        if time.time() > lastapiget: lastapiget = time.time()
        else: i = lastapiget - time.time()
        print "get radar api call spacing oneshot get i="+str(i)
        QtCore.QTimer.singleShot(i*1000, self.getwx2)

    def getwx2(self):
        global manager
        try:
            if self.wxreply.isRunning(): return
        except Exception:
            pass
        print "getting radar map "+self.myname+":"+time.ctime()
        self.wxreq = QNetworkRequest(QUrl(self.wxurl+'&rrrand='+str(time.time())))
        self.wxreply = manager.get(self.wxreq)
        QtCore.QObject.connect(self.wxreply, QtCore.SIGNAL("finished()"),self.wxfinished)

    def getbase(self):
        global manager
        self.basereq = QNetworkRequest(QUrl(self.baseurl))
        self.basereply = manager.get(self.basereq)
        QtCore.QObject.connect(self.basereply,QtCore.SIGNAL("finished()"),self.basefinished)

    def getmk(self):
        global manager
        self.mkreq = QNetworkRequest(QUrl(self.mkurl))
        self.mkreply = manager.get(self.mkreq)
        QtCore.QObject.connect(self.mkreply,QtCore.SIGNAL("finished()"),self.mkfinished)
        
    def start(self, interval=0):
        if interval > 0: self.interval = interval
        self.getbase()
        self.getmk()
        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer,QtCore.SIGNAL("timeout()"), self.getwx)
       
    def wxstart(self):
        print "wxstart for "+self.myname
        if (self.lastwx == 0 or (self.lastwx+self.interval) < time.time()): self.getwx()
        # random 1 to 10 seconds added to refresh interval to spread the queries over time
        i = (self.interval+random.uniform(1,10))*1000
        self.timer.start(i)
        self.wxmovie.start()
        QtCore.QTimer.singleShot(1000, self.wxmovie.start)
        
    def wxstop(self):
        print "wxstop for "+self.myname
        self.timer.stop()
        self.wxmovie.stop()
        
    def stop(self):
        try:
            self.timer.stop()
            self.timer = None
            if self.wxmovie: self.wxmovie.stop()
        except Exception:
            pass
Esempio n. 48
0
class Procedure(QtGui.QWidget, Ui_Procedure):
    def __init__(self, conf_path):
        QtGui.QWidget.__init__(self)
        Ui_Procedure.__init__(self)
        self.setupUi(self)
        self.db_api = db_api.DBApi(
            utils.get_conf_value(conf_path, 'db', 'db_path'))

        self.image_advertisement_path = utils.get_static_images_path(
            conf_path, 'image_advisediment_name')
        self.image_advertisement_path_other = utils.get_static_images_path(
            conf_path, 'image_advisediment_name2')
        self.image_guide_path = utils.get_static_images_path(
            conf_path, 'image_guide_name')
        self.image_recogniting_path = utils.get_static_images_path(
            conf_path, 'image_recogniting_name')
        self.image_unidentified_path = utils.get_static_images_path(
            conf_path, 'image_unidentified_name')

        self.guide_timeout = int(
            utils.get_conf_value(conf_path, 'guide', 'timeout'))
        self.unidentified_timeout = int(
            utils.get_conf_value(conf_path, 'unidentified', 'timeout'))

        self.rec_sys_path = utils.get_static_images_path(
            conf_path, 'rec_sys_name')
        self.pra_sys_path = utils.get_static_images_path(
            conf_path, 'pra_sys_name')
        self.save_image_base_path = utils.get_conf_value(
            conf_path, 'cache_fruits_images', 'save_image_base_path')
        self.pra_button.setStyleSheet("QPushButton{border-image: url(%s)}" %
                                      self.pra_sys_path)
        self.rec_button.setStyleSheet("QPushButton{border-image: url(%s)}" %
                                      self.rec_sys_path)

        self.advertisement_movie = QMovie(self.image_advertisement_path)
        self.guide_movie = QMovie(self.image_guide_path)
        self.recogniting_movie = QMovie(self.image_recogniting_path)
        self.unidentified_movie = QMovie(self.image_unidentified_path)

        self.advertisement_button.clicked.connect(self.show_guide_ui)
        self.setWindowFlags(Qt.Qt.FramelessWindowHint)

        self.running_dialog = ''
        self.timeout_timer = QTimer()
        self.timeout_timer.timeout.connect(self.timeout_handler)

        self.image_choice_system_path = utils.get_static_images_path(
            conf_path, 'image_logo_name')
        self.pra_button.clicked.connect(self.show_praitce_dialog)
        self.rec_button.clicked.connect(self.show_advertisment_ui)
        self.return_choice_button.clicked.connect(self.upload_cloud)
        self.choice_system()
        self.change_shop_button.clicked.connect(self.show_praitce_dialog)
        self.file_path = ''
        self.practice_mode = False
        self.qthread = UploadImage(self.save_image_base_path)
        self.qthread.signal_upload_resp.connect(self.set_if_success_label)
        self.setStyleSheet("QPushButton{outline: none}")

    def set_if_success_label(self, is_or_not):
        if is_or_not:
            self.if_success.setText(_translate("RecognitionResult", '成功',
                                               None))
        else:
            self.if_success.setText(_translate("RecognitionResult", '失败',
                                               None))

    def choice_system(self):
        self.show()
        self.shop_image.hide()
        self.change_shop_button.hide()
        self.return_choice_button.hide()
        self.advertisement_button.hide()
        self.gif = QMovie(self.image_choice_system_path)
        self.change_status_label.setMovie(self.gif)
        self.gif.start()
        self.if_success.setText('')
        # self.change_status_label.setStyleSheet(
        #     "QPushButton{background-image: url(%s)}" %
        #     self.image_choice_system_path)
        self.change_status_label.show()

    def upload_cloud(self):
        lists_folder = os.listdir(self.save_image_base_path)
        for folder in lists_folder:
            if os.path.isdir(self.save_image_base_path + folder):
                self.qthread.set_folder_name(folder)
                self.qthread.start()
                self.qthread.wait()
        self.timeout_timer.start(2000)
        self.running_dialog = 'advertisment'

    def timeout_handler(self):
        self.timeout_timer.stop()
        if self.running_dialog == 'guide':
            logger.warning('%s seconds, timeout waiting user to weight, '
                           'return advertisement dialog.' % self.guide_timeout)
            req_id = utils.generate_uuid()
            logger.info("new req id generate %s" % req_id)
            self.db_api.update_device_req_id(req_id)
            self.show_advertisment_ui()
        elif self.running_dialog == 'advertisment':
            self.show_advertisment_ui()
        elif self.running_dialog == 'unidentified':
            logger.info('%s seconds, identified failed notice finished.' %
                        self.unidentified_timeout)
            self.show_guide_ui()
        else:
            self.hide()

    def show_praitce_dialog(self):
        self.pra_button.hide()
        self.rec_button.hide()
        self.shop_image.show()
        self.return_choice_button.show()
        self.change_shop_button.show()
        self.if_success.setText(_translate("RecognitionResult", '', None))
        self.practice_mode = True
        self.file_path = str(time.time())
        if not os.path.exists(self.save_image_base_path):
            os.makedirs(self.save_image_base_path)
        lists_folder = os.listdir(self.save_image_base_path)
        for folder in lists_folder:
            if os.path.isdir(self.save_image_base_path + folder):
                self.qthread.set_folder_name(folder)
                self.qthread.start()
                self.qthread.wait()

    def show_advertisment_ui(self):
        self.if_success.hide()
        self.practice_mode = False
        self.hide_button_show_procedure()
        self.advertisement_button.show()
        self.change_status_label.hide()
        self.advertisement_button.setStyleSheet(
            "QPushButton{border-image: url(%s)}" %
            self.image_advertisement_path)
        req_id = utils.generate_uuid()
        logger.info("new req id generate %s" % req_id)
        self.db_api.update_device_req_id(req_id)

    def show_guide_ui(self):
        self.hide_button_show_procedure()
        self.change_status_label.setMovie(self.guide_movie)
        self.guide_movie.start()
        self.change_status_label.show()
        self.advertisement_button.hide()
        self.running_dialog = 'guide'
        self.timeout_timer.start(self.guide_timeout * 1000)

    def show_recogniting_ui(self):
        self.hide_button_show_procedure()
        self.timeout_timer.stop()
        self.change_status_label.setMovie(self.recogniting_movie)
        self.recogniting_movie.start()
        self.change_status_label.show()
        self.advertisement_button.hide()
        self.running_dialog = 'recogniting'

    def delay_hide(self, recognition_result_win):
        self.running_dialog = 'recognited'
        recognition_result_win.show()
        self.timeout_timer.start(300)

    def show_unidentified_ui(self):
        self.hide_button_show_procedure()
        task_id = self.db_api.get_device_task_id()
        self.db_api.update_task_status(task_id, 'unidentified')
        self.change_status_label.setMovie(self.unidentified_movie)
        self.unidentified_movie.start()
        self.change_status_label.show()
        self.advertisement_button.hide()
        self.running_dialog = 'unidentified'
        self.timeout_timer.start(self.guide_timeout * 1000)

    def hide_button_show_procedure(self):
        self.show()
        self.shop_image.hide()
        self.pra_button.hide()
        self.rec_button.hide()
        self.return_choice_button.hide()
        self.change_shop_button.hide()
Esempio n. 49
0
class Radar(QtGui.QLabel):

    def __init__(self, parent, radar, rect):
        global xscale, yscale
        self.rect = rect
        self.baseurl = self.mapurl(radar, rect, False)
        print "google map base url: "+self.baseurl
        self.mkurl = self.mapurl(radar, rect, True)
        self.wxurl = self.radarurl(radar, rect)
        QtGui.QLabel.__init__(self, parent)
        
        self.setObjectName("radar")
        self.setGeometry(rect)
        self.setStyleSheet("#radar { background-color: grey; }")    
        self.setAlignment(Qt.AlignCenter)

        self.wwx = QtGui.QLabel(self)
        self.wwx.setObjectName("wx")
        self.wwx.setStyleSheet("#wx { background-color: transparent; }")    
        self.wwx.setGeometry(0, 0, rect.width(), rect.height())

        self.wmk = QtGui.QLabel(self)
        self.wmk.setObjectName("mk")
        self.wmk.setStyleSheet("#mk { background-color: transparent; }")    
        self.wmk.setGeometry(0, 0, rect.width(), rect.height())

        self.wxmovie = QMovie()

    def mapurl(self, radar,rect,markersonly):
        #'https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid&center='+rcenter.lat+','+rcenter.lng+'&zoom='+rzoom+'&size=300x275'+markersr;
        urlp = [];
        
        if len(ApiKeys.googleapi) > 0: urlp.append('key='+ApiKeys.googleapi)
        urlp.append('center='+str(radar['center'].lat)+','+str(radar['center'].lng))
        zoom = radar['zoom']
        rsize = rect.size()
        if rsize.width() > 640 or rsize.height() > 640:
            rsize = QtCore.QSize(rsize.width()/2,rsize.height()/2)
            zoom -= 1
        urlp.append('zoom='+str(zoom))
        urlp.append('size='+str(rsize.width())+'x'+str(rsize.height()))
        if markersonly:
            urlp.append('style=visibility:off') 
        else:
            urlp.append('maptype=hybrid')
        for marker in radar['markers']:
            marks = []
            for opts in marker:
                if opts != 'location':
                    marks.append(opts + ':' + marker[opts])
            marks.append(str(marker['location'].lat)+','+str(marker['location'].lng))
            urlp.append('markers='+'|'.join(marks))
        return 'http://maps.googleapis.com/maps/api/staticmap?'+'&'.join(urlp)

    def radarurl(self,radar,rect):
        #wuprefix = 'http://api.wunderground.com/api/';
        #wuprefix+wuapi+'/animatedradar/image.gif?maxlat='+rNE.lat+'&maxlon='+rNE.lng+'&minlat='+rSW.lat+'&minlon='+rSW.lng+wuoptionsr;
        #wuoptionsr = '&width=300&height=275&newmaps=0&reproj.automerc=1&num=5&delay=25&timelabel=1&timelabel.y=10&rainsnow=1&smooth=1';
        rr = getCorners(radar['center'],radar['zoom'],rect.width(),rect.height())
        return (Config.wuprefix+ApiKeys.wuapi+'/animatedradar/image.gif'+
                '?maxlat='+str(rr['N'])+
                '&maxlon='+str(rr['E'])+
                '&minlat='+str(rr['S'])+
                '&minlon='+str(rr['W'])+
                '&width='+str(rect.width())+
                '&height='+str(rect.height())+
                '&newmaps=0&reproj.automerc=1&num=5&delay=25&timelabel=1&timelabel.y=10&rainsnow=1&smooth=1&radar_bitmap=1&xnoclutter=1&xnoclutter_mask=1&cors=1'
                )
    
    def basefinished(self):
        if self.basereply.error() != QNetworkReply.NoError: return
        self.basepixmap = QPixmap()
        self.basepixmap.loadFromData(self.basereply.readAll())
        if self.basepixmap.size() != self.rect.size():
            self.basepixmap = self.basepixmap.scaled(self.rect.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.setPixmap(self.basepixmap)
    
    def mkfinished(self):
        if self.mkreply.error() != QNetworkReply.NoError: return
        self.mkpixmap = QPixmap()
        self.mkpixmap.loadFromData(self.mkreply.readAll())
        if self.mkpixmap.size() != self.rect.size():
            self.mkpixmap = self.mkpixmap.scaled(self.rect.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.wmk.setPixmap(self.mkpixmap)

    def wxfinished(self):
        if self.wxreply.error() != QNetworkReply.NoError: return
        self.wxdata = QtCore.QByteArray(self.wxreply.readAll())
        self.wxbuff = QtCore.QBuffer(self.wxdata)
        self.wxbuff.open(QtCore.QIODevice.ReadOnly)
        self.wxmovie = QMovie(self.wxbuff, 'GIF')
        self.wwx.setMovie( self.wxmovie)
        if self.parent().isVisible():
            self.wxmovie.start()

    def getwx(self):
        global manager
        self.wxreq = QNetworkRequest(QUrl(self.wxurl+'&rrrand='+str(time.time())))
        self.wxreply = manager.get(self.wxreq)
        QtCore.QObject.connect(self.wxreply, QtCore.SIGNAL("finished()"),self.wxfinished)

    def getbase(self):
        global manager
        self.basereq = QNetworkRequest(QUrl(self.baseurl))
        self.basereply = manager.get(self.basereq)
        QtCore.QObject.connect(self.basereply,QtCore.SIGNAL("finished()"),self.basefinished)

    def getmk(self):
        global manager
        self.mkreq = QNetworkRequest(QUrl(self.mkurl))
        self.mkreply = manager.get(self.mkreq)
        QtCore.QObject.connect(self.mkreply,QtCore.SIGNAL("finished()"),self.mkfinished)
        
    def start(self, interval=10*60*1000):
        self.getbase()
        self.getmk()
        self.getwx()
        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer,QtCore.SIGNAL("timeout()"), self.getwx)
        self.timer.start(interval)
       
    def wxstart(self):
        self.wxmovie.start()
        
    def wxstop(self):
        self.wxmovie.stop()
        
    def stop(self):
        try:
            self.timer.stop()
            self.timer = None
            if self.wxmovie: self.wxmovie.stop()
        except Exception:
            pass
Esempio n. 50
0
class MuWizard(QWizard):

    def __init__(self, R=None, parent=None):
        QWizard.__init__(self, parent)

        self.R = R
        self.data = None

        self.addPage(self.introPage())
        self.addPage(self.loadPage())
        self.addPage(self.modelsPage())
        self.addPage(self.resultsPage())
        self.setWindowTitle('Wizard of muScale')
        self.setPixmap(QWizard.LogoPixmap, QPixmap(RES + ICONS + LOGO))

        self.setStyleSheet('QWizard {' + GRADIENT +'}\
                        QPushButton {\
                            color: #333;\
                            border: 1px solid #555;\
                            border-radius: 11px;\
                            padding: 2px;\
                            background: qradialgradient(cx: 0.3, cy: -0.4,\
                            fx: 0.3, fy: -0.4,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #888);\
                            min-width: 80px;}\
                        QPushButton:hover {\
                            color: #fff;\
                            background: qradialgradient(cx: 0.3, cy: -0.4,\
                            fx: 0.3, fy: -0.4,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #bbb);}\
                        QPushButton:pressed {\
                            color: #800;\
                            background: qradialgradient(cx: 0.4, cy: -0.1,\
                            fx: 0.4, fy: -0.1,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #ddd);}\
                        QPushButton:checked {\
                            background: qradialgradient(cx: 0.4, cy: -0.1,\
                            fx: 0.4, fy: -0.1,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #ddd);}\
                        QComboBox {\
                            color: #333;\
                            border: 1px solid #555;\
                            border-radius: 11px;\
                            padding: 1px 18px 1px 3px;\
                            background: qradialgradient(cx: 0.3, cy: -0.4,\
                            fx: 0.3, fy: -0.4,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #888);\
                            min-width: 20px;}\
                        QComboBox:hover {\
                            color: #fff;\
                            background: qradialgradient(cx: 0.3, cy: -0.4,\
                            fx: 0.3, fy: -0.4,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #bbb);}\
                        QComboBox::down-arrow {\
                             image: url(' + RES + ICONS + ARROW_DOWN + ');}\
                        QComboBox::down-arrow:on {\
                             top: 1px;\
                             left: 1px;}\
                        QComboBox::drop-down {\
                             subcontrol-origin: padding;\
                             subcontrol-position: top right;\
                             width: 15px;\
                             border-left-width: 1px;\
                             border-left-color: darkgray;\
                             border-left-style: solid;\
                             border-top-right-radius: 3px;\
                             border-bottom-right-radius: 3px;}\
                         QToolButton {\
                            color: #333;\
                            border: 1px solid #555;\
                            border-radius: 11px;\
                            padding: 2px;\
                            background: qradialgradient(cx: 0.3, cy: -0.4,\
                            fx: 0.3, fy: -0.4,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #888);\
                            min-width: 20px;}\
                        QToolButton:hover {\
                            color: #fff;\
                            background: qradialgradient(cx: 0.3, cy: -0.4,\
                            fx: 0.3, fy: -0.4,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #bbb);}\
                        QToolButton:pressed {\
                            background: qradialgradient(cx: 0.4, cy: -0.1,\
                            fx: 0.4, fy: -0.1,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #ddd);}\
                        QToolButton:checked {\
                            background: qradialgradient(cx: 0.4, cy: -0.1,\
                            fx: 0.4, fy: -0.1,\
                            radius: 1.35, stop: 0 #fff, stop: 1 #ddd);}')

    def introPage(self):
        intro = QWizardPage()

        intro.setTitle('Hello and welcome')
        label = QLabel('''This is a wizard.
Now you're ready to forecast some time series!
        ''')

        label.setWordWrap(True)
        layout = QVBoxLayout()
        layout.addWidget(label)
        intro.setLayout(layout)

        return intro

    def loadPage(self):
        load = WizardPageEx('loadCheck')

        load.setTitle('Initial data')
        pathLbl = QLabel("<font style='color: gray'>Specify the file with time series to forecast:</font>")
        loadLbl = QLabel("<font style='color: gray'>Click</font>")
        loadLbl.setAlignment(Qt.AlignCenter)

        self.path = QLineEdit()
        self.path.setPlaceholderText('path to file')
        getPath = QToolButton()
        getPath.setText('...')

        self.resultLbl = QLabel()
        self.resultLbl.setAlignment(Qt.AlignCenter)
        self.resultLbl.hide()

        self.preview = QLabel()
        self.preview.setAlignment(Qt.AlignCenter)
        self.preview.setWordWrap(True)
        self.preview.hide()

        self.preview.setAttribute(Qt.WA_Hover)
        self.filter = Filter()
        self.preview.installEventFilter(self.filter)

        getPath.clicked.connect(self.loadData)

        layout = QGridLayout()
        layout.addWidget(pathLbl, 0, 0)
        layout.addWidget(loadLbl, 0, 1)
        layout.addWidget(self.path, 1, 0)
        layout.addWidget(getPath, 1, 1)
        layout.addWidget(self.resultLbl, 2, 0, 1, 2)
        layout.addWidget(self.preview, 3, 0, 1, 2)
        load.setLayout(layout)

        load.previewSeries = SeriesPreview()
        self.previewSeries = load.previewSeries

        # to be able to reference from class namespace
        self.loadCheck = load.check

        return load

    def modelsPage(self):
        models = WizardPageEx('modelCheck')
        models.setTitle('Forecast')

        lbl = QLabel("<font style='color: gray'>Forecast horizon:</font>")
        self.steps = QSpinBox()
        self.steps.setRange(MIN_FORECAST, MAX_FORECAST)
        self.steps.setValue(10)
        self.start = QPushButton('Forecast')
        self.start.clicked.connect(self.modelling)
        self.custom = QPushButton('Advanced')
        self.processing = QLabel()

        self.gifLoading = QMovie(RES + ICONS + PROGRESS, QByteArray(), self)
        self.gifLoading.setCacheMode(QMovie.CacheAll)
        self.gifLoading.setSpeed(100)
        self.processing.setMovie(self.gifLoading)
        self.processing.setAlignment(Qt.AlignCenter)
        self.processing.hide()

        self.status = QLabel()
        self.status.setAlignment(Qt.AlignCenter)
        self.status.hide()

        layout = QGridLayout()
        layout.addWidget(lbl, 0, 0)
        layout.addWidget(self.steps, 0, 1)
        layout.addWidget(self.start, 0, 2)
        layout.addWidget(self.custom, 0, 3)
        layout.addWidget(self.status, 1, 0, 1, 4)
        layout.addWidget(self.processing, 2, 0, 1, 4)
        models.setLayout(layout)

        self.customOpt = CustomOption()
        self.custom.clicked.connect(self.customOpt.show)
        self.modelCheck = models.check

        return models

    def resultsPage(self):
        results = QWizardPage()
        results.setFinalPage(True)
        results.setTitle('Results')

        self.graph = QLabel("<font style='font-size: 16px;'>Plot</font>")
        self.export = QLabel("<font style='font-size: 16px;'>Export</font>")
        self.showData = QLabel("<font style='font-size: 16px;'>Data</font>")
        
        self.plotResult = MplWidget(None)
        self.plotResult.canvas.fig.set_facecolor('white')
        self.resData = QLabel('')
        self.resData.setAlignment(Qt.AlignCenter)
        self.resData.setWordWrap(True)
        self.resData.hide()

        self.resFilter = ResFilter()

        self.resLayout = QVBoxLayout()
        self.resLayout.addWidget(self.export)
        self.resLayout.addWidget(self.graph)
        self.resLayout.addWidget(self.showData)
        self.resLayout.addWidget(self.plotResult)
        self.resLayout.addWidget(self.resData)

        self.plotResult.hide()

        for index in range(0, self.resLayout.count()):
            try:
                self.resLayout.itemAt(index).widget().setAlignment(Qt.AlignCenter)
                self.resLayout.itemAt(index).widget().setStyleSheet('QLabel { color: gray; }')
                self.resLayout.itemAt(index).widget().setAttribute(Qt.WA_Hover)
                self.resLayout.itemAt(index).widget().installEventFilter(self.resFilter)
            except Exception:
                pass

        self.resLayout.setAlignment(Qt.AlignCenter)
        self.resLayout.setSpacing(60)

        results.setLayout(self.resLayout)

        return results

    #---- actions ----#
    def loadData(self):
        fileName = unicode(QFileDialog.getOpenFileName(self, 'Open text file', RES))
        if fileName:
            self.resultLbl.hide()
            self.preview.hide()
            if DataParser.istextfile(fileName):
                self.data = DataParser.getTimeSeriesFromTextData(data=open(fileName, 'r').read())
                if len(self.data[0]) > DATA_LOW_LIMIT:
                    self.resultLbl.setText("<font style='color: gray'>Success! Loaded<b> " + str(len(self.data[0])) +
                                           '</b> values, errors: <b>' + str(
                                            self.data[1]) + '</b></font>')
                    self.resultLbl.show()
                    self.path.setText(fileName)

                    previewLength = 40
                    self.preview.setText("<font style='color: gray'><b>Preview:</b> "+ ' '.join(
                                        [str(e) for e in self.data[0][:previewLength]]) +
                                        "...</font>")
                    self.previewSeries.updateData(self.data)
                    self.preview.show()
                    self.loadCheck.setChecked(True)
                else:
                    self.resultLbl.setText("<font style='color: gray'>Not enough values to form data series.</font>")
                    self.resultLbl.show()
            else:
                self.resultLbl.setText("<font style='color: gray'>Specified file is binary file!</font>")
                self.resultLbl.show()

    def modelling(self):
        self.processing.show()
        self.gifLoading.start()
        self.status.setText('')

        statusText = u"<font style='color: gray'>"

        # decomposition #
        if self.customOpt.options['enable']:
            self.signalEx = self.customOpt.options['signal']
            self.wavelet = pywt.Wavelet(self.customOpt.options['wavelet'])
            wLevel = self.customOpt.options['lvls'] - 1
            maxLevel = pywt.dwt_max_level(len(self.data[0]), self.wavelet)

            if wLevel > maxLevel:
                wLevel = maxLevel

            self.wInitialCoefficients = pywt.wavedec(self.data[0], self.wavelet,
                                                       level=wLevel, mode=self.signalEx)
            self.wCoefficients = self.wInitialCoefficients
        else:
            self.signalEx = pywt.MODES.sp1
            selected = select_wavelet(self.data[0], self.R)
            index = max(selected)
            self.wavelet = pywt.Wavelet(selected[index][1])

            wLevel = calculate_suitable_lvl(self.data[0],
                                         self.wavelet, self.R, swt=False)
            self.wInitialCoefficients = pywt.wavedec(self.data[0], self.wavelet,
                                                     level=wLevel, mode=self.signalEx)
            self.wCoefficients = self.wInitialCoefficients

        statusText += 'Wavelet: <b>' + self.wavelet.family_name + \
                      '</b> (' + self.wavelet.name + ', ' + self.wavelet.symmetry + ', orthogonal: ' + \
                      str(self.wavelet.orthogonal) + ')<br/>'

        statusText += 'Discrete Wavelet Transfom: <b>' + str(wLevel + 1) + ' levels</b><br/>'

        # models #
        options = {}
        options['multi'] = True
        options['fractal'] = False
        options['ljung'] = False
        self.models = auto_model(self.wCoefficients, self.R, options, self.data[0])

        statusText += '<br/>Selected models:<br/>'
        for lvl, model in self.models.iteritems():
            statusText += str(lvl) + '. <b>' + model.enumname.replace('_', ' ') + '</b><br/>'

        # forecasting #
        try:
            frequency = self.customOpt.options['frequency']
        except Exception:
            frequency = 8
        aic = False
        options['hw_gamma'] = True
        options['hw_model'] = 'additive'
        options['hw_period'] = frequency
        options['ar_aic'] = aic
        options['ar_method'] = 'burg'
        options['ar_order'] = 50
        options['arima_auto'] = False
        options['arima_nons'] = True
        options['arima_nons_order'] = [6, 0, 9]
        options['arima_seas'] = True
        options['arima_seas_order'] = [9, 0, 1]
        options['lsf_aic'] = aic
        options['lsf_order'] = 30
        options['ets_auto'] = aic
        options['ets_period'] = frequency
        options['sts_type'] = 'trend'
        options['append_fit'] = True

        self.multi_model_thread = MultiModelThread(self.models,
                                           self.wCoefficients,
                                           self.R,
                                           self.steps.value(),
                                           options,)
        self.multi_model_thread.done.connect(self.multiForecastFinished)
        self.multi_model_thread.start()

        statusText += '<br/>Forecasting...'

        self.status.setText(statusText)
        self.status.show()

    def multiForecastFinished(self, results):
        self.forecast = results
        self.gifLoading.stop()
        self.processing.hide()

        self.status.setText('<br/>'.join(str(self.status.text()).split('<br/>')[:-1]) +
                            '<br/>Forecast complete.')
        self.modelCheck.setChecked(True)

    #---- results -----#
    def togglePlot(self):
        if self.plotResult.isVisible():
            self.plotResult.hide()
            self.export.show()
            self.showData.show()
            self.resLayout.setSpacing(60)
        else:
            self.updateGraph()
            self.plotResult.show()
            self.export.hide()
            self.showData.hide()
            self.resLayout.setSpacing(5)

    def toggleData(self):
        if self.resData.isVisible():
            self.export.show()
            self.graph.show()
            self.showData.show()
            self.resData.hide()
            self.resLayout.setSpacing(60)
            self.adjustSize()
        else:
            self.plotResult.hide()
            self.graph.hide()
            self.export.hide()
            self.showData.show()
            self.resData.show()
            self.resLayout.setSpacing(5)

            res = self.inverseWT()
            max = len(self.data[0]) - 1
            resText = '<table border="0" align="center" style="border-style: groove;">'
            resText += '<tr><td align="center"><i>Initial</i></td><td align="center"><i>Forecast</i></td></tr>'
            resText += '<tr><td align="center">...</td><td></td></tr>'
            table = zip(self.data[0][max-10:max], res[max-10:max])
            for i, j in table:
                resText += '<tr>'
                resText += '<td align="center">' + str(i) + '</td>'
                resText += '<td align="center">' + str(j) + '</td>'
                resText += '</tr>'

            for e in res[max+1:max+10]:
                resText += '<tr>'
                resText += '<td align="center"></td>'
                resText += '<td align="center">' + str(e) + '</td>'
                resText += '</tr>'

            resText += '<tr><td align="center"></td><td align="center">...</td></tr>'
            resText += '</table>'

            self.resData.setText(resText)
            self.adjustSize()

    def inverseWT(self):
        return pywt.waverec(update_dwt([e [1] for e in self.forecast], self.wavelet, self.signalEx),
                                            self.wavelet, mode=self.signalEx)

    def updateGraph(self):
        self.plotResult.updatePlot(self.inverseWT(), label='Simulation', color='r')
        self.plotResult.updatePlot(self.data[0], label='Time series', color='b')

    def exportToXls(self):
        # opening file dialog
        fileName = QFileDialog.getSaveFileName(self,
            'Save as', RES, 'Microsoft Excel Spreadsheet (*.xls)')

        if fileName.count() > 0:
            try:
                COLUMN_WIDTH = 3000

                alignment = Alignment()
                alignment.horizontal = Alignment.HORZ_CENTER
                alignment.vertical = Alignment.VERT_CENTER

                borders = Borders()
                borders.left = Borders.THIN
                borders.right = Borders.THIN
                borders.top = Borders.THIN
                borders.bottom = Borders.THIN

                style = XFStyle()
                style.alignment = alignment
                style.borders = borders

                font = Font()
                font.bold = True
                headerStyle = XFStyle()
                headerStyle.font = font

                separate = Borders()
                separate.left = Borders.THIN
                separate.right = Borders.DOUBLE
                separate.top = Borders.THIN
                separate.bottom = Borders.THIN
                separateStyle = XFStyle()
                separateStyle.borders = separate

                book = Workbook(encoding='utf-8')

                # modelling data
                dec_sheet = book.add_sheet('Data decomposition')

                # decomposition data
                # initial data
                column = 0
                row = 0
                dec_sheet.write(row, column, 'Time series', headerStyle)
                dec_sheet.col(column).width = COLUMN_WIDTH
                row += 1
                for item in self.data[0]:
                    dec_sheet.write(row, column, item, separateStyle)
                    row += 1

                # decomposition
                for lvl in self.wCoefficients:
                    row = 0
                    column += 1
                    dec_sheet.write(row, column, 'Level' + str(column - 1), headerStyle)
                    dec_sheet.col(column).width = COLUMN_WIDTH
                    row += 1
                    for item in lvl:
                        dec_sheet.write(row, column, item, style)
                        row += 1

                # decomposition graphs
                pass

                levels_sheet = book.add_sheet('Multiscale forecast')

                # levels data
                column = 0
                for lvl in self.forecast:
                    row = 0
                    levels_sheet.write(row, column, 'Level' + str(column), headerStyle)
                    levels_sheet.col(column).width = COLUMN_WIDTH
                    row += 1
                    for item in lvl[1]:
                        levels_sheet.write(row, column, float(item), style)
                        row += 1
                    column += 1

                result_sheet = book.add_sheet('Results')

                # initial
                column = 0
                row = 0
                result_sheet.write(row, column, 'Initial data', headerStyle)
                result_sheet.col(column).width = COLUMN_WIDTH
                row += 1
                for item in self.data[0]:
                    result_sheet.write(row, column, item, separateStyle)
                    row += 1

                # forecast
                row = 0
                column += 1
                result_sheet.write(row, column, 'Forecast', headerStyle)
                result_sheet.col(column).width = COLUMN_WIDTH
                row += 1
                for item in self.inverseWT():
                    result_sheet.write(row, column, item, style)
                    row += 1

                row = 0
                column = 2
                self.updateGraph()
                self.plotResult.saveFigure('forecast', format='bmp')

                result_sheet.insert_bitmap(RES + TEMP + 'forecast.bmp', row, column)

                # saving xls
                try:
                    book.save(unicode(fileName))
                except Exception:
                    pass

            except Exception, e:
                pass