pman_win.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 667 行 · 第 1/2 页
ERL
667 行
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%%% ------------------------------------------------------------%% Purpose: window management and the gs interface%% -------------------------------------------------------------module(pman_win).%% ---------------------------------------------------------------%% The user interface exports %% ----------------------------------------------------------------export([pman_window/3, window/1, module_data/1, display/1, format/2, dialog_window/2, configeditor/2, configwin/3, update/1, update/3, msg_win/1, title/1, remove_menu/1, add_menu/3, change_colour/3, links_menus/1, calc_columnwidths/1]).-export([font/0, font/1]).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants%%-include("pman_win.hrl").%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pman_window/3 - Create a GS window and components for the%% Pman overview window, the main window.%%%% Arguments:%% Size number of processes%% HiddenModules list of modules %% Nodes list of supervised nodes%%%% Return: %% {Win, Grid, Frame, Procnum, W, H} where%% Win The GS top window%% Grid The GS grid%% Procnum Number of displayed processes%%pman_window(Size, _HiddenModules, Nodes) -> GS = gs:start([{kernel,true}]), Font = font(GS), Win_Options = [{title, lists:concat(["Pman: Overview on ",node()])}, {width, ?WIN_WIDTH}, {height, ?WIN_HEIGHT}, {destroy, true}, {keypress,true}], Win = gs:create(window, GS, Win_Options), %% Menu bar MenuBar = gs:create(menubar, Win, []), MBFile = gs:create(menubutton, MenuBar, [{label,{text," File "}}, {font,Font}, {underline,1}]), MBView = gs:create(menubutton, MenuBar, [{label,{text, " View "}}, {font,Font}, {underline,1}]), MBTrace = gs:create(menubutton, MenuBar, [{label,{text, " Trace "}}, {font,Font}, {underline,1}]), MBHelp = gs:create(menubutton, MenuBar, [{label, {text, " Help "}}, {font,Font}, {side,right}, {underline,1}]), %% Addition of a menu for distribution add_node_menu(MenuBar, Nodes, Font), %% All menu buttons MenuFile = gs:create(menu, MBFile, []), MenuView = gs:create(menu, MBView, []), MenuTrace = gs:create(menu, MBTrace, []), MenuHelp = gs:create(menu, MBHelp, []), %% File menu gse:named_menuitem('Default Options', MenuFile, [{label,{text,"Options..."}}, {font,Font}, {underline,0}]), gse:named_menuitem('Save Options',MenuFile, [{label,{text,"Save Options"}}, {font,Font}]), gse:named_menuitem('Exit', MenuFile, [{label,{text,"Exit"}}, {font,Font}, {underline,0}]), %% View menu gse:named_menuitem('Hide All',MenuView, [{label, {text, "Hide All Processes"}}, {font,Font}, {underline,1}]), gse:named_menuitem('Hide Modules', MenuView, [{label, {text, "Hide Modules..."}}, {font,Font}, {underline,8}]), gse:named_menuitem('Hide Selected Process', MenuView, [{label, {text, "Hide Selected Process"}}, {font,Font}, {underline,2}]), gse:named_menuitem('Module',MenuView, [{label, {text, "Module Info..."}}, {font,Font}, {underline,7}]), gse:named_menuitem('Refresh', MenuView, [{label, {text, "Refresh"}}, {font,Font}, {underline,0}]), gse:named_menuitem('Show All',MenuView, [{label, {text, "Show All Processes"}}, {font,Font}]), gse:named_menuitem('Show Selected',MenuView, [{label, {text, "Show Processes..."}}, {font,Font}]), %% Trace menu gs:create(menuitem, 'Kill', MenuTrace, [{label,{text, "Kill"}}, {font,Font}, {underline,0}]), gs:create(menuitem, 'Trace Process', MenuTrace, [{label, {text, "Trace Selected Process"}}, {font,Font}, {underline,0}]), gs:create(menuitem,'Trace Shell', MenuTrace, [{label, {text,"Shell Process"}}, {font,Font}, {underline,0}]), %% Help menu gs:create(menuitem,'Help', MenuHelp, [{label, {text, "Help" }}, {font,Font}, {underline,0}]), %% Window contents %% Geometry managing frame Frame = gse:frame(Win, [{y,?MENU_HEIGHT}, {packer_x,[{stretch, 1}]}, {packer_y,[{stretch,10}, {fixed,?CHECKBAR_HEIGHT}]}]), %% Grid Grid_Options = [ {pack_x,1}, {pack_y,1}, {fg,black}, {vscroll,right},{hscroll,bottom}, calc_columnwidths(739), {rows, {1,Size}}], Grid = gse:grid(Frame,Grid_Options), %% Checkbutton bar at the bottom of the window CheckBar = gse:frame(Frame, [{pack_x,1}, {pack_y,2}, {packer_x,[{stretch, 2, 100,300}, {stretch, 2, 100,300}, {stretch,1}, {stretch, 2,100,300}]}, {packer_y,[{stretch,1}]}]), gse:named_checkbutton('Hide System',CheckBar, [{pack_xy,{1,1}}, {justify, left}, {align,w}, {width, 200}, {font, Font}, {label, {text, "Hide System Processes" }}]), gse:named_checkbutton('Auto Hide New',CheckBar, [{pack_xy,{2,1}}, {width, 200}, {justify, left}, {align,w}, {font, Font}, {label, {text, "Auto-Hide New" }}]), gse:named_label('Number Hidden',CheckBar, [{pack_xy,{4,1}}, {justify, left}, {align,w}, {width, 200}, {font, Font}, {label, {text, ?CPIDHIDDENTEXT }}]), %% Finalize it! gse:map(Win), gse:config(Win,[raise]), gse:config(Win,[{configure,true}]), {Win, Grid, Frame, length(processes())+1, ?WIN_WIDTH, ?WIN_HEIGHT}.%% Calculate columnwidths in respect to the size of the window.calc_columnwidths(Width) -> if Width =< 739 -> {columnwidths,[75,215,146,90,105,105]}; true -> S = (Width - 75)/(215+146+90+105+105), {columnwidths,[75,round(215*S),round(146*S),round(90*S), round(105*S),round(105*S)]} end.%% ---------------------------------------------------------------%% Create a trace window%%%% Process, a process id or an atom%%%% Return: A window and a editor%% ---------------------------------------------------------------window(Process) -> GS = gs:start([{kernel,true}]), Font = font(GS), Win_Options = [{title,title(Process)}, {width,550}, {keypress,true}, {configure,true}, {destroy,true},{height, 400}], Win = gs:create(window,GS,Win_Options), MenuBar = gs:create(menubar, Win, []), %% File menu MBFile = gs:create(menubutton,MenuBar,[{label,{text," File "}}, {font,Font}, {underline, 1}]), MenuFile = gs:create(menu, MBFile, []), make_menus(pman_process:is_running(Process), MenuBar, MenuFile, Font), gse:named_menuitem('Save buffer',MenuFile, [{label,{text, "Save buffer..."}}, {font,Font}, {underline,0}]), gse:named_menuitem('Close',MenuFile, [{label, {text, "Close"}}, {font,Font}, {underline,0}]), Editor = gs:create(editor,Win,[{x,3}, {y,40}, {width,546}, {height,348}, {font,Font}]), gs:config(Editor, [{keypress, true},{insert, {'end', display(Process)}}]), gs:config(Editor, [{enable, false},{vscroll, right}, {hscroll, bottom}, {wrap,none}]), gs:config(Win, [{map, true}]), {Win, Editor}.%% ---------------------------------------------------------------------%% Menu Help Fuctions%% ---------------------------------------------------------------------links_menus(Links) -> gs:destroy('Links'), gs:create(menu,'Links','LinksMenu',[]), Flag = case links_menus(Links,[]) of [] -> false; Pids -> add_menu('Links', Pids, "Trace"), true end, gse:config('LinksMenu',[{enable,Flag}]). links_menus([],Pids) -> Pids;links_menus([Pid|Links],Pids) when is_pid(Pid) -> links_menus(Links,[Pid|Pids]);links_menus([_Port|Links],Pids) -> links_menus(Links,Pids).%% Create the node menu. add_node_menu(MenuBar, Nodes, Font) -> MBNode = gs:create(menubutton, MenuBar, [{label,{text, " Nodes "}}, {font,Font}, {underline, 1}]), gs:create(menu, node, MBNode, []), add_menu(node, Nodes, "Show", Font), gse:disable(node()).%% ---------------------------------------------------------------------%% Add Menus in the list under Menu menuitem.add_menu(Menu, Names, Tag) -> add_menu(Menu, Names, Tag, font()).add_menu(_Menu, [], _Tag, _Font) -> ok;add_menu(Menu, [Name|Names], Tag, Font) -> Title = io_lib:format("~s ~p",[Tag, Name]), gs:create(menuitem,Name,Menu,[{label,{text,Title}}, {font,Font}, {data,{Menu,Name}}]), add_menu(Menu, Names, Tag, Font).%% ---------------------------------------------------------------------%% Remove a specific menu item, or a whole menu, or a list of both.%%remove_menu(List) when is_list(List)-> lists:foreach(fun(X) -> gs:destroy(X) end, List);remove_menu(Object) -> gse:destroy(Object).%% ---------------------------------------------------------------------%% If the trace window opened is supposed to trace a real pid, let us%% add the trace menu, and other items specific to tracing. If not,%% the only menus available are the ones in the default defined in%% window(Pid).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?