コード例 #1
0
    def __init__(self, parent=None):
        super(NonstopPlayer, self).__init__(parent)

        self.ui = Ui_NonstopPlayer()
        self.ui.setupUi(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.lblSprite = QLabel(self.ui.lblPreview)
        self.lblSprite.setGeometry(0, 0, 480, 272)

        self.nonstop = None

        self.line = 0
        self.lines = []
        self.labels = []

        self.ui.actionSaveImg = QtGui.QAction("Save image...",
                                              None,
                                              triggered=self.saveImage)
        self.ui.actionSaveImg.setShortcut("Ctrl+S")
        self.addAction(self.ui.actionSaveImg)

        self.voice_player = VoicePlayer()
        self.auto_play = True
 def __init__(self, parent = None):
   super(NonstopPlayer, self).__init__(parent)
   
   self.ui = Ui_NonstopPlayer()
   self.ui.setupUi(self)
   self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
   
   self.lblSprite = QLabel(self.ui.lblPreview)
   self.lblSprite.setGeometry(0, 0, 480, 272)
   
   self.nonstop = None
   
   self.line   = 0
   self.lines  = []
   self.labels = []
   
   self.ui.actionSaveImg = QtGui.QAction("Save image...", None, triggered = self.saveImage)
   self.ui.actionSaveImg.setShortcut("Ctrl+S")
   self.addAction(self.ui.actionSaveImg)
   
   self.voice_player = VoicePlayer()
   self.auto_play    = True
class NonstopPlayer(QtGui.QDialog):
  def __init__(self, parent = None):
    super(NonstopPlayer, self).__init__(parent)
    
    self.ui = Ui_NonstopPlayer()
    self.ui.setupUi(self)
    self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    
    self.lblSprite = QLabel(self.ui.lblPreview)
    self.lblSprite.setGeometry(0, 0, 480, 272)
    
    self.nonstop = None
    
    self.line   = 0
    self.lines  = []
    self.labels = []
    
    self.ui.actionSaveImg = QtGui.QAction("Save image...", None, triggered = self.saveImage)
    self.ui.actionSaveImg.setShortcut("Ctrl+S")
    self.addAction(self.ui.actionSaveImg)
    
    self.voice_player = VoicePlayer()
    self.auto_play    = True
  
  def load(self, filename):
    self.nonstop = NonstopParser()
    self.nonstop.load(filename)
    
    if len(self.nonstop.script_pack) == 0:
      return
    
    self.bg = get_trial(self.nonstop.script_pack[0].scene_info, show_box = False, show_sprite = False)
    qt_pixmap = QtGui.QPixmap.fromImage(self.bg)
    self.ui.lblPreview.setPixmap(qt_pixmap)
    
    self.lines = []
    for i in range(len(self.nonstop.lines)):
      if self.nonstop.script_pack[i][common.editor_config.lang_trans] != "":
        text = self.nonstop.script_pack[i][common.editor_config.lang_trans]
      else:
        text = self.nonstop.script_pack[i][common.editor_config.lang_orig]
      
      format = self.nonstop.script_pack[i].scene_info.format
      text_img = get_text(text, common.SCENE_MODES.debate, format)
      
      self.lines.append(QtGui.QPixmap.fromImage(text_img))
    
    self.anims  = [None] * len(self.nonstop.lines)
    self.labels = [None] * len(self.nonstop.lines)
    self.timers = [None] * len(self.nonstop.lines)
  
  def start(self):
    self.line = 0
    self.show_line(self.line)
  
  def _finished(self, line):
    self.labels[line].deleteLater()
  
  def show_line(self, line, queue_next = True):
    
    scene_info = self.nonstop.script_pack[line].scene_info
    voice  = scene_info.voice
    format = scene_info.format
    sprite_id = scene_info.sprite
    sprite_id.sprite_type = SPRITE_TYPE.stand
    sprite = get_sprite(sprite_id)
    
    if self.auto_play:
      self.voice_player.play(voice)
    
    if sprite:
      qt_pixmap = QtGui.QPixmap.fromImage(sprite)
      self.lblSprite.setPixmap(qt_pixmap)
    
    text_img  = self.lines[line]
    line_info = self.nonstop.lines[line]
    
    matrix = QMatrix()
    matrix.rotate(line_info.rot_angle - (90 if format.orient == TEXT_ORIENT.ver else 0))
    text_img = text_img.transformed(matrix, Qt.Qt.SmoothTransformation)
    
    time_visible = line_info.time_visible / 60.0
    
    width_start  = text_img.width() * line_info.zoom_start / 100.0
    height_start = text_img.height() * line_info.zoom_start / 100.0
    width_end    = width_start * ((line_info.zoom_change / 100.0) ** time_visible)
    height_end   = height_start * ((line_info.zoom_change / 100.0) ** time_visible)
    
    x_start = line_info.x_start - (width_start / 2.0)
    y_start = line_info.y_start - (height_start / 2.0)
    x_vel   = line_info.velocity * math.cos(math.radians(90 - line_info.angle))
    y_vel   = -line_info.velocity * math.sin(math.radians(90 - line_info.angle))
    
    x_end = x_start + (x_vel * time_visible) - ((width_end - width_start) / 2.0)
    y_end = y_start + (y_vel * time_visible) - ((height_end - height_start) / 2.0)
    
    self.labels[line] = QLabel(self.ui.lblPreview)
    self.labels[line].setScaledContents(True)
    self.labels[line].setGeometry(x_start, y_start, text_img.width(), text_img.height())
    self.labels[line].setPixmap(text_img)
    self.labels[line].show()
    
    self.anims[line] = QtCore.QPropertyAnimation(self.labels[line], "geometry")
    self.anims[line].setDuration(time_visible * 1000)
    self.anims[line].setStartValue(QRectF(x_start, y_start, width_start, height_start))
    self.anims[line].setEndValue(QRectF(x_end, y_end, width_end, height_end))
    self.anims[line].finished.connect(lambda: self._finished(line))
    
    self.anims[line].start(QtCore.QAbstractAnimation.DeleteWhenStopped)
    
    if queue_next:
      next_line = line + 1
      if next_line < len(self.lines):
        self.timers[line] = QtCore.QTimer()
        self.timers[line].timeout.connect(lambda: self.show_line(next_line, queue_next = True))
        self.timers[line].setSingleShot(True)
        self.timers[line].start(line_info.delay / 60.0 * 1000)
    
  ##############################################################################
  ### @fn   saveImage()
  ### @desc Saves a preview image. :D
  ##############################################################################
  def saveImage(self):
  
    dir   = "ss"
    index = 0
    
    if not os.path.isdir(dir):
      if os.path.isfile(dir):
        return
      else:
        os.mkdir(dir)
    
    while True:
      if index >= 9999:
        return
        
      filename = os.path.join(dir, ("shot%04d.png" % index))
      
      if not os.path.isfile(filename):
        break
        
      index = index + 1
    
    if not os.path.isdir(dir):
      os.mkdir(dir)
    
    self.lblText.pixmap().save(filename)
コード例 #4
0
class NonstopPlayer(QtGui.QDialog):
    def __init__(self, parent=None):
        super(NonstopPlayer, self).__init__(parent)

        self.ui = Ui_NonstopPlayer()
        self.ui.setupUi(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.lblSprite = QLabel(self.ui.lblPreview)
        self.lblSprite.setGeometry(0, 0, 480, 272)

        self.nonstop = None

        self.line = 0
        self.lines = []
        self.labels = []

        self.ui.actionSaveImg = QtGui.QAction("Save image...",
                                              None,
                                              triggered=self.saveImage)
        self.ui.actionSaveImg.setShortcut("Ctrl+S")
        self.addAction(self.ui.actionSaveImg)

        self.voice_player = VoicePlayer()
        self.auto_play = True

    def load(self, filename):
        self.nonstop = NonstopParser()
        self.nonstop.load(filename)

        if len(self.nonstop.script_pack) == 0:
            return

        self.bg = get_trial(self.nonstop.script_pack[0].scene_info,
                            show_box=False,
                            show_sprite=False)
        qt_pixmap = QtGui.QPixmap.fromImage(self.bg)
        self.ui.lblPreview.setPixmap(qt_pixmap)

        self.lines = []
        for i in range(len(self.nonstop.lines)):
            if self.nonstop.script_pack[i][
                    common.editor_config.lang_trans] != "":
                text = self.nonstop.script_pack[i][
                    common.editor_config.lang_trans]
            else:
                text = self.nonstop.script_pack[i][
                    common.editor_config.lang_orig]

            format = self.nonstop.script_pack[i].scene_info.format
            text_img = get_text(text, common.SCENE_MODES.debate, format)

            self.lines.append(QtGui.QPixmap.fromImage(text_img))

        self.anims = [None] * len(self.nonstop.lines)
        self.labels = [None] * len(self.nonstop.lines)
        self.timers = [None] * len(self.nonstop.lines)

    def start(self):
        self.line = 0
        self.show_line(self.line)

    def _finished(self, line):
        self.labels[line].deleteLater()

    def show_line(self, line, queue_next=True):

        scene_info = self.nonstop.script_pack[line].scene_info
        voice = scene_info.voice
        format = scene_info.format
        sprite_id = scene_info.sprite
        sprite_id.sprite_type = SPRITE_TYPE.stand
        sprite = get_sprite(sprite_id)

        if self.auto_play:
            self.voice_player.play(voice)

        if sprite:
            qt_pixmap = QtGui.QPixmap.fromImage(sprite)
            self.lblSprite.setPixmap(qt_pixmap)

        text_img = self.lines[line]
        line_info = self.nonstop.lines[line]

        matrix = QMatrix()
        matrix.rotate(line_info.rot_angle -
                      (90 if format.orient == TEXT_ORIENT.ver else 0))
        text_img = text_img.transformed(matrix, Qt.Qt.SmoothTransformation)

        time_visible = line_info.time_visible / 60.0

        width_start = text_img.width() * line_info.zoom_start / 100.0
        height_start = text_img.height() * line_info.zoom_start / 100.0
        width_end = width_start * (
            (line_info.zoom_change / 100.0)**time_visible)
        height_end = height_start * (
            (line_info.zoom_change / 100.0)**time_visible)

        x_start = line_info.x_start - (width_start / 2.0)
        y_start = line_info.y_start - (height_start / 2.0)
        x_vel = line_info.velocity * math.cos(
            math.radians(90 - line_info.angle))
        y_vel = -line_info.velocity * math.sin(
            math.radians(90 - line_info.angle))

        x_end = x_start + (x_vel * time_visible) - (
            (width_end - width_start) / 2.0)
        y_end = y_start + (y_vel * time_visible) - (
            (height_end - height_start) / 2.0)

        self.labels[line] = QLabel(self.ui.lblPreview)
        self.labels[line].setScaledContents(True)
        self.labels[line].setGeometry(x_start, y_start, text_img.width(),
                                      text_img.height())
        self.labels[line].setPixmap(text_img)
        self.labels[line].show()

        self.anims[line] = QtCore.QPropertyAnimation(self.labels[line],
                                                     "geometry")
        self.anims[line].setDuration(time_visible * 1000)
        self.anims[line].setStartValue(
            QRectF(x_start, y_start, width_start, height_start))
        self.anims[line].setEndValue(
            QRectF(x_end, y_end, width_end, height_end))
        self.anims[line].finished.connect(lambda: self._finished(line))

        self.anims[line].start(QtCore.QAbstractAnimation.DeleteWhenStopped)

        if queue_next:
            next_line = line + 1
            if next_line < len(self.lines):
                self.timers[line] = QtCore.QTimer()
                self.timers[line].timeout.connect(
                    lambda: self.show_line(next_line, queue_next=True))
                self.timers[line].setSingleShot(True)
                self.timers[line].start(line_info.delay / 60.0 * 1000)

    ##############################################################################
    ### @fn   saveImage()
    ### @desc Saves a preview image. :D
    ##############################################################################
    def saveImage(self):

        dir = "ss"
        index = 0

        if not os.path.isdir(dir):
            if os.path.isfile(dir):
                return
            else:
                os.mkdir(dir)

        while True:
            if index >= 9999:
                return

            filename = os.path.join(dir, ("shot%04d.png" % index))

            if not os.path.isfile(filename):
                break

            index = index + 1

        if not os.path.isdir(dir):
            os.mkdir(dir)

        self.lblText.pixmap().save(filename)