Exemplo n.º 1
0
def main(lsysargv, sysargv):
    sc = 1.0
    xfl.fl_initialize(lsysargv, sysargv, "FormDemo", None, 0)
    ui = create_form_form()
    strng = "%.2f" % sc
    xfl.fl_set_input(ui.pscaleobj, strng)
    xfl.fl_show_form(ui.pform, xfl.FL_PLACE_CENTER | xfl.FL_FREE_SIZE, xfl.FL_FULLBORDER, "Scaling")
    while True:
        oldsc = sc
        pobj = xfl.fl_do_forms()
        if xfl.fl_is_same_object(pobj, ui.pexitobj):
            sys.exit(0)
        elif xfl.fl_is_same_object(pobj, ui.psmallerobj):
            sc = sc * 0.8
        elif xfl.fl_is_same_object(pobj, ui.plargerobj):
            sc = sc / 0.8
        elif xfl.fl_is_same_object(pobj, ui.pscaleobj):
            sc = float(xfl.fl_get_input(ui.pscaleobj))
        if sc < 0.50:
            sc = 0.50
        elif sc > 3:
            sc = 3
        if sc != oldsc:
            xfl.fl_scale_form(ui.pform, sc / oldsc, sc / oldsc)
            xfl.fl_redraw_form(ui.pform)  # to avoid garbage on screen
            strng = "%.2f" % sc
            xfl.fl_set_input(ui.pscaleobj, strng)
def bounds_cb(pobj, data):
    # char buf[ 50 ]

    if not data:
        xmin = float(xfl.fl_get_input(xypui.xmin))
        xmax = float(xfl.fl_get_input(xypui.xmax))

        if xmin <= 0.0:
            xmin = 1.0
            xfl.fl_set_input(xypui.xmin, "1.0")

        if xmax <= 0.0:
            xmax = 10.0
            xfl.fl_set_input(xypui.xmax, "10.0")

        xfl.fl_set_xyplot_xbounds(xypui.xyplot, xmin, xmax)

        xmin, xmax = xfl.fl_get_xyplot_xbounds(xypui.xyplot)
        #sprintf( buf, "%g", xmin );
        buf = str(xmin)
        xfl.fl_set_input(xypui.xmin, buf)
        #sprintf( buf, "%g", xmax );
        buf = str(xmax)
        xfl.fl_set_input(xypui.xmax, buf)

    else:
        ymin = float(xfl.fl_get_input(xypui.ymin))
        ymax = float(xfl.fl_get_input(xypui.ymax))

        if ymin <= 0.0:
            ymin = 1.0
            xfl.fl_set_input(xypui.ymin, "1.0")

        if ymax <= 0.0:
            ymax = 10.0
            xfl.fl_set_input(xypui.ymax, "10.0")

        xfl.fl_set_xyplot_ybounds(xypui.xyplot, ymin, ymax)

        ymin, ymax = xfl.fl_get_xyplot_ybounds(xypui.xyplot)
        #sprintf( buf, "%g", ymin );
        buf = str(ymin)
        xfl.fl_set_input(xypui.ymin, buf)
        #sprintf( buf, "%g", ymax );
        buf = str(ymax)
        xfl.fl_set_input(xypui.ymax, buf)
