在MATLAB中显示自定义帮助文档 [英] Displaying custom help documentation in MATLAB

查看:127
本文介绍了在MATLAB中显示自定义帮助文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照以下说明创建和显示自定义帮助文档:

I am following these instructions to create and display custom help documentation: http://www.mathworks.co.uk/help/matlab/matlab_prog/display-custom-documentation.html. I am making this help for a GUI I have written with GUIDE and was wondering if it was possible to go directly to the 'supplemental software' page, described in step 5, from my GUI. I plan to make this program into a standalone app. If there are other, better ways to create help documentation for a standalone app I would be happy to hear them too.

推荐答案

不一定要在MatLab文档中嵌入自定义帮助文档.

It is not strictly necessary to embed the Custom help documentation in the MatLab documentation.

您可以通过在figure menu bar中添加专用的menu来构建自己的文档帮助.

You can build your own documentation help by adding a dedicated menu in the figure menu bar.

实际上,您可以通过添加个人物品来对标准menu bar进行定制化处理,也可以定义自己的menu bar并将其添加到您的GUI中,以代替标准MatLab.

Actually you can either costomize the standard menu bar by adding your personal items or define your own menu bar and add it to your GUI in place of the standard MatLab one.

此外,您还可以将context menu添加到GUI中的任何uicontrol(由uicontrol上的right clicking激活的menu).

Moreover you can also add context menu to any uicontrol in your GUI (menu that are activated by right clicking on the uicontrol).

Bot menucontextmenu可以访问用几种format编写的文档(HTML,PDF,TXT等).

Bot menu and contextmenu can get access to the documentation written in in several format (HTML, PDF, TXT, ...).

您可以通过GUIDEby code

  • GUIDE上,可以选择GUIDE工具栏上的Menu Editor工具.它允许同时创建menucontext menu.
  • On GUIDE you can select the Menu Editor tool on the GUIDE toolbar. It allows creating both menu and context menu.

通过将GUI窗口的Mneu bar属性设置为figure,您的客户menuadded设置为figure menu bar

By setting the Mneu bar property of the GUI window to figure your custon menu wil be added to the figure menu bar

通过将GUI窗口的Mneu bar属性设置为none,您的客户menu将成为figure menu bar

By setting the Mneu bar property of the GUI window to none your custon menu wil be the only one displayed on the figure menu bar

  • by code分别使用uimenuuicontextmenu内置函数创建menucontext menu.
  • by code you create both menu and context menu by using, respectively, the uimenu and uicontextmenu built-in functions.

您已经创建了menu和/或context menu的对象,可以在其callback中为每个menu item指定要打开的文档:

Ones you've created your menu and / or context menu you can specify the document to be opened to each menu item in its callback:

  • 要打开HTML文档,您可以使用web函数,它允许使用默认的MatLab浏览器或自定义"浏览器打开文档
  • to open HTML documentation you can use the web function, it allows to open the documentation using either the default MatLab browser or a Custom browser

web('my_doc.html') % Open doc with MatLab default browser, if the doc folder is not in the MatLab Path, add the full path

web('my_doc.html','-browser') % Open doc with custom browser, if the doc folder is not in the MatLab Path, add the full path

  • 要打开PDF文档,可以使用open功能
  • to open PDF documentation you can use the open function

open('example.pdf')

  • 要打开TXT文档,您可以使用winopen功能
  • to open TXT documentation you can use the winopen function

