示例#1
0
    def on_export(self, event: wx.Event):
        org_morph_list = []
        rep_morph_list = []
        ratio_list = []
        for m in self.get_morph_list():
            org_morph_list.append(m[0])
            rep_morph_list.append(m[1])
            ratio_list.append(m[2])

        output_morph_path = MFileUtils.get_output_morph_path(
            self.file_set.motion_vmd_file_ctrl.file_ctrl.GetPath(),
            self.file_set.org_model_file_ctrl.file_ctrl.GetPath(),
            self.file_set.rep_model_file_ctrl.file_ctrl.GetPath())

        try:
            with open(output_morph_path,
                      encoding='cp932',
                      mode='w',
                      newline='') as f:
                cw = csv.writer(f,
                                delimiter=",",
                                quotechar='"',
                                quoting=csv.QUOTE_ALL)

                # 元モーフ行
                cw.writerow(org_morph_list)
                # 先モーフ行
                cw.writerow(rep_morph_list)
                # 大きさ
                cw.writerow(ratio_list)

            logger.info("出力成功: %s" % output_morph_path)

            dialog = wx.MessageDialog(self.frame,
                                      "モーフデータのエクスポートに成功しました \n'%s'" %
                                      (output_morph_path),
                                      style=wx.OK)
            dialog.ShowModal()
            dialog.Destroy()

        except Exception:
            dialog = wx.MessageDialog(
                self.frame,
                "モーフデータのエクスポートに失敗しました \n'%s'\n\n%s." %
                (output_morph_path, traceback.format_exc()),
                style=wx.OK)
            dialog.ShowModal()
            dialog.Destroy()
示例#2
0
    def on_import(self, event: wx.Event):
        input_morph_path = MFileUtils.get_output_morph_path(
            self.file_set.motion_vmd_file_ctrl.file_ctrl.GetPath(),
            self.file_set.org_model_file_ctrl.file_ctrl.GetPath(),
            self.file_set.rep_model_file_ctrl.file_ctrl.GetPath())

        with wx.FileDialog(
                self.frame,
                "モーフ組み合わせCSVを読み込む",
                wildcard=u"CSVファイル (*.csv)|*.csv|すべてのファイル (*.*)|*.*",
                defaultDir=os.path.dirname(input_morph_path),
                style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:

            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return  # the user changed their mind

            # Proceed loading the file chosen by the user
            target_morph_path = fileDialog.GetPath()
            try:
                with open(target_morph_path, 'r') as f:
                    cr = csv.reader(f, delimiter=",", quotechar='"')
                    morph_lines = [row for row in cr]

                    if len(morph_lines) == 0:
                        return

                    org_choice_values = morph_lines[0]
                    rep_choice_values = morph_lines[1]
                    rep_rate_values = morph_lines[2]

                    logger.debug("org_choice_values: %s", org_choice_values)
                    logger.debug("rep_choice_values: %s", rep_choice_values)
                    logger.debug("rep_rate_values: %s", rep_rate_values)

                    if len(org_choice_values) == 0 or len(
                            rep_choice_values) == 0 or len(
                                rep_rate_values) == 0:
                        return

                    for vcv, rcv, rrv in zip(org_choice_values,
                                             rep_choice_values,
                                             rep_rate_values):
                        vc = self.org_choices[-1]
                        rc = self.rep_choices[-1]
                        rr = self.ratios[-1]
                        # 全件なめる
                        for v, c in [(vcv, vc), (rcv, rc)]:
                            logger.debug("v: %s, c: %s", v, c)
                            is_seted = False
                            for n in range(c.GetCount()):
                                for p in ["目", "眉", "口", "他", "?"]:
                                    for s in ["", "○", "●", "▲"]:
                                        # パネル情報を含める
                                        txt = "{0}{1}:{2}".format(p, s, v[:10])
                                        # if v == vcv:
                                        # 	logger.debug("txt: %s, c.GetString(n): %s", txt, c.GetString(n))
                                        if c.GetString(n).strip() == txt:
                                            logger.debug(
                                                "[HIT] txt: %s, c.GetString(n): %s, n: %s",
                                                txt, c.GetString(n), n)
                                            # パネルとモーフ名で一致している場合、採用
                                            c.SetSelection(n)
                                            is_seted = True
                                            break
                                    if is_seted:
                                        break
                        # 大きさ補正を設定する
                        try:
                            rr.SetValue(float(rrv))
                        except Exception:
                            pass

                        # 行追加
                        self.add_line()

                # パス変更
                self.file_set.set_output_vmd_path(event)

            except Exception:
                dialog = wx.MessageDialog(
                    self.frame,
                    "CSVファイルが読み込めませんでした '%s'\n\n%s." %
                    (target_morph_path, traceback.format_exc()),
                    style=wx.OK)
                dialog.ShowModal()
                dialog.Destroy()