From ac18ecc916e03f789fcaadcb85b485230db2c824 Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Fri, 1 May 2026 14:03:07 +0900 Subject: [PATCH] WIP: De-kajiggering --- src/gd_lib.erl | 11 +++++--- src/gd_v_call.erl | 68 ++++++++++++++++++++++++++------------------- src/gd_v_devman.erl | 39 ++++++++++---------------- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/gd_lib.erl b/src/gd_lib.erl index 96ec690..a8512eb 100644 --- a/src/gd_lib.erl +++ b/src/gd_lib.erl @@ -7,7 +7,7 @@ -include_lib("wx/include/wx.hrl"). -export([is_int/1, - mono_text/2, mono_text/3, + mono_text/2, mono_text/3, mono_text/4, button/2, button/3, copy_to_clipboard/1]). @@ -50,14 +50,17 @@ mono_text(Parent, Name) -> %% notion of text styling). mono_text(Parent, Name, Value) -> - Text = wxStaticText:new(Parent, ?wxID_ANY, Value), + mono_text(Parent, Name, Value, []). + +mono_text(Parent, Name, Value, Options) -> + Text = wxTextCtrl:new(Parent, ?wxID_ANY, [{value, Value} | Options]), Font = wxFont:new(10, ?wxFONTFAMILY_TELETYPE, ?wxFONTSTYLE_NORMAL, ?wxFONTWEIGHT_NORMAL), ok = - case wxStaticText:setFont(Text, Font) of + case wxTextCtrl:setFont(Text, Font) of true -> ok; false -> tell(info, "wxStaticText ~p is already monospace.", [Text]) end, - #w{name = Name, id = wxStaticText:getId(Text), wx = Text}. + #w{name = Name, id = wxTextCtrl:getId(Text), wx = Text}. -spec button(Parent, Label) -> Button diff --git a/src/gd_v_call.erl b/src/gd_v_call.erl index b86209b..9d63721 100644 --- a/src/gd_v_call.erl +++ b/src/gd_v_call.erl @@ -96,18 +96,21 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) -> ok = wxChoice:setSelection(KeyPicker, ZeroBasedSelected), _ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)), - {ArgSz, Args, Dimensions} = call_arg_sizer(Frame, J, FunSpec), + {ArgSz, Args, HasArgs} = call_arg_sizer(Frame, J, FunSpec), {ParamSz, Params} = call_param_sizer(Frame, J), Action = #w{wx = ActionBn} = gd_lib:button(Frame, ActionLabel), TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]), TX_Sz_Box = wxStaticBoxSizer:getStaticBox(TX_Sz), - TX_Data = #w{wx = DataT} = gd_lib:mono_text(TX_Sz_Box, tx_hash), - TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz_Box, tx_hash), - TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_hash), + TxStyle = [{style, ?wxTE_READONLY}], + TX_Data = #w{wx = DataT} = gd_lib:mono_text(TX_Sz_Box, tx_data, "", TxStyle), + TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz_Box, tx_hash, "", TxStyle), + TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_info, "", TxStyle), + Line = wxStaticLine:new(TX_Sz_Box, [{style, ?wxLI_HORIZONTAL}]), - Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out), + OutStyle = [{style, ?wxTE_MULTILINE bor ?wxTE_READONLY}], + Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out, "", OutStyle), Copy = #w{wx = CopyBn} = gd_lib:button(TX_Sz_Box, J("Copy")), _ = wxStaticBoxSizer:add(TX_Sz, DataT, zxw:flags({base, 5})), @@ -117,14 +120,19 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) -> _ = wxStaticBoxSizer:add(TX_Sz, OutTxt, zxw:flags({wide, 5})), _ = wxStaticBoxSizer:add(TX_Sz, CopyBn, zxw:flags({base, 5})), - _ = wxSizer:add(MainSz, ArgSz, zxw:flags({wide, 5})), + ArgSzArgs = + case HasArgs of + true -> {wide, 5}; + false -> {base, 5} + end, + _ = wxSizer:add(MainSz, ArgSz, zxw:flags(ArgSzArgs)), _ = wxSizer:add(MainSz, KeySz, zxw:flags({base, 5})), _ = wxSizer:add(MainSz, ParamSz, zxw:flags({base, 5})), _ = wxSizer:add(MainSz, ActionBn, zxw:flags({base, 5})), - _ = wxSizer:add(MainSz, TX_Sz, zxw:flags({base, 5})), + _ = wxSizer:add(MainSz, TX_Sz, zxw:flags({wide, 5})), _ = wxFrame:setSizer(Frame, MainSz), - _ = wxFrame:setSize(Frame, Dimensions), + _ = wxFrame:setSize(Frame, {900, 900}), _ = wxSizer:layout(MainSz), ok = wxFrame:connect(Frame, close_window), ok = wxFrame:connect(Frame, command_button_clicked), @@ -141,17 +149,17 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) -> call_arg_sizer(Frame, J, {CallArgs, ReturnType}) -> SpecSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Function Spec")}]), - {CallSz, CallControls, Dimensions} = call_sizer(Frame, J, CallArgs), + {CallSz, CallControls, HasArgs} = call_sizer(Frame, J, CallArgs), ReturnSz = return_sizer(Frame, J, ReturnType), _ = wxStaticBoxSizer:add(SpecSz, CallSz, zxw:flags({wide, 5})), _ = wxStaticBoxSizer:add(SpecSz, ReturnSz, zxw:flags({base, 5})), - {SpecSz, CallControls, Dimensions}. + {SpecSz, CallControls, HasArgs}. call_sizer(Frame, J, []) -> CallSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Call Args")}]), Args = wxStaticText:new(Frame, ?wxID_ANY, ["[", J("No Args"), "]"]), _ = wxStaticBoxSizer:add(CallSz, Args, zxw:flags({wide, 5})), - {CallSz, [], {500, 700}}; + {CallSz, [], false}; call_sizer(Frame, J, CallArgs) -> ScrollWin = wxScrolledWindow:new(Frame), ScrollSz = wxBoxSizer:new(?wxVERTICAL), @@ -172,7 +180,7 @@ call_sizer(Frame, J, CallArgs) -> #w{name = Name, id = wxTextCtrl:getId(C), wx = C} end, Controls = lists:map(AddArg, CallArgs), - {CallSz, Controls, {500, 900}}. + {CallSz, Controls, true}. return_sizer(Frame, J, ReturnType) -> ReturnSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Return Type")}]), @@ -195,28 +203,28 @@ call_param_sizer(Frame, J) -> TTL_L = wxStaticText:new(Frame, ?wxID_ANY, "TTL"), TTL_T = wxTextCtrl:new(Frame, ?wxID_ANY), ok = wxTextCtrl:setValue(TTL_T, integer_to_list(DefTTL)), - GasP_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas Price")), - GasP_T = wxTextCtrl:new(Frame, ?wxID_ANY), - ok = wxTextCtrl:setValue(GasP_T, integer_to_list(DefGasP)), Gas_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas")), Gas_T = wxTextCtrl:new(Frame, ?wxID_ANY), ok = wxTextCtrl:setValue(Gas_T, integer_to_list(DefGas)), + GasP_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas Price")), + GasP_T = wxTextCtrl:new(Frame, ?wxID_ANY), + ok = wxTextCtrl:setValue(GasP_T, integer_to_list(DefGasP)), Amount_L = wxStaticText:new(Frame, ?wxID_ANY, J("TX Amount")), Amount_T = wxTextCtrl:new(Frame, ?wxID_ANY), ok = wxTextCtrl:setValue(Amount_T, integer_to_list(DefAmount)), _ = wxFlexGridSizer:add(GridSz, TTL_L, zxw:flags({base, 5})), _ = wxFlexGridSizer:add(GridSz, TTL_T, zxw:flags({wide, 5})), - _ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})), - _ = wxFlexGridSizer:add(GridSz, GasP_T, zxw:flags({wide, 5})), _ = wxFlexGridSizer:add(GridSz, Gas_L, zxw:flags({base, 5})), _ = wxFlexGridSizer:add(GridSz, Gas_T, zxw:flags({wide, 5})), + _ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})), + _ = wxFlexGridSizer:add(GridSz, GasP_T, zxw:flags({wide, 5})), _ = wxFlexGridSizer:add(GridSz, Amount_L, zxw:flags({base, 5})), _ = wxFlexGridSizer:add(GridSz, Amount_T, zxw:flags({wide, 5})), _ = wxSizer:add(ParamSz, GridSz, zxw:flags(wide)), Params = [{ "TTL", fun gte_0/1, TTL_T}, - {J("Gas Price"), fun gt_0/1, GasP_T}, {J("Gas") , fun gt_0/1, Gas_T}, + {J("Gas Price"), fun gt_0/1, GasP_T}, {J("TX Amount"), fun gte_0/1, Amount_T}], {ParamSz, Params}. @@ -289,13 +297,13 @@ engage3(State, ChainID, Params) -> engage4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) -> tell(info, "Args: ~p", [Args]), - {CallerID, Nonce, TTL, GP, Gas, Amount} = Params, - case hz:contract_create_built(CallerID, Nonce, Gas, GP, Amount, TTL, Build, Args) of + {CallerID, Nonce, TTL, Gas, GP, Amount} = Params, + case hz:contract_create_built(CallerID, Nonce, Amount, TTL, Gas, GP, Build, Args) of {ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX); Error -> handle_troubling(State, Error) end; engage4(State = #s{fundef = {Name, Type}, con_id = ConID, build = Build}, ChainID, Params, Args) -> - {CallerID, Nonce, TTL, GP, Gas, Amount} = Params, + {CallerID, Nonce, TTL, Gas, GP, Amount} = Params, AACI = maps:get(aaci, Build), case hz:contract_call(CallerID, Nonce, Gas, GP, Amount, TTL, AACI, ConID, Name, Args) of {ok, UnsignedTX} -> @@ -317,7 +325,7 @@ params(State = #s{kp = #w{wx = KeyPicker}}) -> params2(#s{params = Params}, PK, Nonce) -> case lists:foldl(fun extract/2, {ok, []}, Params) of - {ok, [TTL, GP, Gas, Amount]} -> {ok, {PK, Nonce, TTL, GP, Gas, Amount}}; + {ok, [Amount, GP, Gas, TTL]} -> {ok, {PK, Nonce, TTL, Gas, GP, Amount}}; Error -> Error end. @@ -344,9 +352,13 @@ deploy(State, ChainID, CallerID, CreateTX) -> deploy2(State, SignedTX) -> case hz:post_tx(SignedTX) of - {ok, Data} -> check_tx(State#s{tx_data = Data}); -% {ok, WTF} -> handle_troubling(State, {error, WTF}); - Error -> handle_troubling(State, Error) + {ok, Data} -> + case maps:is_key("reason", Data) of + false -> check_tx(State#s{tx_data = Data}); + true -> handle_troubling(State, {error, Data}) + end; + Error -> + handle_troubling(State, Error) end. @@ -358,7 +370,7 @@ do_call(State, ChainID, CallerID, UnsignedTX) -> do_call2(State, SignedTX) -> case hz:post_tx(SignedTX) of - {ok, Data} -> check_tx(State = #s{tx_data = Data}); + {ok, Data} -> check_tx(State#s{tx_data = Data}); Error -> handle_troubling(State, Error) end. @@ -391,14 +403,14 @@ check_tx(State = #s{tx_data = TXData}) -> update_info(State = #s{tx_info = TXInfo, out = #w{wx = Out}}) -> Formatted = io_lib:format("TXInfo: ~p~n", [TXInfo]), - ok = wxStaticText:setLabel(Out, Formatted), + ok = wxTextCtrl:setValue(Out, Formatted), State. copy(#s{tx_info = none}) -> ok; copy(#s{out = #w{wx = Out}}) -> - Output = wxStaticText:getLabel(Out), + Output = wxTextCtrl:getValue(Out), gd_lib:copy_to_clipboard(Output). diff --git a/src/gd_v_devman.erl b/src/gd_v_devman.erl index cd2d7e4..0b09b08 100644 --- a/src/gd_v_devman.erl +++ b/src/gd_v_devman.erl @@ -233,8 +233,8 @@ handle_cast({dryrun_result, ConID, CallInfo}, State) -> ok = do_dryrun_result(State, ConID, CallInfo), {noreply, State}; handle_cast({trouble, Info}, State) -> - ok = handle_troubling(State, Info), - {noreply, State}; + NewState = handle_troubling(State, Info), + {noreply, NewState}; handle_cast(Unexpected, State) -> ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]), {noreply, State}. @@ -287,8 +287,9 @@ handle_event(Event, State) -> {noreply, State}. -handle_troubling(#s{frame = Frame}, Info) -> - zxw:show_message(Frame, Info). +handle_troubling(State = #s{frame = Frame}, Info) -> + ok = zxw:show_message(Frame, Info), + State. code_change(_, State, _) -> @@ -374,20 +375,16 @@ add_code_page2(State = #s{j = J}, {file, File}) -> add_code_page(State, {file, File}, Code); Error -> Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Error]), - ok = handle_troubling(State, Message), - State + handle_troubling(State, Message) end; {error, Reason} -> Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Reason]), - ok = handle_troubling(State, Message), - State + handle_troubling(State, Message) end; add_code_page2(State, {hash, Address}) -> open_hash2(State, Address). add_code_page(State = #s{tabs = TopBook, code = {Codebook, Pages}}, Location, Code) -> - Color = wxSystemSettings:getColour(?wxSYS_COLOUR_WINDOW), - tell("Color: ~p", [Color]), Window = wxWindow:new(Codebook, ?wxID_ANY), PageSz = wxBoxSizer:new(?wxHORIZONTAL), @@ -612,8 +609,7 @@ open_hash2(State, Address) -> {ok, Source} -> open_hash3(State, Address, Source); Error -> - ok = handle_troubling(State, Error), - State + handle_troubling(State, Error) end. open_hash3(State, Address, Source) -> @@ -640,15 +636,11 @@ save(State = #s{prefs = Prefs, code = {Codebook, Pages}}) -> case filelib:ensure_dir(Path) of ok -> case file:write_file(Path, Source) of - ok -> - State; - Error -> - ok = handle_troubling(State, Error), - State + ok -> State; + Error -> handle_troubling(State, Error) end; Error -> - ok = handle_troubling(State, Error), - State + handle_troubling(State, Error) end; Page = #p{path = {hash, Hash}, code = Widget} -> DefDir = @@ -718,12 +710,10 @@ save_dialog(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pa NewCode = {Codebook, NewPages}, State#s{prefs = NewPrefs, code = NewCode}; Error -> - ok = handle_troubling(State, Error), - State + handle_troubling(State, Error) end; Error -> - ok = handle_troubling(State, Error), - State + handle_troubling(State, Error) end end; ?wxID_CANCEL -> @@ -773,8 +763,7 @@ load2(State, Address) -> {ok, Source} -> load3(State, Address, Source); Error -> - ok = handle_troubling(State, Error), - State + handle_troubling(State, Error) end. load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j = J},