diff --git a/src/Mousetrap.jl b/src/Mousetrap.jl index 6c2e27f..fc3bfa0 100644 --- a/src/Mousetrap.jl +++ b/src/Mousetrap.jl @@ -376,11 +376,6 @@ module Mousetrap push!(out.args, esc( :(is_native_widget(::$Type) = return true) )) - #= - push!(out.args, esc( - :(Mousetrap.get_top_level_widget(x::$Type) = return x) - )) - =# return out end @@ -4162,7 +4157,7 @@ module Mousetrap row_i = 1 for i in 1:get_n_columns(column_view) column = get_column_at(column_view, i) - set_widget_at!(column_view, column, row_i, widgets[i] + set_widget_at!(column_view, column, row_i, widgets[i]) end end export push_front_row! @@ -5548,13 +5543,21 @@ end # else MOUSETRAP_ENABLE_OPENGL_COMPONENT connect_signal_name = :connect_signal_ * signal * :! push!(out.args, esc(:( function Mousetrap.$connect_signal_name(f, x::Widget) - $connect_signal_name(f, Mousetrap.get_top_level_widget(x)) + if Mousetrap.is_native_widget(x) + log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(connect_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`") + else + $connect_signal_name(f, Mousetrap.get_top_level_widget(x)) + end end ))) push!(out.args, esc(:( function Mousetrap.$connect_signal_name(f, x::Widget, data::Data_t) where Data_t - $connect_signal_name(f, Mousetrap.get_top_level_widget(x), data) + if Mousetrap.is_native_widget(x) + log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(connect_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`") + else + $connect_signal_name(f, Mousetrap.get_top_level_widget(x), data) + end end ))) @@ -5562,7 +5565,11 @@ end # else MOUSETRAP_ENABLE_OPENGL_COMPONENT push!(out.args, esc(:( function $emit_signal_name(x::Widget, args...) - $emit_signal_name(Mousetrap.get_top_level_widget(x), args) + if Mousetrap.is_native_widget(x) + log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(emit_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`") + else + $emit_signal_name(Mousetrap.get_top_level_widget(x), args) + end end ))) @@ -5570,7 +5577,11 @@ end # else MOUSETRAP_ENABLE_OPENGL_COMPONENT push!(out.args, esc(:( function $disconnect_signal_name(x::Widget) - $disconnect_signal_name(Mousetrap.get_top_level_widget(x)) + if Mousetrap.is_native_widget(x) + log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(disconnect_signal_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`") + else + $disconnect_signal_name(Mousetrap.get_top_level_widget(x)) + end end ))) @@ -5578,7 +5589,11 @@ end # else MOUSETRAP_ENABLE_OPENGL_COMPONENT push!(out.args, esc(:( function $set_signal_blocked_name(x::Widget, b) - $set_signal_blocked_name(Mousetrap.get_top_level_widget(x), b) + if Mousetrap.is_native_widget(x) + log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(set_signal_blocked_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`") + else + $set_signal_blocked_name(Mousetrap.get_top_level_widget(x), b) + end end ))) @@ -5586,7 +5601,12 @@ end # else MOUSETRAP_ENABLE_OPENGL_COMPONENT push!(out.args, esc(:( function $get_signal_blocked_name(x::Widget) - return $get_signal_blocked_name(Mousetrap.get_top_level_widget(x)) + if Mousetrap.is_native_widget(x) + log_critical(Mousetrap.MOUSETRAP_DOMAIN, "In " * $(string(get_signal_blocked_name)) * ": object of type `$(typeof(x))` has no signal with ID `" * $(string(signal)) * "`") + return false + else + return $get_signal_blocked_name(Mousetrap.get_top_level_widget(x)) + end end ))) end diff --git a/src/docgen/signals.jl b/src/docgen/signals.jl index 3de2c2b..c1b6aa9 100644 --- a/src/docgen/signals.jl +++ b/src/docgen/signals.jl @@ -272,10 +272,8 @@ macro signal_table(T, signals...) for signal_id in signals push!(ids, string(signal_id)) - signature = signal_descriptors[signal_id][1] push!(signatures, replace(signature, "T" => string(T))) - push!(descriptions, signal_descriptors[signal_id][2]) end diff --git a/test/example.jl b/test/example.jl index 35453c2..4566518 100644 --- a/test/example.jl +++ b/test/example.jl @@ -1,8 +1,22 @@ # File used for debugging and for dosc examples, why are you snooping through this file? -# File used for debugging and for dosc examples, why are you snooping through this file? using Mousetrap +main() do app::Application + window = Window(app) + aspect_frame = AspectFrame(1.0) + + set_child!(window, aspect_frame) + + connect_signal_motion!(aspect_frame) do _, x, y + println((x,y)) + end + + present!(window) +end + +#== + main() do app::Application window = Window(app) diff --git a/test/runtests.jl b/test/runtests.jl index 4997064..bba8dd0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2335,81 +2335,44 @@ end function test_window(::Container) @testset "Window" begin - window = Window(Main.app[]) - other_window = Window(Main.app[]) - - Base.show(devnull, window) - @test Mousetrap.is_native_widget(window) - - close_request_called = Ref{Bool}(false) - connect_signal_close_request!(window, close_request_called) do self::Window, close_request_called - close_request_called[] = true - return WINDOW_CLOSE_REQUEST_RESULT_ALLOW_CLOSE - end - - activate_default_widget_called = Ref{Bool}(false) - connect_signal_activate_default_widget!(window, activate_default_widget_called) do self::Window, activate_default_widget_called - activate_default_widget_called[] = true - return nothing - end - - activate_focused_widget_called = Ref{Bool}(false) - connect_signal_activate_focused_widget!(window, activate_focused_widget_called) do self::Window, activate_focused_widget_called - activate_focused_widget_called[] = true - return nothing - end - - @test get_destroy_with_parent(window) == false - set_destroy_with_parent!(window, true) - @test get_destroy_with_parent(window) == true - @test get_focus_visible(window) == true - set_focus_visible!(window, false) - @test get_focus_visible(window) == false +main() do app::Application + window = Window(app) - @test get_has_close_button(window) == true - set_has_close_button!(window, false) - @test get_has_close_button(window) == false + # create column view with columns + column_view = ColumnView() - @test get_is_decorated(window) == true - set_is_decorated!(window, false) - @test get_is_decorated(window) == false + row_index_column = push_back_column!(column_view, " ") + count_column = push_back_column!(column_view, "#") + name_column = push_back_column!(column_view, "Name") + weight_column = push_back_column!(column_view, "Weight") + unit_column = push_back_column!(column_view, "Units") - @test get_is_modal(window) == false - set_is_modal!(window, true) - @test get_is_modal(window) == true + set_expand!.((row_index, count_column, name_column, weight_column, unit_column), true) - set_title!(window, "test") - @test get_title(window) == "test" + # fill columns with text + for i in 1:100 + row = [ + Label(string(i)), # row index + Label(string(rand(0:99))), # count + Label(rand(["Apple", "Orange", "Banana", "Kumquat", "Durian", "Mangosteen"])), # name + Label(string(rand(0:100))), # weight + Label(string(rand(["mg", "g", "kg", "ton"]))) # unit + ] - button = Entry() - set_child!(window, button) - set_default_widget!(window, button) - activate!(button) - - set_transient_for!(other_window, window) - - #@test activate_default_widget_called[] == true - #@test activate_focused_widget_called[] == true - - @test get_header_bar(window) isa HeaderBar + set_horizontal_alignment!.(row, ALIGNMENT_START) + push_back_row!(column_view, row...) + end - @test get_hide_on_close(window) == false - set_hide_on_close!(window, true) - @test get_hide_on_close(window) == true + # create viewport, this will add a scrollbar + scrolled_viewport = Viewport() + set_propagate_natural_width!(scrolled_viewport, true) # hides horizontal scrollbar + set_child!(scrolled_viewport, column_view) - @test get_is_closed(window) == true - present!(window) - @test get_is_closed(window) == false - set_minimized!(window, true) - set_maximized!(window, true) + # show both in window + set_child!(window, scrolled_viewport) + present!(window) - close!(other_window) - close!(window) - @test get_is_closed(window) == true - destroy!(window) - destroy!(other_window) - end end ### WIDGET @@ -2803,7 +2766,6 @@ end main(Main.app_id) do app::Application - #= Main.app[] = app Main.window[] = Window(app) set_is_decorated!(window, false) # prevent user from closing the window during tests @@ -2889,78 +2851,7 @@ main(Main.app_id) do app::Application present!(window) close!(window) #quit!(app) - =# - - window = Window(Main.app[]) - Base.show(devnull, window) - @test Mousetrap.is_native_widget(window) - - close_request_called = Ref{Bool}(false) - connect_signal_close_request!(window, close_request_called) do self::Window, close_request_called - close_request_called[] = true - return WINDOW_CLOSE_REQUEST_RESULT_ALLOW_CLOSE - end - - activate_default_widget_called = Ref{Bool}(false) - connect_signal_activate_default_widget!(window, activate_default_widget_called) do self::Window, activate_default_widget_called - activate_default_widget_called[] = true - return nothing - end - - activate_focused_widget_called = Ref{Bool}(false) - connect_signal_activate_focused_widget!(window, activate_focused_widget_called) do self::Window, activate_focused_widget_called - activate_focused_widget_called[] = true - return nothing - end - - @test get_destroy_with_parent(window) == false - set_destroy_with_parent!(window, true) - @test get_destroy_with_parent(window) == true - - @test get_focus_visible(window) == true - set_focus_visible!(window, false) - @test get_focus_visible(window) == false - - @test get_has_close_button(window) == true - set_has_close_button!(window, false) - @test get_has_close_button(window) == false - - @test get_is_decorated(window) == true - set_is_decorated!(window, false) - @test get_is_decorated(window) == false - - @test get_is_modal(window) == false - set_is_modal!(window, true) - @test get_is_modal(window) == true - - set_title!(window, "test") - @test get_title(window) == "test" - - button = Entry() - set_child!(window, button) - set_default_widget!(window, button) - activate!(button) - - #@test activate_default_widget_called[] == true - #@test activate_focused_widget_called[] == true - - @test get_header_bar(window) isa HeaderBar - - @test get_hide_on_close(window) == false - set_hide_on_close!(window, true) - @test get_hide_on_close(window) == true - - other_window = Window(app) - set_transient_for!(other_window, window) - @test get_is_closed(window) == true - present!(window) - @test get_is_closed(window) == false - set_minimized!(window, true) - set_maximized!(window, true) - close!(window) - @test get_is_closed(window) == true - destroy!(window) println("TODO: done.") end