def create_form_axypform():

    fdui = FD_axyform()

    fdui.axypform = xfl.fl_bgn_form(xfl.FL_NO_BOX, 431, 301)

    xfl.fl_add_box(xfl.FL_UP_BOX, 0, 0, 431, 301, "")

    fdui.xyplot = xfl.fl_add_xyplot(xfl.FL_ACTIVE_XYPLOT, 20, 50, \
            285, 235, "")
    xfl.fl_set_xyplot_xscale(fdui.xyplot, xfl.FL_LOG, 2.0)
    xfl.fl_set_xyplot_yscale(fdui.xyplot, xfl.FL_LOG, 2.0)

    xfl.fl_set_object_boxtype(fdui.xyplot, xfl.FL_DOWN_BOX)
    xfl.fl_set_object_color(fdui.xyplot, xfl.FL_BLACK, xfl.FL_GREEN)
    xfl.fl_set_object_lalign(fdui.xyplot, \
            xfl.fl_to_inside_lalign(xfl.FL_ALIGN_BOTTOM))

    xfl.fl_set_object_callback(fdui.xyplot, xyplot_cb, 0)
    xfl.fl_set_object_gravity(fdui.xyplot, xfl.FL_NorthWest, xfl.FL_SouthEast)

    pobj = xfl.fl_add_checkbutton(xfl.FL_PUSH_BUTTON, 315, 40, 80, 25, \
            "AlwaysReturn")
    xfl.fl_set_object_color(pobj, xfl.FL_COL1, xfl.FL_BLUE)
    xfl.fl_set_object_callback(pobj, alwaysreturn_cb, 0)
    xfl.fl_set_object_gravity(pobj, xfl.FL_NorthEast, xfl.FL_NorthEast)

    pobj = xfl.fl_add_checkbutton(xfl.FL_PUSH_BUTTON, 315, 65, 80, 25, \
            "Interpolate")
    xfl.fl_set_object_color(pobj, xfl.FL_COL1, xfl.FL_BLUE)
    xfl.fl_set_object_callback(pobj, interpolate_cb, 0)
    xfl.fl_set_object_gravity(pobj, xfl.FL_NorthEast, xfl.FL_NorthEast)

    pobj = xfl.fl_add_checkbutton(xfl.FL_PUSH_BUTTON, 315, 90, 85, 25, \
            "InspectOnly")
    xfl.fl_set_object_color(pobj, xfl.FL_COL1, xfl.FL_BLUE)
    xfl.fl_set_object_callback(pobj, inspect_cb, 0)
    xfl.fl_set_object_gravity(pobj, xfl.FL_NorthEast, xfl.FL_NorthEast)

    pobj = xfl.fl_add_checkbutton(xfl.FL_PUSH_BUTTON, 315, 120, 85, 25, \
            "NoTics")
    xfl.fl_set_object_color(pobj, xfl.FL_COL1, xfl.FL_BLUE)
    xfl.fl_set_object_callback(pobj, notic_cb, 0)
    xfl.fl_set_object_gravity(pobj, xfl.FL_NorthEast, xfl.FL_NorthEast)

    fdui.xmin = xfl.fl_add_input(xfl.FL_FLOAT_INPUT, 315, 150, 50, 20,
            " x_min")
    xfl.fl_set_input(fdui.xmin, "1.0")
    xfl.fl_set_object_lalign(fdui.xmin, xfl.FL_ALIGN_RIGHT)
    xfl.fl_set_object_callback(fdui.xmin, bounds_cb, 0)
    xfl.fl_set_object_gravity(fdui.xmin, xfl.FL_NorthEast, xfl.FL_NorthEast)

    fdui.xmax = xfl.fl_add_input(xfl.FL_FLOAT_INPUT, 315, 170, 50, 20,
            " x_max")
    xfl.fl_set_input(fdui.xmax, "10.0")
    xfl.fl_set_object_lalign(fdui.xmax, xfl.FL_ALIGN_RIGHT)
    xfl.fl_set_object_callback(fdui.xmax, bounds_cb, 0)
    xfl.fl_set_object_gravity(fdui.xmax, xfl.FL_NorthEast, xfl.FL_NorthEast)

    fdui.ymin = xfl.fl_add_input(xfl.FL_FLOAT_INPUT, 315, 200, 50, 20,
             " y_min")
    xfl.fl_set_input(fdui.ymin, "1.0")
    xfl.fl_set_object_lalign(fdui.ymin, xfl.FL_ALIGN_RIGHT)
    xfl.fl_set_object_callback(fdui.ymin, bounds_cb, 1)
    xfl.fl_set_object_gravity(fdui.ymin, xfl.FL_NorthEast, xfl.FL_NorthEast)

    fdui.ymax = xfl.fl_add_input(xfl.FL_FLOAT_INPUT, 315, 220, 50, 20,
             " y_max")
    xfl.fl_set_input(fdui.ymax, "10.0")
    xfl.fl_set_object_lalign(fdui.ymax, xfl.FL_ALIGN_RIGHT)
    xfl.fl_set_object_callback(fdui.ymax, bounds_cb, 1)
    xfl.fl_set_object_gravity(fdui.ymax, xfl.FL_NorthEast, xfl.FL_NorthEast)

    fdui.status = xfl.fl_add_box(xfl.FL_BORDER_BOX, 20, 15, 285, 25, "")
    xfl.fl_set_object_boxtype(fdui.status, xfl.FL_DOWN_BOX)
    xfl.fl_set_object_gravity(fdui.status, xfl.FL_NorthWest, xfl.FL_NorthEast)
    xfl.fl_set_object_lalign(fdui.status, xfl.FL_ALIGN_CENTER)

    pobj = xfl.fl_add_button(xfl.FL_NORMAL_BUTTON, 325, 250, 90, 30, "Done")
    xfl.fl_set_object_gravity(pobj, xfl.FL_SouthEast, xfl.FL_SouthEast)

    xfl.fl_end_form()

    return fdui