コード例 #1
0
ファイル: qt_wrapper.py プロジェクト: Fine112358/dnf-
def add_row(form_layout: QFormLayout,
            row_name: str,
            row_widget: QWidget,
            minium_row_name_size=0):
    if minium_row_name_size > 0:
        row_name = padLeftRight(row_name, minium_row_name_size, mode="left")
    form_layout.addRow(row_name, row_widget)
コード例 #2
0
ファイル: test_util.py プロジェクト: fzls/djc_helper
def test_pad_left_right():
    assert padLeftRight("test", 4) == "test"
    assert padLeftRight("test", 8) == "  test  "
    assert padLeftRight("test", 8, pad_char="-") == "--test--"
    assert padLeftRight("test", 8, mode="left") == "test    "
    assert padLeftRight("test", 8, mode="right") == "    test"
    assert padLeftRight("tests", 4, need_truncate=True) == "t..."
コード例 #3
0
def format_act(act_id: str,
               act_name: str,
               begin_time: str,
               end_time: str,
               needPadding=False):
    if needPadding:
        act_name = padLeftRight(act_name, 44, mode="left")

    msg = f"活动 {act_name}({act_id})"

    if end_time != "":
        msg += f" 开始时间为 {begin_time},结束时间为 {end_time},"
        if not is_act_expired(end_time):
            msg += f"距离结束还有 {get_remaining_time(end_time)}"
        else:
            msg += f"已经结束了 {get_past_time(end_time)}"
    else:
        msg += " 尚无已知的开始和结束时间"

    return msg
コード例 #4
0
    def show_current_valid_act_infos(self):
        acts: List[ActCommonInfo] = []

        # others
        for not_ams_act in not_ams_activities:
            if is_act_expired(not_ams_act.dtEndTime):
                continue

            acts.append(not_ams_act.get_common_info())

        # ams
        for attr_name, act_id in self.__dict__.items():
            if not attr_name.startswith("iActivityId_"):
                continue

            # 部分电脑上可能会在这一步卡住,因此加一个标志项,允许不启用活动
            if exists_flag_file("不查询活动.txt"):
                continue

            act = search_act(act_id)
            if act is None:
                continue

            if is_act_expired(act.dtEndTime):
                continue

            acts.append(act.get_common_info())

        # ide
        for attr_name, act_id in self.__dict__.items():
            if not attr_name.startswith("ide_iActivityId_"):
                continue

            # 部分电脑上可能会在这一步卡住,因此加一个标志项,允许不启用活动
            if exists_flag_file("不查询活动.txt"):
                continue

            act = search_ide_act(act_id)
            if act is None:
                continue

            if is_act_expired(act.get_endtime()):
                continue

            acts.append(act.get_common_info(act_id))

        acts.sort(key=lambda act: act.dtEndTime)

        heads = ["序号", "活动名称", "活动ID", "开始时间", "结束时间", "剩余时间"]
        colSizes = [4, 44, 10, 20, 20, 14]

        table = ""
        table += "\n" + tableify(heads, colSizes)
        for idx, act in enumerate(acts):
            line_color = "bold_green"
            if is_act_expired(act.dtEndTime):
                line_color = "bold_black"

            print_act_name = padLeftRight(act.sActivityName,
                                          colSizes[1],
                                          mode="left",
                                          need_truncate=True)
            remaining_times = parse_time(act.dtEndTime) - get_now()
            remaining_times = f"{remaining_times.days:3d} 天 {remaining_times.seconds // 3600} 小时"

            table += ("\n" + color(line_color) + tableify(
                [
                    idx + 1, print_act_name, act.iActivityId, act.dtBeginTime,
                    act.dtEndTime, remaining_times
                ],
                colSizes,
                need_truncate=False,
            ))

        logger.info(table)