(winopen('release_notes.txt')

我构建了一个简单的GUI来显示menucontext menu的实现:它由menu barpushbuttonaxes组成.

I've built a simple GUI to show the implementaion of menu and context menu: it consists of a menu bar, a pushbutton and an axes.

manu bar仅包含用户定义的项目(Menu bar属性已改为none),但是,custon菜单中的in项也可以显示标准的MatLab菜单栏

The manu bar contains only the item defined by the user (the Menu bar property bas been ste to none), nevertheless, an in item in the custon menu allows displaying also the standard MatLab menu bar

pushbutton允许在axes中绘制由peaks函数生成的表面(只是对其进行贴合);更重要的是,具有两个项目的context menu已添加到pushbutton.用户可以通过pushbutton

The pushbutton allows to plot in the axes the surface generated by the peaks function (just to have it doing somenting); more important, a context menu with two items has been added to the pushbutton. The user can access to the pushbutton documentation by right clicking on the pushbutton

我还编写了一个标准的MatLab .m脚本,该脚本创建具有相同功能的相同GUI,以显示如何使用uimenuuicontextmanu函数创建menucontext manu.

Also I've wrote a standard MatLab .m script which create the same GUI with the same functionalities to show how to create menu and context manu by using uimenu and uicontextmanu functions.

在下面,您可以找到源代码和显示GUI的图片.

In the following you can find both the source codes and a picture showing the GUI.

    function varargout = custom_menu_gui(varargin)
% CUSTOM_MENU_GUI MATLAB code for custom_menu_gui.fig
%      CUSTOM_MENU_GUI, by itself, creates a new CUSTOM_MENU_GUI or raises the existing
%      singleton*.
%
%      H = CUSTOM_MENU_GUI returns the handle to a new CUSTOM_MENU_GUI or the handle to
%      the existing singleton*.
%
%      CUSTOM_MENU_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CUSTOM_MENU_GUI.M with the given input arguments.
%
%      CUSTOM_MENU_GUI('Property','Value',...) creates a new CUSTOM_MENU_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before custom_menu_gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to custom_menu_gui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help custom_menu_gui

% Last Modified by GUIDE v2.5 19-Aug-2015 17:40:05

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @custom_menu_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @custom_menu_gui_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before custom_menu_gui is made visible.
function custom_menu_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to custom_menu_gui (see VARARGIN)

% Choose default command line output for custom_menu_gui
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes custom_menu_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = custom_menu_gui_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


%
% Callback for: 
%    Custom DOC -> Getting Started (HTML) -> Open with browser
% --------------------------------------------------------------------
function open_with_browser_Callback(hObject, eventdata, handles)
% hObject    handle to open_with_browser (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

web('my_doc.html','-browser')

%
% Callback for: 
%    Custom DOC -> Getting Started (HTML) -> Open with MatLab browser
% --------------------------------------------------------------------
function open_with_matlab_browser_Callback(hObject, eventdata, handles)
% hObject    handle to open_with_matlab_browser (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

web('my_doc.html')

%
% Callback for: 
%    Custom DOC -> Reference Manual (PDF)
% --------------------------------------------------------------------
function reference_manual_pdf_Callback(hObject, eventdata, handles)
% hObject    handle to reference_manual_pdf (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open('example.pdf')


%
% Callback for: 
%    Custom DOC -> Release Notes (TXT)
% --------------------------------------------------------------------
function release_notes_txt_Callback(hObject, eventdata, handles)
% hObject    handle to release_notes_txt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

winopen('release_notes.txt')

%
% Callback for: 
%    Custom DOC -> Show Standard Menu
% --------------------------------------------------------------------
function show_standard_menu_Callback(hObject, eventdata, handles)
% hObject    handle to show_standard_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if(strcmp(get(gcf,'menubar'),'figure'))
   set(gcf,'menubar','none')
   set(hObject,'checked','off')
else
   set(gcf,'menubar','figure')
   set(hObject,'checked','on')
end

%
% Pushbutton callback, just to make it doing somenting
% 
% --- Executes on button press in plot_button.
function plot_button_Callback(hObject, eventdata, handles)
% hObject    handle to plot_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
peaks


%
% Callback for pushbuton ContextMenu "Open Doc (HTML) 
%
% --------------------------------------------------------------------
function open_plot_button_doc_html_Callback(hObject, eventdata, handles)
% hObject    handle to open_plot_button_doc_pdf (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

web('my_doc.html','-browser')

%
% Callback for pushbuton ContextMenu "Open Doc (PDF) 
%
% --------------------------------------------------------------------
function open_plot_button_doc_pdf_Callback(hObject, eventdata, handles)
% hObject    handle to open_plot_button_doc_pdf (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

open('example.pdf')

.m脚本

% Create the Main Window
the_fig=figure('unit','normalized','menubar','none', ...
   'color',[0.9412    0.9412    0.9412],'position',[0.4    0.5    0.5    0.3]);
% Create the Axes
the_ax=axes('position',[0.07    0.1    0.5    0.7500],'unit','normalized');
% Create the Pushbutton uicontrol
the_pb=uicontrol('style','pushbutton','unit','normalized', ...
   'position',[.7 .7 .2 .2], 'string','Plot', ...
   'tooltipstring','Right Click for Menu','callback','peaks;');
% Create the Main Custom Menu
the_menu=uimenu(the_fig,'label','Custom DOC');
% Create the first sub-menu
the_sub_menu=uimenu(the_menu,'label','Getting Started (HTML)');
% Create the 2 menu items belongoing to the sub-menu
the_sub_menu_1=uimenu(the_sub_menu,'label','Open with browser', ...
   'callback',['web(''my_doc.html'',''-browser'')']);
the_sub_menu_2=uimenu(the_sub_menu,'label','Open with MatLab browser', ...
   'callback',['web(''my_doc.html'')']);
% Creater 3 su-menu belonging to the main menu
the_sub_menu_3=uimenu(the_menu,'label','Reference manual (PDF)', ...
   'callback',['open(''example.pdf'')']);
the_sub_menu_4=uimenu(the_menu,'label','Release notes (TXT)', ...
   'callback',['winopen(''release_notes.txt'')']);
the_sub_menu_5=uimenu(the_menu,'label','Show Standard Menu', ...
   'callback','show_std_menu');
% Create the uicontext menu of the pushbutton
the_context_menu=uicontextmenu;
% Create the menu items of the uicontext menu
uimenu(the_context_menu,'label','Open ODC (HTML)', ...
   'callback',['web(''my_doc.html'',''-browser'')'])
uimenu(the_context_menu,'label','Open ODC (PDF)', ...
   'callback',['open(''example.pdf'')'])
% Assign the uicontextmenu to the pushbutton
set(the_pb,'uicontextmenu',the_context_menu);

the_sub_menu_5 callback

show_std_menu.m script for the_sub_menu_5 callback

% If the Figure menubar is on
if(strcmp(get(gcf,'menubar'),'figure'))
   % Remove it
   set(gcf,'menubar','none')
   % Un-check the menu item
   set(the_sub_menu_5,'checked','off')
% If the Figure menubar is off
else
   % Show it
   set(gcf,'menubar','figure')
   % Check the menu item
   set(the_sub_menu_5,'checked','on')
end

GUI

希望这会有所帮助.

这篇关于在MATLAB中显示自定义帮助文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