Ejemplo n.º 1
0
 def test_simple(self):
     self.assertEqual(2, eval_el('hoge.ora.1', {"hoge": {
         "ora": [1, 2, 3]
     }}))
     self.assertEqual(3, eval_el('hoge.ora.2', {"hoge": {
         "ora": [1, 2, 3]
     }}))
Ejemplo n.º 2
0
def replace_all_els_in_text_frame(text_frame, model, clear_tags):
    """
     text_frame 中のテキストに EL 形式が一つ以上あれば、それを model の該当する値と置き換える
    """
    text_id = None

    for el in _iterate_els(text_frame.text):
        try:
            value = pyel.eval_el(el, model)
        except ValueError:
            replacing_text = ''  # Deleted None tags tags
            if not clear_tags:
                raise

        else:
            if not value:
                replacing_text = ''
            elif isinstance(value, numbers.Number):
                replacing_text = str(value)
            elif not isinstance(value, string_types):
                log.error(u"Invalid value for {%s}, model: %s" % (el, value))
                continue
            else:
                replacing_text = value

        if not replace_el_in_text_frame_with_str(text_frame, el,
                                                 replacing_text):
            log.error(
                u"Cannot find {%s} in one text-run. To fix this, select this whole EL [%s] and reset font size by "
                u"clicking size up then down" % (text_id, text_frame.text))
Ejemplo n.º 3
0
def replace_img_in_text_frame(text_frame, model, slide, rect):
    """
     text_frame 中のテキストに EL 形式があれば、それを model の該当する画像を挿入する
     見つからない場合は ValueError 例外となる
    """
    el = txt.extract_image(text_frame.text)
    if el is not None:
        value = pyel.eval_el(el, model)
        if not value:
            txt.replace_el_in_text_frame_with_str(text_frame, 'image:' + el,
                                                  '')
            return
        elif isinstance(value, string_types):
            replace_img(slide, value, rect, Pt(5))
        elif isinstance(value, list):
            if len(value) == 0:
                txt.replace_el_in_text_frame_with_str(text_frame,
                                                      'image:' + el, '')
                return
            replace_imgs(slide, value, rect, Pt(5))
        else:
            raise ValueError(u"Invalid value for {%s}, model: %s" %
                             (el, str(value)))

        text_frame.text = ''
Ejemplo n.º 4
0
def load_data_into_chart(chart, model):
    log.debug(u"model:%s" % model)
    # チャートタイトルから {} で囲まれた文字列を探し、それをキーとしてチャート設定と紐付ける
    if not chart.has_title or not chart.chart_title.has_text_frame:
        return

    # チャートIDを取得
    title_frame = chart.chart_title.text_frame
    chart_id = txt.search_first_el(title_frame.text)
    if not chart_id:
        return

    # チャートタイトル中のチャートIDを削除
    txt.replace_el_in_text_frame_with_str(title_frame, chart_id, '')

    # チャートタイトル中のEL式の置換を行う
    txt.replace_all_els_in_text_frame(title_frame, model)

    chart_setting = pyel.eval_el(chart_id, model)
    log.debug(u" Found chart_id: %s, chart_setting: %s" % (chart_id, chart_setting))

    # チャートにデータを流し込む
    _replace_chart_data_with_csv(chart, chart_id, chart_setting)

    # 軸の最大値、最小値を設定
    _set_value_axis(chart, chart_id, chart_setting)
Ejemplo n.º 5
0
def replace_all_els_in_text_frame(text_frame, model):
    """
     text_frame 中のテキストに EL 形式が一つ以上あれば、それを model の該当する値と置き換える
    """
    for el in _iterate_els(text_frame.text):
        value = pyel.eval_el(el, model)
        if isinstance(value, list):
            replace_el_in_text_frame_with_list(text_frame, el, value)
        else:
            raise ValueError(u"Invalid value for {%s}, model: %s" %
                             (el, str(value)))
Ejemplo n.º 6
0
def load_data_into_table(table, model):
    # テーブルIDを取得
    table_id = get_table_id(table)
    if not table_id:
        return
    log.debug("table_id:%s" % table_id)

    # 対象テーブルIDのモデル情報を取得
    table_setting = pyel.eval_el(table_id, model)
    log.debug(u" Found table_id: %s, table_setting: %s" %
              (table_id, table_setting))

    # データを流し込む
    _load_data(table, table_setting)
Ejemplo n.º 7
0
def load_data_into_chart(chart, model):
    # チャートタイトルから {} で囲まれた文字列を探し、それをキーとしてチャート設定と紐付ける
    if not chart.has_title or not chart.chart_title.has_text_frame:
        return

    title_frame = chart.chart_title.text_frame
    chart_id = txt.search_first_el(title_frame.text)
    if not chart_id:
        return

    chart_setting = pyel.eval_el(chart_id, model)
    log.debug(u" Found chart_id: %s, chart_setting: %s" %
              (chart_id, chart_setting))

    txt.replace_el_in_text_frame_with_str(title_frame, chart_id, '')
    _replace_chart_data_with_csv(chart, chart_id, chart_setting)
    _set_value_axis(chart, chart_id, chart_setting)