From 177e28e47a2745529a09afcfe0494d290079cdfe Mon Sep 17 00:00:00 2001 From: Henry Luetcke <hluetcke@ethz.ch> Date: Thu, 21 Mar 2019 15:53:09 +0100 Subject: [PATCH] bug fixes and documentation --- OpenBis.m | 373 ++++++++--- html/OpenBis.html | 1155 ++++++++++++++++++++++++++++++++ html/df_to_table.html | 92 +++ html/passwordEntryDialog.html | 826 +++++++++++++++++++++++ html/user_url_pw_inputdlg.html | 102 +++ pybis_example.ipynb | 23 +- user_url_pw_inputdlg.m | 2 + 7 files changed, 2463 insertions(+), 110 deletions(-) create mode 100644 html/OpenBis.html create mode 100644 html/df_to_table.html create mode 100644 html/passwordEntryDialog.html create mode 100644 html/user_url_pw_inputdlg.html diff --git a/OpenBis.m b/OpenBis.m index 8f0b6f7e688..7043a1e7c36 100644 --- a/OpenBis.m +++ b/OpenBis.m @@ -28,10 +28,13 @@ classdef OpenBis function obj = OpenBis(varargin) % OpenBis Constructor method for class OpenBis % Creates the Python Openbis object and logs into the server - % Optional input arguments: + % Optional positional input arguments: % url ... URL of the openBIS server (incl. port) % user ... user name for openBIS % pw ... password for openBIS + % Usage: + % obi = OpenBis() --> opens UI to enter URL, user name and password + % obi = OpenBis('server_url', 'user_name', 'user_password') if nargin > 0 url = varargin{1}; @@ -47,57 +50,99 @@ classdef OpenBis end function logout(obj) - % logout Log out of openBIS. + %logout + % Log out of openBIS. + % Usage: + % obi.logout() + % % After logout, the session token is no longer valid. + obj.pybis.logout(); end function tf= is_session_active(obj) - % isvalid Check if the session token is still active. Returns true or false. + %is_session_active + % Check if the session token is still active. Returns true or false. + % Usage: + % true_false = obi.is_session_active() + tf = obj.pybis.is_session_active(); end + function token = token(obj) + %token + % Returns the current session token. + % Usage: + % token = obi.token() + + token = char(obj.pybis.token); + end + %% Masterdata methods % this section defines Matlab equivalents of the following pyBIS methods: - % get_experiment_types - % get_sample_types - % get_material_types - % get_dataset_types - % get_terms - % get_tags + % get_experiment_types + % get_sample_types + % get_material_types + % get_dataset_types + % get_terms + % get_tags function experiment_types = get_experiment_types(obj) - % Return table of all available experiment types. + %get_experiment_types + % Return a table of all available experiment types. + % Usage: + % experiment_types = obi.get_experiment_types() + experiment_types = obj.pybis.get_experiment_types(); experiment_types = df_to_table(experiment_types.df); end function sample_types = get_sample_types(obj) + %get_sample_types % Return table of all available sample types. + % Usage: + % sample_types = obi.get_sample_types() + sample_types = obj.pybis.get_sample_types(); sample_types = df_to_table(sample_types.df); end function material_types = get_material_types(obj) + %get_material_types % Return table of all available material types. + % Usage: + % material_types = obi.get_material_types() + material_types = obj.pybis.get_material_types(); material_types = df_to_table(material_types.df); end function dataset_types = get_dataset_types(obj) + %get_dataset_types % Return table of all available dataset types. + % Usage: + % dataset_types = obi.get_dataset_types() + dataset_types = obj.pybis.get_dataset_types(); dataset_types = df_to_table(dataset_types.df); end function terms = get_terms(obj) + %get_terms % Return table of all available terms. + % Usage: + % terms = obi.get_terms() + terms = obj.pybis.get_terms(); terms = df_to_table(terms.df); end function tags = get_tags(obj) + %get_tags % Return table of all available tags. + % Usage: + % tags = obi.get_tags() + tags = obj.pybis.get_tags(); tags = df_to_table(tags.df); end @@ -105,39 +150,56 @@ classdef OpenBis %% Space methods % this section defines Matlab equivalents of the following pyBIS methods: - % get_spaces - % get_space - % new_space - % space.delete + % get_spaces + % get_space + % new_space + % space.delete function spaces = get_spaces(obj) + %get_spaces % Return table of all available spaces. + % Usage: + % spaces = obi.get_spaces() + spaces = obj.pybis.get_spaces(); spaces = df_to_table(spaces.df); end function space = get_space(obj, code) - % Get space with code and return the space object - % Input arguments + %get_space + % Fetch space with matching space code and return the space object. + % An error is raised if a space with the code is not found on the server. + % Required input arguments: % code ... space code + % Usage: + % space = obi.get_space('code') + space = obj.pybis.get_space(code); end function space = new_space(obj, code, description) + %new_space % Create a new space with code and description and return the space object - % Input arguments + % Required input arguments: % code ... Space code % description ... Space description + % Usage: + % space = obi.new_space('code', 'description') + space = obj.pybis.new_space(pyargs('code', code, ... 'description', description)); space.save; end function delete_space(obj, code, reason) + %delete_space % Delete space with code and provide a reason for deletion - % Input arguments + % Required input arguments: % code ... Space code % reason ... reason for deletion + % Usage: + % obi.delete_space('code', 'reason') + space = obj.pybis.get_space(code); space.delete(reason); end @@ -145,145 +207,217 @@ classdef OpenBis %% Project methods % this section defines Matlab equivalents of the following pyBIS methods: - % get_projects - % get_project - % new_project + % get_projects + % get_project + % new_project + % project.delete function projects = get_projects(obj, space, code) + %get_projects % Return table of matching projects. % Input arguments: % space ... space to fetch projects from % project ... fetch projects matching code + % Usage: + % projects = obi.get_projects('space', 'code') + projects = obj.pybis.get_projects(pyargs('space', space, 'code', code)); projects = df_to_table(projects.df); end function project = get_project(obj, id) - % Return matching project. - % Input arguments: - % id ... project permID + %get_project + % Fetch project with matching project id and return the project object. + % An error is raised if a project with the id is not found on the server. + % Required input arguments: + % id ... project id + % Usage: + % project = obi.get_project('id') + project = obj.pybis.get_project(id); end - function project_cell = get_project_by_code(obj, space, code) - % Return matching project. - % Input arguments: - % space ... space code - % code ... project code - projects = obj.get_projects(space, code); - project_ids = projects.permId; - project_cell = cell(1, numel(project_ids)); - for ix = 1:numel(project_ids) - project_cell{ix} = obj.get_project(project_ids{ix}); - end - end - function project = new_project(obj, space, code, description) + %new_project % Create a new project in space with code and description % Return the project object % Input arguments % space ... Space code - % code ... Project code + % code ... Project code / id % description ... Project description + % Usage: + % project = obi.new_project('space', 'code', 'description') + space = obj.pybis.get_space(space); project = space.new_project(pyargs('code', code, 'description', description)); project.save(); end + function delete_project(obj, code, reason) + %delete_project + % Delete project with code and provide a reason for deletion + % Required input arguments: + % code ... Project code + % reason ... reason for deletion + % Usage: + % obi.delete_project('code', 'reason') + + project = obj.pybis.get_project(code); + project.delete(reason); + end - %% Object methods - % this section defines following Matlab methods related to openBIS objects / samples: - % get_object - % get_objects - % new_object - % delete_object - function object = get_object(obj, id) - % Return object (sample) corresponding to the id - % ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234) - object = obj.pybis.get_object(id); - end + %% Experiment methods + % this section defines the following Matlab methods: + % get_experiments + % get_experiment + % new_experiment - function objects = get_objects(obj, varargin) - defaultSpace = ''; - defaultType = ''; - defaultTag = ''; % currently only 1 tag can be specified + function experiments = get_experiments(obj, varargin) + %get_experiments + % Return table of matching experiments. + % Optional input arguments: + % space ... space to fetch experiments from + % type ... fetch experiments of specific type + % project ... project to fetch experiments from + % Usage: + % experiments = obi.get_experiments() + % experiments = obi.get_experiments('space', 'SPACE') + % experiments = obi.get_experiments('space', 'SPACE', 'type', 'UNKNOWN') + + space = ''; + type = ''; + project = ''; p = inputParser; addRequired(p, 'obj'); - addParameter(p, 'space', defaultSpace, @ischar); - addParameter(p, 'type', defaultType, @ischar); - addParameter(p, 'tag', defaultTag); + addParameter(p, 'space', space, @ischar); + addParameter(p, 'type', type, @ischar); + addParameter(p, 'project', project, @ischar); parse(p, obj, varargin{:}); a = p.Results; - objects = obj.pybis.get_objects(pyargs('space', a.space, 'type', a.type, 'tag', a.tag)); - objects = df_to_table(objects.df); - end - - function object = new_object(obj, type, space, code) - % Create a new object (sample) of specific type in a space - % Return the object - object = obj.pybis.new_object(pyargs('type', type, 'space', space, 'code', code)); - object.save(); + experiments = obj.pybis.get_experiments(pyargs('space', a.space, 'type', a.type, 'project', a.project)); + experiments = df_to_table(experiments.df); end - function object = delete_object(obj, object, reason) - % Delete object (sample) specifying a reason + function experiment = get_experiment(obj, id) + %get_experiment + % Return experiment with identifier % ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234) - object.delete(reason) + % Usage: + % exp = obi.get_experiment('/SPACE/PROJECT/EXP') + % exp = obi.get_experiment('permID') + + experiment = obj.pybis.get_experiment(id); end + function experiment = new_experiment(obj, type, code, project) + %new_experiment + % Create a new experiment of specific type in a defined project + % Required input arguments: + % type ... new experiment type + % code ... new experiment code + % project ... project for new experiment ('SPACE/Project') + % Usage: + % experiment = obi.new_experiment('type', 'space', 'Space/Project') + + experiment = obj.pybis.new_experiment(pyargs('type', type, 'code', code, 'project', project)); + experiment.save(); + end - %% Experiment methods - % this section defines the following Matlab methods: - % get_experiment - % get_experiments - function experiment = get_experiment(obj, id) - % Return experiment corresponding to the id - % ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234) - experiment = obj.pybis.get_experiment(id); - end + %% Object methods + % this section defines following Matlab methods related to openBIS objects / samples: + % get_object + % get_objects + % new_object + % delete_object - function experiments = get_experiments(obj, varargin) - space = ''; - type = ''; - project = ''; + function objects = get_objects(obj, varargin) + %get_objects + % Return a table of objects matching specified criteria + % Optional keyword arguments: + % id ... object identifier ('SPACE/PROJECT/') + % Usage: + % objects = obi.get_objects() + % objects = obi.get_objects('id', 'SPACE/') + + defaultId = ''; p = inputParser; addRequired(p, 'obj'); - addParameter(p, 'space', space, @ischar); - addParameter(p, 'type', type, @ischar); - addParameter(p, 'project', project, @ischar); + addParameter(p, 'id', defaultId, @ischar); parse(p, obj, varargin{:}); a = p.Results; + + objects = obj.pybis.get_objects(a.id); + objects = df_to_table(objects.df); + end + + function object = get_object(obj, id) + %get_object + % Return object (sample) corresponding to the id + % ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234) + % An error is raised if an object with the id is not found on the server. + % Required input arguments: + % id ... object id + % Usage: + % object = obi.get_object('id') - experiments = obj.pybis.get_experiments(pyargs('space', a.space, 'type', a.type, 'project', a.project)); - experiments = df_to_table(experiments.df); + object = obj.pybis.get_object(id); end - function experiment = new_experiment(obj, type, space, project) - % Create a new experiment of specific type in a defined space and project + function object = new_object(obj, type, space, code) + %new_object + % Create a new object of type in space with code % Return the object - experiment = obj.pybis.new_experiment(pyargs('type', type, 'space', space, 'project', project)); - experiment.save(); + % Input arguments + % type ... object type + % space ... Space code + % code ... object code + % Usage: + % object = obi.new_object('type', 'space', 'code') + object = obj.pybis.new_object(pyargs('type', type, 'space', space, 'code', code)); + object.save(); + end + + function object = delete_object(obj, object, reason) + %delete_object + % Delete object and provide a reason for deletion + % Required input arguments: + % object ... object returned by get_object / new_object methods + % reason ... reason for deletion + % Usage: + % obi.delete_object(object, 'reason') + + object.delete(reason) end + %% Dataset methods % this section defines following Matlab methods: - % get_datasets - % get_dataset - % get_dataset_files - % dataset_download - % new_dataset - % new_dataset_container + % get_datasets + % get_dataset + % get_dataset_files + % dataset_download + % new_dataset + % new_dataset_container function datasets = get_datasets(obj, varargin) + %get_datasets % Return table of matching datasets. % Optional input arguments: - % code, type, experiment, project, tags + % code ... dataset code / permId + % type ... dataset type + % experiment ... datasets in experiment + % project ... datasets in project + % tags ... datasets with tags + % Usage: + % datasets = obi.get_datasets() + % datasets = obi.get_datasets('type', 'RAW_DATA') + % datasets = obi.get_datasets('experiment', '/SPACE/PROJECT/EXPERIMENT') defaultCode = ''; defaultType = ''; @@ -307,6 +441,12 @@ classdef OpenBis end function dataset = get_dataset(obj, permid, varargin) + %get_dataset + % Get dataset with permId. An error is raised if a dataset with the id is not found on the server. + % Input arguments: + % permId ... dataset permId + % Usage: + % dataset = obi.get_dataset('permId') only_data = false; @@ -319,11 +459,17 @@ classdef OpenBis % dataset = obj.pybis.get_dataset(pyargs('permid', a.permid, 'only_data', a.only_data)); dataset = obj.pybis.get_dataset(a.permid); - end function files = get_dataset_files(obj, dataset, varargin) + %get_dataset_files + % Get list of files in a dataset starting with start_folder. + % Input arguments: + % dataset ... dataset object returned by get_dataset + % start_folder ... starting folder for files (default: '/') + % Usage: + % files = obi.get_dataset_files(dataset) start_folder = '/'; @@ -335,13 +481,19 @@ classdef OpenBis a = p.Results; files = dataset.get_files(pyargs('start_folder', a.start_folder)); - files = df_to_table(files); - end function path_to_file = dataset_download(obj, dataset, files, varargin) - % provide files as cell array of files + %dataset_download + % Download files in a dataset + % dataset ... dataset object returned by get_dataset + % files ... cell array of files + % destination ... folder to download to (default: data) + % wait_until_finished ... wait or download in the background (default: true) + % workers ... number of workers to use for download (default: 10) + % Usage: + % path_to_files = obi.dataset_download(dataset, {'file1', 'file2'}) destination = 'data'; wait_until_finished = true; @@ -365,8 +517,14 @@ classdef OpenBis end function dataset = new_dataset(obj, type, experiment, object, file_list) - % Create a new dataset - % Return the dataset + %new_dataset + % Create a new dataset with files + % type ... dataset type + % experiment ... experiment for dataset + % object ... object for dataset + % file_list ... list of files (cell string) to upload to new dataset + % Usage: + % dataset = obi.new_dataset('type', 'RAW_DATA', 'experiment', 'MY_EXP', 'object', 'MY_SAMPLE', 'file_list', {'file1', 'file2'}) p = inputParser; addRequired(p, 'obj'); @@ -384,8 +542,13 @@ classdef OpenBis end function dataset = new_dataset_container(obj, type, experiment, object) - % Create a new dataset container - % Return the dataset container + %new_dataset_container + % Create a new dataset container + % type ... dataset container type + % experiment ... experiment for dataset container + % object ... object for dataset container + % Usage: + % dataset = obi.new_dataset_container('type', 'RAW_DATA', 'experiment', 'MY_EXP', 'object', 'MY_SAMPLE') p = inputParser; addRequired(p, 'obj'); diff --git a/html/OpenBis.html b/html/OpenBis.html new file mode 100644 index 00000000000..29a410ec83d --- /dev/null +++ b/html/OpenBis.html @@ -0,0 +1,1155 @@ + +<!DOCTYPE html + PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <!-- +This HTML was auto-generated from MATLAB code. +To make changes, update the MATLAB code and republish this document. + --><title>OpenBis</title><meta name="generator" content="MATLAB 9.4"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2019-03-21"><meta name="DC.source" content="OpenBis.m"><style type="text/css"> +html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0} + +html { min-height:100%; margin-bottom:1px; } +html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; } +html body td { vertical-align:top; text-align:left; } + +h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; } +h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; } +h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; } + +a { color:#005fce; text-decoration:none; } +a:hover { color:#005fce; text-decoration:underline; } +a:visited { color:#004aa0; text-decoration:none; } + +p { padding:0px; margin:0px 0px 20px; } +img { padding:0px; margin:0px 0px 20px; border:none; } +p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; } + +ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; } +ul li { padding:0px; margin:0px 0px 7px 0px; } +ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; } +ul li ol li { list-style:decimal; } +ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; } +ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; } +ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; } +ol li ol li { list-style-type:lower-alpha; } +ol li ul { padding-top:7px; } +ol li ul li { list-style:square; } + +.content { font-size:1.2em; line-height:140%; padding: 20px; } + +pre, code { font-size:12px; } +tt { font-size: 1.2em; } +pre { margin:0px 0px 20px; } +pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; } +pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; } +pre.error { color:red; } + +@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } } + +span.keyword { color:#0000FF } +span.comment { color:#228B22 } +span.string { color:#A020F0 } +span.untermstring { color:#B20000 } +span.syscmd { color:#B28C00 } + +.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; } +.footer p { margin:0px; } +.footer a { color:#878787; } +.footer a:hover { color:#878787; text-decoration:underline; } +.footer a:visited { color:#878787; } + +table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; } +table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; } + + + + + + </style></head><body><div class="content"><h2>Contents</h2><div><ul><li><a href="#2">Constructor method</a></li><li><a href="#3">Masterdata methods</a></li><li><a href="#4">Space methods</a></li><li><a href="#5">Project methods</a></li><li><a href="#6">Experiment methods</a></li><li><a href="#7">Object methods</a></li><li><a href="#8">Dataset methods</a></li></ul></div><pre class="codeinput"><span class="keyword">classdef</span> OpenBis + <span class="comment">% OpenBis High-level class for interacting with Python (pyBIS) Openbis objects</span> + <span class="comment">% This class creates a MATLAB OpenBis object that encapsulates the Python (pyBIS) Openbis object</span> + <span class="comment">% and provides methods for interacting with the Python (pyBIS) Openbis object.</span> + <span class="comment">%</span> + <span class="comment">% Usage:</span> + <span class="comment">% Construct the MATLAB OpenBis object like this:</span> + <span class="comment">% obi = OpenBis()</span> + <span class="comment">% This will ask for URL, user name and password to connect to openBIS server.</span> + <span class="comment">% These can also be provided as optional input arguments.</span> + <span class="comment">%</span> + <span class="comment">% Methods are generally called like this:</span> + <span class="comment">% spaces = obi.get_spaces()</span> + <span class="comment">% space = obi.get_space(code)</span> + <span class="comment">%</span> + <span class="comment">% Logout:</span> + <span class="comment">% obi.logout()</span> + + + <span class="keyword">properties</span> + pybis <span class="comment">% Python Openbis object</span> + <span class="keyword">end</span> + + + <span class="keyword">methods</span> +</pre><h2 id="2">Constructor method</h2><pre class="codeinput"> <span class="keyword">function</span> obj = OpenBis(varargin) + <span class="comment">% OpenBis Constructor method for class OpenBis</span> + <span class="comment">% Creates the Python Openbis object and logs into the server</span> + <span class="comment">% Optional positional input arguments:</span> + <span class="comment">% url ... URL of the openBIS server (incl. port)</span> + <span class="comment">% user ... user name for openBIS</span> + <span class="comment">% pw ... password for openBIS</span> + <span class="comment">% Usage:</span> + <span class="comment">% obi = OpenBis() --> opens UI to enter URL, user name and password</span> + <span class="comment">% obi = OpenBis('server_url', 'user_name', 'user_password')</span> + + <span class="keyword">if</span> nargin > 0 + url = varargin{1}; + user = varargin{2}; + pw = varargin{3}; + <span class="keyword">else</span> + [url, user, pw] = user_url_pw_inputdlg; + <span class="keyword">end</span> + + o = py.pybis.Openbis(url, pyargs(<span class="string">'verify_certificates'</span>, 0)); + o.login(user, pw, pyargs(<span class="string">'save_token'</span>, 1)); + obj.pybis = o; + <span class="keyword">end</span> + + <span class="keyword">function</span> logout(obj) + <span class="comment">%logout</span> + <span class="comment">% Log out of openBIS.</span> + <span class="comment">% Usage:</span> + <span class="comment">% obi.logout()</span> + <span class="comment">%</span> + <span class="comment">% After logout, the session token is no longer valid.</span> + + obj.pybis.logout(); + <span class="keyword">end</span> + + <span class="keyword">function</span> tf= is_session_active(obj) + <span class="comment">%is_session_active</span> + <span class="comment">% Check if the session token is still active. Returns true or false.</span> + <span class="comment">% Usage:</span> + <span class="comment">% true_false = obi.is_session_active()</span> + + tf = obj.pybis.is_session_active(); + <span class="keyword">end</span> + + <span class="keyword">function</span> token = token(obj) + <span class="comment">%token</span> + <span class="comment">% Returns the current session token.</span> + <span class="comment">% Usage:</span> + <span class="comment">% token = obi.token()</span> + + token = char(obj.pybis.token); + <span class="keyword">end</span> +</pre><h2 id="3">Masterdata methods</h2><p>this section defines Matlab equivalents of the following pyBIS methods: get_experiment_types get_sample_types get_material_types get_dataset_types get_terms get_tags</p><pre class="codeinput"> <span class="keyword">function</span> experiment_types = get_experiment_types(obj) + <span class="comment">%get_experiment_types</span> + <span class="comment">% Return a table of all available experiment types.</span> + <span class="comment">% Usage:</span> + <span class="comment">% experiment_types = obi.get_experiment_types()</span> + + experiment_types = obj.pybis.get_experiment_types(); + experiment_types = df_to_table(experiment_types.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> sample_types = get_sample_types(obj) + <span class="comment">%get_sample_types</span> + <span class="comment">% Return table of all available sample types.</span> + <span class="comment">% Usage:</span> + <span class="comment">% sample_types = obi.get_sample_types()</span> + + sample_types = obj.pybis.get_sample_types(); + sample_types = df_to_table(sample_types.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> material_types = get_material_types(obj) + <span class="comment">%get_material_types</span> + <span class="comment">% Return table of all available material types.</span> + <span class="comment">% Usage:</span> + <span class="comment">% material_types = obi.get_material_types()</span> + + material_types = obj.pybis.get_material_types(); + material_types = df_to_table(material_types.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> dataset_types = get_dataset_types(obj) + <span class="comment">%get_dataset_types</span> + <span class="comment">% Return table of all available dataset types.</span> + <span class="comment">% Usage:</span> + <span class="comment">% dataset_types = obi.get_dataset_types()</span> + + dataset_types = obj.pybis.get_dataset_types(); + dataset_types = df_to_table(dataset_types.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> terms = get_terms(obj) + <span class="comment">%get_terms</span> + <span class="comment">% Return table of all available terms.</span> + <span class="comment">% Usage:</span> + <span class="comment">% terms = obi.get_terms()</span> + + terms = obj.pybis.get_terms(); + terms = df_to_table(terms.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> tags = get_tags(obj) + <span class="comment">%get_tags</span> + <span class="comment">% Return table of all available tags.</span> + <span class="comment">% Usage:</span> + <span class="comment">% tags = obi.get_tags()</span> + + tags = obj.pybis.get_tags(); + tags = df_to_table(tags.df); + <span class="keyword">end</span> +</pre><h2 id="4">Space methods</h2><p>this section defines Matlab equivalents of the following pyBIS methods: get_spaces get_space new_space space.delete</p><pre class="codeinput"> <span class="keyword">function</span> spaces = get_spaces(obj) + <span class="comment">%get_spaces</span> + <span class="comment">% Return table of all available spaces.</span> + <span class="comment">% Usage:</span> + <span class="comment">% spaces = obi.get_spaces()</span> + + spaces = obj.pybis.get_spaces(); + spaces = df_to_table(spaces.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> space = get_space(obj, code) + <span class="comment">%get_space</span> + <span class="comment">% Fetch space with matching space code and return the space object.</span> + <span class="comment">% An error is raised if a space with the code is not found on the server.</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% code ... space code</span> + <span class="comment">% Usage:</span> + <span class="comment">% space = obi.get_space('code')</span> + + space = obj.pybis.get_space(code); + <span class="keyword">end</span> + + <span class="keyword">function</span> space = new_space(obj, code, description) + <span class="comment">%new_space</span> + <span class="comment">% Create a new space with code and description and return the space object</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% code ... Space code</span> + <span class="comment">% description ... Space description</span> + <span class="comment">% Usage:</span> + <span class="comment">% space = obi.new_space('code', 'description')</span> + + space = obj.pybis.new_space(pyargs(<span class="string">'code'</span>, code, <span class="keyword">...</span> + <span class="string">'description'</span>, description)); + space.save; + <span class="keyword">end</span> + + <span class="keyword">function</span> delete_space(obj, code, reason) + <span class="comment">%delete_space</span> + <span class="comment">% Delete space with code and provide a reason for deletion</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% code ... Space code</span> + <span class="comment">% reason ... reason for deletion</span> + <span class="comment">% Usage:</span> + <span class="comment">% obi.delete_space('code', 'reason')</span> + + space = obj.pybis.get_space(code); + space.delete(reason); + <span class="keyword">end</span> +</pre><h2 id="5">Project methods</h2><p>this section defines Matlab equivalents of the following pyBIS methods: get_projects get_project new_project project.delete</p><pre class="codeinput"> <span class="keyword">function</span> projects = get_projects(obj, space, code) + <span class="comment">%get_projects</span> + <span class="comment">% Return table of matching projects.</span> + <span class="comment">% Input arguments:</span> + <span class="comment">% space ... space to fetch projects from</span> + <span class="comment">% project ... fetch projects matching code</span> + <span class="comment">% Usage:</span> + <span class="comment">% projects = obi.get_projects('space', 'code')</span> + + projects = obj.pybis.get_projects(pyargs(<span class="string">'space'</span>, space, <span class="string">'code'</span>, code)); + projects = df_to_table(projects.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> project = get_project(obj, id) + <span class="comment">%get_project</span> + <span class="comment">% Fetch project with matching project id and return the project object.</span> + <span class="comment">% An error is raised if a project with the id is not found on the server.</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% id ... project id</span> + <span class="comment">% Usage:</span> + <span class="comment">% project = obi.get_project('id')</span> + + project = obj.pybis.get_project(id); + <span class="keyword">end</span> + + <span class="keyword">function</span> project = new_project(obj, space, code, description) + <span class="comment">%new_project</span> + <span class="comment">% Create a new project in space with code and description</span> + <span class="comment">% Return the project object</span> + <span class="comment">% Input arguments</span> + <span class="comment">% space ... Space code</span> + <span class="comment">% code ... Project code / id</span> + <span class="comment">% description ... Project description</span> + <span class="comment">% Usage:</span> + <span class="comment">% project = obi.new_project('space', 'code', 'description')</span> + + space = obj.pybis.get_space(space); + project = space.new_project(pyargs(<span class="string">'code'</span>, code, <span class="string">'description'</span>, description)); + project.save(); + <span class="keyword">end</span> + + <span class="keyword">function</span> delete_project(obj, code, reason) + <span class="comment">%delete_project</span> + <span class="comment">% Delete project with code and provide a reason for deletion</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% code ... Project code</span> + <span class="comment">% reason ... reason for deletion</span> + <span class="comment">% Usage:</span> + <span class="comment">% obi.delete_project('code', 'reason')</span> + + project = obj.pybis.get_project(code); + project.delete(reason); + <span class="keyword">end</span> +</pre><h2 id="6">Experiment methods</h2><p>this section defines the following Matlab methods: get_experiments get_experiment new_experiment</p><pre class="codeinput"> <span class="keyword">function</span> experiments = get_experiments(obj, varargin) + <span class="comment">%get_experiments</span> + <span class="comment">% Return table of matching experiments.</span> + <span class="comment">% Optional input arguments:</span> + <span class="comment">% space ... space to fetch experiments from</span> + <span class="comment">% type ... fetch experiments of specific type</span> + <span class="comment">% project ... project to fetch experiments from</span> + <span class="comment">% Usage:</span> + <span class="comment">% experiments = obi.get_experiments()</span> + <span class="comment">% experiments = obi.get_experiments('space', 'SPACE')</span> + <span class="comment">% experiments = obi.get_experiments('space', 'SPACE', 'type', 'UNKNOWN')</span> + + space = <span class="string">''</span>; + type = <span class="string">''</span>; + project = <span class="string">''</span>; + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addParameter(p, <span class="string">'space'</span>, space, @ischar); + addParameter(p, <span class="string">'type'</span>, type, @ischar); + addParameter(p, <span class="string">'project'</span>, project, @ischar); + parse(p, obj, varargin{:}); + a = p.Results; + + experiments = obj.pybis.get_experiments(pyargs(<span class="string">'space'</span>, a.space, <span class="string">'type'</span>, a.type, <span class="string">'project'</span>, a.project)); + experiments = df_to_table(experiments.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> experiment = get_experiment(obj, id) + <span class="comment">%get_experiment</span> + <span class="comment">% Return experiment with identifier</span> + <span class="comment">% ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234)</span> + <span class="comment">% Usage:</span> + <span class="comment">% exp = obi.get_experiment('/SPACE/PROJECT/EXP')</span> + <span class="comment">% exp = obi.get_experiment('permID')</span> + + experiment = obj.pybis.get_experiment(id); + <span class="keyword">end</span> + + <span class="keyword">function</span> experiment = new_experiment(obj, type, code, project) + <span class="comment">%new_experiment</span> + <span class="comment">% Create a new experiment of specific type in a defined project</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% type ... new experiment type</span> + <span class="comment">% code ... new experiment code</span> + <span class="comment">% project ... project for new experiment ('SPACE/Project')</span> + <span class="comment">% Usage:</span> + <span class="comment">% experiment = obi.new_experiment('type', 'space', 'Space/Project')</span> + + experiment = obj.pybis.new_experiment(pyargs(<span class="string">'type'</span>, type, <span class="string">'code'</span>, code, <span class="string">'project'</span>, project)); + experiment.save(); + <span class="keyword">end</span> +</pre><h2 id="7">Object methods</h2><p>this section defines following Matlab methods related to openBIS objects / samples: get_object get_objects new_object delete_object</p><pre class="codeinput"> <span class="keyword">function</span> objects = get_objects(obj, varargin) + <span class="comment">%get_objects</span> + <span class="comment">% Return a table of objects matching specified criteria</span> + <span class="comment">% Optional keyword arguments:</span> + <span class="comment">% id ... object identifier ('SPACE/PROJECT/')</span> + <span class="comment">% Usage:</span> + <span class="comment">% objects = obi.get_objects()</span> + <span class="comment">% objects = obi.get_objects('id', 'SPACE/')</span> + + defaultId = <span class="string">''</span>; + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addParameter(p, <span class="string">'id'</span>, defaultId, @ischar); + parse(p, obj, varargin{:}); + a = p.Results; + + objects = obj.pybis.get_objects(a.id); + objects = df_to_table(objects.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> object = get_object(obj, id) + <span class="comment">%get_object</span> + <span class="comment">% Return object (sample) corresponding to the id</span> + <span class="comment">% ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234)</span> + <span class="comment">% An error is raised if an object with the id is not found on the server.</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% id ... object id</span> + <span class="comment">% Usage:</span> + <span class="comment">% object = obi.get_object('id')</span> + + object = obj.pybis.get_object(id); + <span class="keyword">end</span> + + <span class="keyword">function</span> object = new_object(obj, type, space, code) + <span class="comment">%new_object</span> + <span class="comment">% Create a new object of type in space with code</span> + <span class="comment">% Return the object</span> + <span class="comment">% Input arguments</span> + <span class="comment">% type ... object type</span> + <span class="comment">% space ... Space code</span> + <span class="comment">% code ... object code</span> + <span class="comment">% Usage:</span> + <span class="comment">% object = obi.new_object('type', 'space', 'code')</span> + + object = obj.pybis.new_object(pyargs(<span class="string">'type'</span>, type, <span class="string">'space'</span>, space, <span class="string">'code'</span>, code)); + object.save(); + <span class="keyword">end</span> + + <span class="keyword">function</span> object = delete_object(obj, object, reason) + <span class="comment">%delete_object</span> + <span class="comment">% Delete object and provide a reason for deletion</span> + <span class="comment">% Required input arguments:</span> + <span class="comment">% object ... object returned by get_object / new_object methods</span> + <span class="comment">% reason ... reason for deletion</span> + <span class="comment">% Usage:</span> + <span class="comment">% obi.delete_object(object, 'reason')</span> + + object.delete(reason) + <span class="keyword">end</span> +</pre><h2 id="8">Dataset methods</h2><p>this section defines following Matlab methods: get_datasets get_dataset get_dataset_files dataset_download new_dataset new_dataset_container</p><pre class="codeinput"> <span class="keyword">function</span> datasets = get_datasets(obj, varargin) + <span class="comment">%get_datasets</span> + <span class="comment">% Return table of matching datasets.</span> + <span class="comment">% Optional input arguments:</span> + <span class="comment">% code ... dataset code / permId</span> + <span class="comment">% type ... dataset type</span> + <span class="comment">% experiment ... datasets in experiment</span> + <span class="comment">% project ... datasets in project</span> + <span class="comment">% tags ... datasets with tags</span> + <span class="comment">% Usage:</span> + <span class="comment">% datasets = obi.get_datasets()</span> + <span class="comment">% datasets = obi.get_datasets('type', 'RAW_DATA')</span> + <span class="comment">% datasets = obi.get_datasets('experiment', '/SPACE/PROJECT/EXPERIMENT')</span> + + defaultCode = <span class="string">''</span>; + defaultType = <span class="string">''</span>; + defaultExp = <span class="string">''</span>; + defaultProj = <span class="string">''</span>; + defaultTags = <span class="string">''</span>; + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addParameter(p, <span class="string">'code'</span>, defaultCode, @ischar); + addParameter(p, <span class="string">'type'</span>, defaultType, @ischar); + addParameter(p, <span class="string">'experiment'</span>, defaultExp, @ischar); + addParameter(p, <span class="string">'project'</span>, defaultProj, @ischar); + addParameter(p, <span class="string">'tags'</span>, defaultTags, @ischar); + parse(p, obj, varargin{:}); + a = p.Results; + + datasets = obj.pybis.get_datasets(pyargs(<span class="string">'code'</span>, a.code, <span class="string">'type'</span>, a.type, <span class="string">'experiment'</span>, a.experiment, <span class="keyword">...</span> + <span class="string">'project'</span>, a.project, <span class="string">'tags'</span>, a.tags)); + datasets = df_to_table(datasets.df); + <span class="keyword">end</span> + + <span class="keyword">function</span> dataset = get_dataset(obj, permid, varargin) + <span class="comment">%get_dataset</span> + <span class="comment">% Get dataset with permId. An error is raised if a dataset with the id is not found on the server.</span> + <span class="comment">% Input arguments:</span> + <span class="comment">% permId ... dataset permId</span> + <span class="comment">% Usage:</span> + <span class="comment">% dataset = obi.get_dataset('permId')</span> + + only_data = false; + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addRequired(p, <span class="string">'permid'</span>, @ischar); + addOptional(p, <span class="string">'only_data'</span>, only_data, @islogical); + parse(p, obj, permid, varargin{:}); + a = p.Results; + +<span class="comment">% dataset = obj.pybis.get_dataset(pyargs('permid', a.permid, 'only_data', a.only_data));</span> + dataset = obj.pybis.get_dataset(a.permid); + <span class="keyword">end</span> + + + <span class="keyword">function</span> files = get_dataset_files(obj, dataset, varargin) + <span class="comment">%get_dataset_files</span> + <span class="comment">% Get list of files in a dataset starting with start_folder.</span> + <span class="comment">% Input arguments:</span> + <span class="comment">% dataset ... dataset object returned by get_dataset</span> + <span class="comment">% start_folder ... starting folder for files (default: '/')</span> + <span class="comment">% Usage:</span> + <span class="comment">% files = obi.get_dataset_files(dataset)</span> + + start_folder = <span class="string">'/'</span>; + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addRequired(p, <span class="string">'dataset'</span>); + addOptional(p, <span class="string">'start_folder'</span>, start_folder, @ischar); + parse(p, obj, dataset, varargin{:}); + a = p.Results; + + files = dataset.get_files(pyargs(<span class="string">'start_folder'</span>, a.start_folder)); + files = df_to_table(files); + <span class="keyword">end</span> + + <span class="keyword">function</span> path_to_file = dataset_download(obj, dataset, files, varargin) + <span class="comment">%dataset_download</span> + <span class="comment">% Download files in a dataset</span> + <span class="comment">% dataset ... dataset object returned by get_dataset</span> + <span class="comment">% files ... cell array of files</span> + <span class="comment">% destination ... folder to download to (default: data)</span> + <span class="comment">% wait_until_finished ... wait or download in the background (default: true)</span> + <span class="comment">% workers ... number of workers to use for download (default: 10)</span> + <span class="comment">% Usage:</span> + <span class="comment">% path_to_files = obi.dataset_download(dataset, {'file1', 'file2'})</span> + + destination = <span class="string">'data'</span>; + wait_until_finished = true; + workers = 10; + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addRequired(p, <span class="string">'dataset'</span>); + addRequired(p, <span class="string">'files'</span>, @iscellstr); + addParameter(p, <span class="string">'destination'</span>, destination, @ischar); + addParameter(p, <span class="string">'wait_until_finished'</span>, wait_until_finished, @islogical); + addParameter(p, <span class="string">'workers'</span>, workers, @isscalar); + + parse(p, obj, dataset, files, varargin{:}); + a = p.Results; + + dataset.download(pyargs(<span class="string">'files'</span>, a.files, <span class="string">'destination'</span>, a.destination, <span class="string">'wait_until_finished'</span>, a.wait_until_finished, <span class="string">'workers'</span>, int16(a.workers))); + + path_to_file = fullfile(a.destination, dataset.char, a.files); + + <span class="keyword">end</span> + + <span class="keyword">function</span> dataset = new_dataset(obj, type, experiment, object, file_list) + <span class="comment">%new_dataset</span> + <span class="comment">% Create a new dataset with files</span> + <span class="comment">% type ... dataset type</span> + <span class="comment">% experiment ... experiment for dataset</span> + <span class="comment">% object ... object for dataset</span> + <span class="comment">% file_list ... list of files (cell string) to upload to new dataset</span> + <span class="comment">% Usage:</span> + <span class="comment">% dataset = obi.new_dataset('type', 'RAW_DATA', 'experiment', 'MY_EXP', 'object', 'MY_SAMPLE', 'file_list', {'file1', 'file2'})</span> + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addRequired(p, <span class="string">'type'</span>, @ischar); + addRequired(p, <span class="string">'experiment'</span>, @ischar); + addRequired(p, <span class="string">'object'</span>, @ischar); + addRequired(p, <span class="string">'file_list'</span>, @iscellstr); + + parse(p, obj, type, experiment, object, file_list); + a = p.Results; + + dataset = obj.pybis.new_dataset(pyargs(<span class="string">'type'</span>, a.type, <span class="string">'experiment'</span>, a.experiment, <span class="string">'sample'</span>, a.object, <span class="string">'files'</span>, a.file_list)); + dataset.save(); + + <span class="keyword">end</span> + + <span class="keyword">function</span> dataset = new_dataset_container(obj, type, experiment, object) + <span class="comment">%new_dataset_container</span> + <span class="comment">% Create a new dataset container</span> + <span class="comment">% type ... dataset container type</span> + <span class="comment">% experiment ... experiment for dataset container</span> + <span class="comment">% object ... object for dataset container</span> + <span class="comment">% Usage:</span> + <span class="comment">% dataset = obi.new_dataset_container('type', 'RAW_DATA', 'experiment', 'MY_EXP', 'object', 'MY_SAMPLE')</span> + + p = inputParser; + addRequired(p, <span class="string">'obj'</span>); + addRequired(p, <span class="string">'type'</span>, @ischar); + addRequired(p, <span class="string">'experiment'</span>, @ischar); + addRequired(p, <span class="string">'object'</span>, @ischar); + + parse(p, obj, type, experiment, object, file_list); + a = p.Results; + + dataset = obj.pybis.new_dataset(pyargs(<span class="string">'type'</span>, a.type, <span class="string">'experiment'</span>, a.experiment, <span class="string">'sample'</span>, a.object, <span class="string">'kind'</span>, <span class="string">'CONTAINER'</span>)); + dataset.save(); + + <span class="keyword">end</span> +</pre><pre class="codeinput"> <span class="keyword">end</span> + +<span class="keyword">end</span> +</pre><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB® R2018a</a><br></p></div><!-- +##### SOURCE BEGIN ##### +classdef OpenBis + % OpenBis High-level class for interacting with Python (pyBIS) Openbis objects + % This class creates a MATLAB OpenBis object that encapsulates the Python (pyBIS) Openbis object + % and provides methods for interacting with the Python (pyBIS) Openbis object. + % + % Usage: + % Construct the MATLAB OpenBis object like this: + % obi = OpenBis() + % This will ask for URL, user name and password to connect to openBIS server. + % These can also be provided as optional input arguments. + % + % Methods are generally called like this: + % spaces = obi.get_spaces() + % space = obi.get_space(code) + % + % Logout: + % obi.logout() + + + properties + pybis % Python Openbis object + end + + + methods + + %% Constructor method + function obj = OpenBis(varargin) + % OpenBis Constructor method for class OpenBis + % Creates the Python Openbis object and logs into the server + % Optional positional input arguments: + % url ... URL of the openBIS server (incl. port) + % user ... user name for openBIS + % pw ... password for openBIS + % Usage: + % obi = OpenBis() REPLACE_WITH_DASH_DASH> opens UI to enter URL, user name and password + % obi = OpenBis('server_url', 'user_name', 'user_password') + + if nargin > 0 + url = varargin{1}; + user = varargin{2}; + pw = varargin{3}; + else + [url, user, pw] = user_url_pw_inputdlg; + end + + o = py.pybis.Openbis(url, pyargs('verify_certificates', 0)); + o.login(user, pw, pyargs('save_token', 1)); + obj.pybis = o; + end + + function logout(obj) + %logout + % Log out of openBIS. + % Usage: + % obi.logout() + % + % After logout, the session token is no longer valid. + + obj.pybis.logout(); + end + + function tf= is_session_active(obj) + %is_session_active + % Check if the session token is still active. Returns true or false. + % Usage: + % true_false = obi.is_session_active() + + tf = obj.pybis.is_session_active(); + end + + function token = token(obj) + %token + % Returns the current session token. + % Usage: + % token = obi.token() + + token = char(obj.pybis.token); + end + + %% Masterdata methods + % this section defines Matlab equivalents of the following pyBIS methods: + % get_experiment_types + % get_sample_types + % get_material_types + % get_dataset_types + % get_terms + % get_tags + + function experiment_types = get_experiment_types(obj) + %get_experiment_types + % Return a table of all available experiment types. + % Usage: + % experiment_types = obi.get_experiment_types() + + experiment_types = obj.pybis.get_experiment_types(); + experiment_types = df_to_table(experiment_types.df); + end + + function sample_types = get_sample_types(obj) + %get_sample_types + % Return table of all available sample types. + % Usage: + % sample_types = obi.get_sample_types() + + sample_types = obj.pybis.get_sample_types(); + sample_types = df_to_table(sample_types.df); + end + + function material_types = get_material_types(obj) + %get_material_types + % Return table of all available material types. + % Usage: + % material_types = obi.get_material_types() + + material_types = obj.pybis.get_material_types(); + material_types = df_to_table(material_types.df); + end + + function dataset_types = get_dataset_types(obj) + %get_dataset_types + % Return table of all available dataset types. + % Usage: + % dataset_types = obi.get_dataset_types() + + dataset_types = obj.pybis.get_dataset_types(); + dataset_types = df_to_table(dataset_types.df); + end + + function terms = get_terms(obj) + %get_terms + % Return table of all available terms. + % Usage: + % terms = obi.get_terms() + + terms = obj.pybis.get_terms(); + terms = df_to_table(terms.df); + end + + function tags = get_tags(obj) + %get_tags + % Return table of all available tags. + % Usage: + % tags = obi.get_tags() + + tags = obj.pybis.get_tags(); + tags = df_to_table(tags.df); + end + + + %% Space methods + % this section defines Matlab equivalents of the following pyBIS methods: + % get_spaces + % get_space + % new_space + % space.delete + + function spaces = get_spaces(obj) + %get_spaces + % Return table of all available spaces. + % Usage: + % spaces = obi.get_spaces() + + spaces = obj.pybis.get_spaces(); + spaces = df_to_table(spaces.df); + end + + function space = get_space(obj, code) + %get_space + % Fetch space with matching space code and return the space object. + % An error is raised if a space with the code is not found on the server. + % Required input arguments: + % code ... space code + % Usage: + % space = obi.get_space('code') + + space = obj.pybis.get_space(code); + end + + function space = new_space(obj, code, description) + %new_space + % Create a new space with code and description and return the space object + % Required input arguments: + % code ... Space code + % description ... Space description + % Usage: + % space = obi.new_space('code', 'description') + + space = obj.pybis.new_space(pyargs('code', code, ... + 'description', description)); + space.save; + end + + function delete_space(obj, code, reason) + %delete_space + % Delete space with code and provide a reason for deletion + % Required input arguments: + % code ... Space code + % reason ... reason for deletion + % Usage: + % obi.delete_space('code', 'reason') + + space = obj.pybis.get_space(code); + space.delete(reason); + end + + + %% Project methods + % this section defines Matlab equivalents of the following pyBIS methods: + % get_projects + % get_project + % new_project + % project.delete + + function projects = get_projects(obj, space, code) + %get_projects + % Return table of matching projects. + % Input arguments: + % space ... space to fetch projects from + % project ... fetch projects matching code + % Usage: + % projects = obi.get_projects('space', 'code') + + projects = obj.pybis.get_projects(pyargs('space', space, 'code', code)); + projects = df_to_table(projects.df); + end + + function project = get_project(obj, id) + %get_project + % Fetch project with matching project id and return the project object. + % An error is raised if a project with the id is not found on the server. + % Required input arguments: + % id ... project id + % Usage: + % project = obi.get_project('id') + + project = obj.pybis.get_project(id); + end + + function project = new_project(obj, space, code, description) + %new_project + % Create a new project in space with code and description + % Return the project object + % Input arguments + % space ... Space code + % code ... Project code / id + % description ... Project description + % Usage: + % project = obi.new_project('space', 'code', 'description') + + space = obj.pybis.get_space(space); + project = space.new_project(pyargs('code', code, 'description', description)); + project.save(); + end + + function delete_project(obj, code, reason) + %delete_project + % Delete project with code and provide a reason for deletion + % Required input arguments: + % code ... Project code + % reason ... reason for deletion + % Usage: + % obi.delete_project('code', 'reason') + + project = obj.pybis.get_project(code); + project.delete(reason); + end + + + %% Experiment methods + % this section defines the following Matlab methods: + % get_experiments + % get_experiment + % new_experiment + + function experiments = get_experiments(obj, varargin) + %get_experiments + % Return table of matching experiments. + % Optional input arguments: + % space ... space to fetch experiments from + % type ... fetch experiments of specific type + % project ... project to fetch experiments from + % Usage: + % experiments = obi.get_experiments() + % experiments = obi.get_experiments('space', 'SPACE') + % experiments = obi.get_experiments('space', 'SPACE', 'type', 'UNKNOWN') + + space = ''; + type = ''; + project = ''; + + p = inputParser; + addRequired(p, 'obj'); + addParameter(p, 'space', space, @ischar); + addParameter(p, 'type', type, @ischar); + addParameter(p, 'project', project, @ischar); + parse(p, obj, varargin{:}); + a = p.Results; + + experiments = obj.pybis.get_experiments(pyargs('space', a.space, 'type', a.type, 'project', a.project)); + experiments = df_to_table(experiments.df); + end + + function experiment = get_experiment(obj, id) + %get_experiment + % Return experiment with identifier + % ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234) + % Usage: + % exp = obi.get_experiment('/SPACE/PROJECT/EXP') + % exp = obi.get_experiment('permID') + + experiment = obj.pybis.get_experiment(id); + end + + function experiment = new_experiment(obj, type, code, project) + %new_experiment + % Create a new experiment of specific type in a defined project + % Required input arguments: + % type ... new experiment type + % code ... new experiment code + % project ... project for new experiment ('SPACE/Project') + % Usage: + % experiment = obi.new_experiment('type', 'space', 'Space/Project') + + experiment = obj.pybis.new_experiment(pyargs('type', type, 'code', code, 'project', project)); + experiment.save(); + end + + + %% Object methods + % this section defines following Matlab methods related to openBIS objects / samples: + % get_object + % get_objects + % new_object + % delete_object + + function objects = get_objects(obj, varargin) + %get_objects + % Return a table of objects matching specified criteria + % Optional keyword arguments: + % id ... object identifier ('SPACE/PROJECT/') + % Usage: + % objects = obi.get_objects() + % objects = obi.get_objects('id', 'SPACE/') + + defaultId = ''; + + p = inputParser; + addRequired(p, 'obj'); + addParameter(p, 'id', defaultId, @ischar); + parse(p, obj, varargin{:}); + a = p.Results; + + objects = obj.pybis.get_objects(a.id); + objects = df_to_table(objects.df); + end + + function object = get_object(obj, id) + %get_object + % Return object (sample) corresponding to the id + % ID can be either the Space + Object code (e.g. /SPACE/123456789) or the PermID (e.g. 20181002164551373-1234) + % An error is raised if an object with the id is not found on the server. + % Required input arguments: + % id ... object id + % Usage: + % object = obi.get_object('id') + + object = obj.pybis.get_object(id); + end + + function object = new_object(obj, type, space, code) + %new_object + % Create a new object of type in space with code + % Return the object + % Input arguments + % type ... object type + % space ... Space code + % code ... object code + % Usage: + % object = obi.new_object('type', 'space', 'code') + + object = obj.pybis.new_object(pyargs('type', type, 'space', space, 'code', code)); + object.save(); + end + + function object = delete_object(obj, object, reason) + %delete_object + % Delete object and provide a reason for deletion + % Required input arguments: + % object ... object returned by get_object / new_object methods + % reason ... reason for deletion + % Usage: + % obi.delete_object(object, 'reason') + + object.delete(reason) + end + + + %% Dataset methods + % this section defines following Matlab methods: + % get_datasets + % get_dataset + % get_dataset_files + % dataset_download + % new_dataset + % new_dataset_container + + function datasets = get_datasets(obj, varargin) + %get_datasets + % Return table of matching datasets. + % Optional input arguments: + % code ... dataset code / permId + % type ... dataset type + % experiment ... datasets in experiment + % project ... datasets in project + % tags ... datasets with tags + % Usage: + % datasets = obi.get_datasets() + % datasets = obi.get_datasets('type', 'RAW_DATA') + % datasets = obi.get_datasets('experiment', '/SPACE/PROJECT/EXPERIMENT') + + defaultCode = ''; + defaultType = ''; + defaultExp = ''; + defaultProj = ''; + defaultTags = ''; + + p = inputParser; + addRequired(p, 'obj'); + addParameter(p, 'code', defaultCode, @ischar); + addParameter(p, 'type', defaultType, @ischar); + addParameter(p, 'experiment', defaultExp, @ischar); + addParameter(p, 'project', defaultProj, @ischar); + addParameter(p, 'tags', defaultTags, @ischar); + parse(p, obj, varargin{:}); + a = p.Results; + + datasets = obj.pybis.get_datasets(pyargs('code', a.code, 'type', a.type, 'experiment', a.experiment, ... + 'project', a.project, 'tags', a.tags)); + datasets = df_to_table(datasets.df); + end + + function dataset = get_dataset(obj, permid, varargin) + %get_dataset + % Get dataset with permId. An error is raised if a dataset with the id is not found on the server. + % Input arguments: + % permId ... dataset permId + % Usage: + % dataset = obi.get_dataset('permId') + + only_data = false; + + p = inputParser; + addRequired(p, 'obj'); + addRequired(p, 'permid', @ischar); + addOptional(p, 'only_data', only_data, @islogical); + parse(p, obj, permid, varargin{:}); + a = p.Results; + +% dataset = obj.pybis.get_dataset(pyargs('permid', a.permid, 'only_data', a.only_data)); + dataset = obj.pybis.get_dataset(a.permid); + end + + + function files = get_dataset_files(obj, dataset, varargin) + %get_dataset_files + % Get list of files in a dataset starting with start_folder. + % Input arguments: + % dataset ... dataset object returned by get_dataset + % start_folder ... starting folder for files (default: '/') + % Usage: + % files = obi.get_dataset_files(dataset) + + start_folder = '/'; + + p = inputParser; + addRequired(p, 'obj'); + addRequired(p, 'dataset'); + addOptional(p, 'start_folder', start_folder, @ischar); + parse(p, obj, dataset, varargin{:}); + a = p.Results; + + files = dataset.get_files(pyargs('start_folder', a.start_folder)); + files = df_to_table(files); + end + + function path_to_file = dataset_download(obj, dataset, files, varargin) + %dataset_download + % Download files in a dataset + % dataset ... dataset object returned by get_dataset + % files ... cell array of files + % destination ... folder to download to (default: data) + % wait_until_finished ... wait or download in the background (default: true) + % workers ... number of workers to use for download (default: 10) + % Usage: + % path_to_files = obi.dataset_download(dataset, {'file1', 'file2'}) + + destination = 'data'; + wait_until_finished = true; + workers = 10; + + p = inputParser; + addRequired(p, 'obj'); + addRequired(p, 'dataset'); + addRequired(p, 'files', @iscellstr); + addParameter(p, 'destination', destination, @ischar); + addParameter(p, 'wait_until_finished', wait_until_finished, @islogical); + addParameter(p, 'workers', workers, @isscalar); + + parse(p, obj, dataset, files, varargin{:}); + a = p.Results; + + dataset.download(pyargs('files', a.files, 'destination', a.destination, 'wait_until_finished', a.wait_until_finished, 'workers', int16(a.workers))); + + path_to_file = fullfile(a.destination, dataset.char, a.files); + + end + + function dataset = new_dataset(obj, type, experiment, object, file_list) + %new_dataset + % Create a new dataset with files + % type ... dataset type + % experiment ... experiment for dataset + % object ... object for dataset + % file_list ... list of files (cell string) to upload to new dataset + % Usage: + % dataset = obi.new_dataset('type', 'RAW_DATA', 'experiment', 'MY_EXP', 'object', 'MY_SAMPLE', 'file_list', {'file1', 'file2'}) + + p = inputParser; + addRequired(p, 'obj'); + addRequired(p, 'type', @ischar); + addRequired(p, 'experiment', @ischar); + addRequired(p, 'object', @ischar); + addRequired(p, 'file_list', @iscellstr); + + parse(p, obj, type, experiment, object, file_list); + a = p.Results; + + dataset = obj.pybis.new_dataset(pyargs('type', a.type, 'experiment', a.experiment, 'sample', a.object, 'files', a.file_list)); + dataset.save(); + + end + + function dataset = new_dataset_container(obj, type, experiment, object) + %new_dataset_container + % Create a new dataset container + % type ... dataset container type + % experiment ... experiment for dataset container + % object ... object for dataset container + % Usage: + % dataset = obi.new_dataset_container('type', 'RAW_DATA', 'experiment', 'MY_EXP', 'object', 'MY_SAMPLE') + + p = inputParser; + addRequired(p, 'obj'); + addRequired(p, 'type', @ischar); + addRequired(p, 'experiment', @ischar); + addRequired(p, 'object', @ischar); + + parse(p, obj, type, experiment, object, file_list); + a = p.Results; + + dataset = obj.pybis.new_dataset(pyargs('type', a.type, 'experiment', a.experiment, 'sample', a.object, 'kind', 'CONTAINER')); + dataset.save(); + + end + + + end + +end + + + +##### SOURCE END ##### +--></body></html> \ No newline at end of file diff --git a/html/df_to_table.html b/html/df_to_table.html new file mode 100644 index 00000000000..195fd7628de --- /dev/null +++ b/html/df_to_table.html @@ -0,0 +1,92 @@ + +<!DOCTYPE html + PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <!-- +This HTML was auto-generated from MATLAB code. +To make changes, update the MATLAB code and republish this document. + --><title>df_to_table</title><meta name="generator" content="MATLAB 9.4"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2019-03-21"><meta name="DC.source" content="df_to_table.m"><style type="text/css"> +html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0} + +html { min-height:100%; margin-bottom:1px; } +html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; } +html body td { vertical-align:top; text-align:left; } + +h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; } +h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; } +h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; } + +a { color:#005fce; text-decoration:none; } +a:hover { color:#005fce; text-decoration:underline; } +a:visited { color:#004aa0; text-decoration:none; } + +p { padding:0px; margin:0px 0px 20px; } +img { padding:0px; margin:0px 0px 20px; border:none; } +p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; } + +ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; } +ul li { padding:0px; margin:0px 0px 7px 0px; } +ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; } +ul li ol li { list-style:decimal; } +ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; } +ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; } +ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; } +ol li ol li { list-style-type:lower-alpha; } +ol li ul { padding-top:7px; } +ol li ul li { list-style:square; } + +.content { font-size:1.2em; line-height:140%; padding: 20px; } + +pre, code { font-size:12px; } +tt { font-size: 1.2em; } +pre { margin:0px 0px 20px; } +pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; } +pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; } +pre.error { color:red; } + +@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } } + +span.keyword { color:#0000FF } +span.comment { color:#228B22 } +span.string { color:#A020F0 } +span.untermstring { color:#B20000 } +span.syscmd { color:#B28C00 } + +.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; } +.footer p { margin:0px; } +.footer a { color:#878787; } +.footer a:hover { color:#878787; text-decoration:underline; } +.footer a:visited { color:#878787; } + +table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; } +table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; } + + + + + + </style></head><body><div class="content"><pre class="codeinput"><span class="keyword">function</span> [matlab_table] = df_to_table(df) +<span class="comment">%df_to_table</span> +<span class="comment">% Returns a Matlab table for a Python dataframe</span> + +csv_temp = sprintf(<span class="string">'%s.csv'</span>, tempname); +df.to_csv(csv_temp); +matlab_table = readtable(csv_temp); +delete(csv_temp); + +<span class="keyword">end</span> +</pre><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB® R2018a</a><br></p></div><!-- +##### SOURCE BEGIN ##### +function [matlab_table] = df_to_table(df) +%df_to_table +% Returns a Matlab table for a Python dataframe + +csv_temp = sprintf('%s.csv', tempname); +df.to_csv(csv_temp); +matlab_table = readtable(csv_temp); +delete(csv_temp); + +end +##### SOURCE END ##### +--></body></html> \ No newline at end of file diff --git a/html/passwordEntryDialog.html b/html/passwordEntryDialog.html new file mode 100644 index 00000000000..37b052b1f70 --- /dev/null +++ b/html/passwordEntryDialog.html @@ -0,0 +1,826 @@ + +<!DOCTYPE html + PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <!-- +This HTML was auto-generated from MATLAB code. +To make changes, update the MATLAB code and republish this document. + --><title>passwordEntryDialog</title><meta name="generator" content="MATLAB 9.4"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2019-03-21"><meta name="DC.source" content="passwordEntryDialog.m"><style type="text/css"> +html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0} + +html { min-height:100%; margin-bottom:1px; } +html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; } +html body td { vertical-align:top; text-align:left; } + +h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; } +h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; } +h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; } + +a { color:#005fce; text-decoration:none; } +a:hover { color:#005fce; text-decoration:underline; } +a:visited { color:#004aa0; text-decoration:none; } + +p { padding:0px; margin:0px 0px 20px; } +img { padding:0px; margin:0px 0px 20px; border:none; } +p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; } + +ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; } +ul li { padding:0px; margin:0px 0px 7px 0px; } +ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; } +ul li ol li { list-style:decimal; } +ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; } +ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; } +ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; } +ol li ol li { list-style-type:lower-alpha; } +ol li ul { padding-top:7px; } +ol li ul li { list-style:square; } + +.content { font-size:1.2em; line-height:140%; padding: 20px; } + +pre, code { font-size:12px; } +tt { font-size: 1.2em; } +pre { margin:0px 0px 20px; } +pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; } +pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; } +pre.error { color:red; } + +@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } } + +span.keyword { color:#0000FF } +span.comment { color:#228B22 } +span.string { color:#A020F0 } +span.untermstring { color:#B20000 } +span.syscmd { color:#B28C00 } + +.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; } +.footer p { margin:0px; } +.footer a { color:#878787; } +.footer a:hover { color:#878787; text-decoration:underline; } +.footer a:visited { color:#878787; } + +table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; } +table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; } + + + + + + </style></head><body><div class="content"><h2>Contents</h2><div><ul><li><a href="#3">History</a></li><li><a href="#4">Program Information</a></li><li><a href="#5">Check for Existance of Java</a></li><li><a href="#6">Parse Input Arguments</a></li><li><a href="#7">Determine GUI Size and Position</a></li><li><a href="#8">Create the GUI</a></li><li><a href="#9">Setup Callbacks for Objects</a></li><li><a href="#10">Wait for Completion</a></li><li><a href="#11">Get current information</a></li><li><a href="#12">DEFINE FUNCTIONS</a></li></ul></div><pre class="codeinput"><span class="keyword">function</span> [Password, UserName] = passwordEntryDialog(varargin) +</pre><pre class="codeinput"><span class="comment">% PASSWORDENTRYDIALOG</span> +<span class="comment">% [Password, UserName] = passwordEntryDialog(varargin)</span> +<span class="comment">%</span> +<span class="comment">% Create a password entry dialog for entering a password that is visibly</span> +<span class="comment">% hidden. Java must be enabled for this function to work properly.</span> +<span class="comment">%</span> +<span class="comment">% It has only been tested on the Windows platform in R2008a. It should</span> +<span class="comment">% work in R2007a or later.</span> +<span class="comment">%</span> +<span class="comment">% The password box is created using the Java Swing component</span> +<span class="comment">% JPasswordField.</span> +<span class="comment">%</span> +<span class="comment">% Optional Input Arguments</span> +<span class="comment">% ------------------------</span> +<span class="comment">%</span> +<span class="comment">% 'enterUserName' DEFAULT: false</span> +<span class="comment">% Display the user name entry box. The user name entered must be at least</span> +<span class="comment">% one character or an error dialog is displayed.</span> +<span class="comment">%</span> +<span class="comment">% 'DefaultUserName' DEFAULT: ''</span> +<span class="comment">% String value of user name to populate in User Name box upon creation.</span> +<span class="comment">%</span> +<span class="comment">% 'ValidatePassword' DEFAULT: false</span> +<span class="comment">% Display dialog box to reenter password for validation purposes.</span> +<span class="comment">%</span> +<span class="comment">% 'CheckPasswordLength' DEFAULT: true</span> +<span class="comment">% Check the password length to ensure it meets the specified criteria.</span> +<span class="comment">%</span> +<span class="comment">% 'PasswordLengthMin' DEFAULT: 2</span> +<span class="comment">% Minimum password length allowed.</span> +<span class="comment">%</span> +<span class="comment">% 'PasswordLengthMax' DEFAULT: 8</span> +<span class="comment">% Maximum password length allowed.</span> +<span class="comment">%</span> +<span class="comment">% 'WindowName' DEFAULT: 'Login'</span> +<span class="comment">% Title of the password entry window.</span> +<span class="comment">%</span> +<span class="comment">% Examples</span> +<span class="comment">% --------</span> +<span class="comment">%</span> +<span class="comment">% Create a password dialog box with the default options.</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% [Password] = passwordEntryDialog;</span> +<span class="comment">%</span> +<span class="comment">% Create a user name and password entry dialog box without password</span> +<span class="comment">% verification.</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% [Password, UserName] = passwordEntryDialog('enterUserName', true)</span> +<span class="comment">%</span> +<span class="comment">% Create a user name and password entry dialog box without password</span> +<span class="comment">% verification. Set the user name to 'jdoe' upon startup.</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% [Password, UserName] = passwordEntryDialog('enterUserName', true,...</span> +<span class="comment">% 'DefaultUserName', 'jdoe')</span> +<span class="comment">%</span> +<span class="comment">% Create a password dialog box with password validation</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% [Password] = passwordEntryDialog('ValidatePassword', true);</span> +<span class="comment">%</span> +<span class="comment">% Create a user name and password entry dialog box with password</span> +<span class="comment">% verification.</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% [Password, UserName] = passwordEntryDialog('enterUserName', true,...</span> +<span class="comment">% 'ValidatePassword', true)</span> +<span class="comment">%</span> +<span class="comment">% Check the length of the password to be between 5 and 8 characters</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% [Password, UserName] = passwordEntryDialog('CheckPasswordLength', true,...</span> +<span class="comment">% 'PasswordLengthMin', 5,...</span> +<span class="comment">% 'PasswordLengthMax', 8)</span> +<span class="comment">%</span> +<span class="comment">% -----------------------------------------------------------------------</span> +<span class="comment">% Copyright (C) 2007-2008, Jesse B. Lai</span> +<span class="comment">%</span> +<span class="comment">% This program is free software: you can redistribute it and/or modify</span> +<span class="comment">% it under the terms of the GNU Lesser General Public License as published</span> +<span class="comment">% by the Free Software Foundation, either version 3 of the License, or</span> +<span class="comment">% (at your option) any later version.</span> +<span class="comment">%</span> +<span class="comment">% This program is distributed in the hope that it will be useful,</span> +<span class="comment">% but WITHOUT ANY WARRANTY; without even the implied warranty of</span> +<span class="comment">% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> +<span class="comment">% GNU Lesser General Public License for more details.</span> +<span class="comment">%</span> +<span class="comment">% You should have received a copy of the GNU Lesser General Public License</span> +<span class="comment">% along with this program. If not, see <http://www.gnu.org/licenses/></span> +</pre><h2 id="3">History</h2><p>The history of this program is outlined in this section.</p><p>20080616 - JBL - 0.0.2 Started 20080612</p><p>Updated to remove requirement for uicomponent function written by Yair Altman. Now, the Java components are created manually and the undocumented feature javacomponent is used.</p><p>A focus issue was worked out by using the drawnow command in a couple of places to allow the objects to be focused properly upon startup.</p><p>20080427 - JBL - 0.0.1 Started 20080425.</p><p>Initial version. Uses Java to create the password entry box. An edit box was initially attemped with the Java frame, but was occasionally getting Java exceptions when trying to query the 'SelectionStart' and 'SelectionEnd' properties.</p><p>Basic options of entering user name and password with options for password validation.</p><p>ToDo: Maybe add valid string input argument to only allow certain characters.</p><h2 id="4">Program Information</h2><pre class="codeinput"><span class="comment">% ProgramName = 'passwordEntryDialog';</span> +<span class="comment">% ProgramVersion = '0.0.2';</span> +<span class="comment">% svnRevision = '$Revision: 184 $';</span> +<span class="comment">% svnRevision = getSVNRevision(svnRevision);</span> +<span class="comment">% ProgramVersion = [ProgramVersion, '.' ,svnRevision];</span> +<span class="comment">%</span> +<span class="comment">% LastChangedDate = '$LastChangedDate: 2008-06-16 09:08:17 -0600 (Mon, 16 Jun 2008) $';</span> +<span class="comment">% ProgramDate = getSVNDate(LastChangedDate);</span> +</pre><h2 id="5">Check for Existance of Java</h2><pre class="codeinput"><span class="keyword">if</span> ~usejava(<span class="string">'swing'</span>) + error(<span class="string">'passwordEntryDialog: Java is required for this program to run.'</span>); +<span class="keyword">end</span> +</pre><h2 id="6">Parse Input Arguments</h2><p>Input arguments are parsed with the MATLAB inputParser class.</p><pre class="codeinput"><span class="comment">% Create input parser object</span> +ProgramOptionsParser = inputParser; +ProgramOptionsParser.KeepUnmatched = true; + +ProgramOptionsParser.addParamValue(<span class="string">'enterUserName'</span>, false, @(x) islogical(x) || isnumeric(x)); +ProgramOptionsParser.addParamValue(<span class="string">'DefaultUserName'</span>, <span class="string">''</span>, @ischar); +ProgramOptionsParser.addParamValue(<span class="string">'ValidatePassword'</span>, false, @(x) islogical(x) || isnumeric(x)); +ProgramOptionsParser.addParamValue(<span class="string">'CheckPasswordLength'</span>, true, @(x) islogical(x) || isnumeric(x)); +ProgramOptionsParser.addParamValue(<span class="string">'PasswordLengthMin'</span>, 2, @isnumeric); +ProgramOptionsParser.addParamValue(<span class="string">'PasswordLengthMax'</span>, 8, @isnumeric); +ProgramOptionsParser.addParamValue(<span class="string">'WindowName'</span>, <span class="string">'Login'</span>, @ischar); + +<span class="comment">% Parse Input Arguments</span> +<span class="keyword">try</span> + ProgramOptionsParser.parse(varargin{:}); +<span class="keyword">catch</span> Error + ProgramOptionsParser.parse; + <span class="keyword">if</span> strcmpi(Error.identifier, <span class="string">'MATLAB:InputParser:ArgumentFailedValidation'</span>) + error(Error.identifier, Error.message); + <span class="keyword">end</span>; +<span class="keyword">end</span>; + +ProgramOptions = ProgramOptionsParser.Results; + +<span class="comment">% Validate password length options</span> +<span class="keyword">if</span> ProgramOptions.CheckPasswordLength + <span class="keyword">if</span> ProgramOptions.PasswordLengthMax < ProgramOptions.PasswordLengthMin + error(<span class="string">'MATLAB:InputParser:ArgumentFailedValidation'</span>, <span class="string">'PasswordLengthMax must be greater than PasswordLengthMin'</span>); + <span class="keyword">end</span>; +<span class="keyword">end</span>; +</pre><h2 id="7">Determine GUI Size and Position</h2><p>Center the GUI on the screen.</p><pre class="codeinput">set(0,<span class="string">'Units'</span>,<span class="string">'pixels'</span>) +Screen = get(0,<span class="string">'screensize'</span>); + +PositionGUI = [0 0 300 50]; +<span class="keyword">if</span> ProgramOptions.enterUserName + PositionGUI = PositionGUI + [0 0 0 50]; +<span class="keyword">end</span>; +<span class="keyword">if</span> ProgramOptions.ValidatePassword + PositionGUI = PositionGUI + [0 0 0 50]; + OffsetBottom = 43; +<span class="keyword">else</span> + OffsetBottom = 0; +<span class="keyword">end</span>; + +PositionGUI = [Screen(3:4)/2-PositionGUI(3:4)/2 PositionGUI(3:4)]; +PositionLeft = 10; +BoxWidth = 200; +</pre><h2 id="8">Create the GUI</h2><pre class="codeinput">BackgroundColor = get(0,<span class="string">'DefaultUicontrolBackgroundcolor'</span>); +handles.figure1 = figure(<span class="string">'Menubar'</span>,<span class="string">'none'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>,<span class="string">'Pixels'</span>, <span class="keyword">...</span> + <span class="string">'Resize'</span>,<span class="string">'off'</span>, <span class="keyword">...</span> + <span class="string">'NumberTitle'</span>,<span class="string">'off'</span>, <span class="keyword">...</span> + <span class="string">'Name'</span>,ProgramOptions.WindowName, <span class="keyword">...</span> + <span class="string">'Position'</span>,PositionGUI, <span class="keyword">...</span> + <span class="string">'Color'</span>, BackgroundColor, <span class="keyword">...</span> + <span class="string">'WindowStyle'</span>,<span class="string">'modal'</span>); + +<span class="comment">% Create Password Validation Entry Box</span> +<span class="keyword">if</span> ProgramOptions.ValidatePassword + handles.java_PasswordValidate = javax.swing.JPasswordField(); + handles.java_PasswordValidate.setFocusable(true); + [handles.java_PasswordValidate, handles.edit_PasswordValidate] = javacomponent(handles.java_PasswordValidate, [], handles.figure1); + + set(handles.edit_PasswordValidate, <span class="keyword">...</span> + <span class="string">'Parent'</span>, handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'edit_PasswordValidate'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>, <span class="string">'Pixels'</span>, <span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft 10 BoxWidth 23]); + + handles.text_LabelPasswordValidate = uicontrol(<span class="string">'Parent'</span>,handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'text_LabelPassword'</span>, <span class="keyword">...</span> + <span class="string">'Style'</span>,<span class="string">'Text'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>,<span class="string">'Pixels'</span>,<span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft 33 BoxWidth 16], <span class="keyword">...</span> + <span class="string">'FontSize'</span>,10, <span class="keyword">...</span> + <span class="string">'String'</span>,<span class="string">'Reenter password:'</span>,<span class="keyword">...</span> + <span class="string">'HorizontalAlignment'</span>, <span class="string">'Left'</span>); +<span class="keyword">end</span>; + +<span class="comment">% Create Password Entry Box</span> +handles.java_Password = javax.swing.JPasswordField(); +[handles.java_Password, handles.edit_Password] = javacomponent(handles.java_Password, [PositionLeft 10+OffsetBottom BoxWidth 23], handles.figure1); +handles.java_Password.setFocusable(true); + +set(handles.edit_Password, <span class="keyword">...</span> + <span class="string">'Parent'</span>, handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'edit_Password'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>, <span class="string">'Pixels'</span>, <span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft 10+OffsetBottom BoxWidth 23]); +drawnow; <span class="comment">% This drawnow is required to allow the focus to work</span> + +handles.text_LabelPassword = uicontrol(<span class="string">'Parent'</span>,handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'text_LabelPassword'</span>, <span class="keyword">...</span> + <span class="string">'Style'</span>,<span class="string">'Text'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>,<span class="string">'Pixels'</span>,<span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft 33+OffsetBottom BoxWidth 16], <span class="keyword">...</span> + <span class="string">'FontSize'</span>,10, <span class="keyword">...</span> + <span class="string">'String'</span>,<span class="string">'Key:'</span>,<span class="keyword">...</span> + <span class="string">'HorizontalAlignment'</span>, <span class="string">'Left'</span>); + +<span class="comment">% Create OK Pushbutton</span> +handles.pushbutton_OK = uicontrol(<span class="string">'Parent'</span>,handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'pushbutton_OK'</span>, <span class="keyword">...</span> + <span class="string">'Style'</span>,<span class="string">'Pushbutton'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>,<span class="string">'Pixels'</span>,<span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft+BoxWidth+5 10 30 23], <span class="keyword">...</span> + <span class="string">'FontSize'</span>,10, <span class="keyword">...</span> + <span class="string">'String'</span>,<span class="string">'OK'</span>,<span class="keyword">...</span> + <span class="string">'HorizontalAlignment'</span>, <span class="string">'Center'</span>); + +<span class="comment">% Create Cancel Pushbutton</span> +handles.pushbutton_Cancel = uicontrol(<span class="string">'Parent'</span>,handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'pushbutton_Cancel'</span>, <span class="keyword">...</span> + <span class="string">'Style'</span>,<span class="string">'Pushbutton'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>,<span class="string">'Pixels'</span>,<span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft+BoxWidth+30+7 10 50 23], <span class="keyword">...</span> + <span class="string">'FontSize'</span>,10, <span class="keyword">...</span> + <span class="string">'String'</span>,<span class="string">'Cancel'</span>,<span class="keyword">...</span> + <span class="string">'HorizontalAlignment'</span>, <span class="string">'Center'</span>); + +<span class="comment">% Create User Name Edit Box</span> +<span class="keyword">if</span> ProgramOptions.enterUserName + handles.java_UserName = javax.swing.JTextField(); + handles.java_UserName.setFocusable(true); + [handles.java_UserName, handles.edit_UserName] = javacomponent(handles.java_UserName, [], handles.figure1); + + set(handles.edit_UserName, <span class="keyword">...</span> + <span class="string">'Parent'</span>, handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'edit_UserName'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>, <span class="string">'Pixels'</span>, <span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft 53+OffsetBottom 200 23]); + set(handles.java_UserName, <span class="string">'Text'</span>, ProgramOptions.DefaultUserName); + drawnow; <span class="comment">% This drawnow is required to allow the focus to work</span> + + handles.text_LabelUserName = uicontrol(<span class="string">'Parent'</span>,handles.figure1, <span class="keyword">...</span> + <span class="string">'Tag'</span>, <span class="string">'text_LabelUserName'</span>, <span class="keyword">...</span> + <span class="string">'Style'</span>,<span class="string">'Text'</span>, <span class="keyword">...</span> + <span class="string">'Units'</span>,<span class="string">'Pixels'</span>,<span class="keyword">...</span> + <span class="string">'Position'</span>,[PositionLeft 76+OffsetBottom 200 16], <span class="keyword">...</span> + <span class="string">'FontSize'</span>,10, <span class="keyword">...</span> + <span class="string">'String'</span>,<span class="string">'User name:'</span>,<span class="keyword">...</span> + <span class="string">'HorizontalAlignment'</span>, <span class="string">'Left'</span>); + + <span class="comment">%uicontrol(handles.edit_UserName);</span> + <span class="comment">%set(handles.figure1,'CurrentObject',handles.java_UserName)</span> + handles.java_UserName.requestFocus; <span class="comment">% Get focus</span> + drawnow; +<span class="keyword">else</span> + handles.java_Password.requestFocus; <span class="comment">% Get focus</span> + drawnow; +<span class="keyword">end</span>; +</pre><h2 id="9">Setup Callbacks for Objects</h2><p>Adds the callback functions for the objects in the GUI</p><pre class="codeinput">set(handles.pushbutton_OK, <span class="string">'Callback'</span>, {@pushbutton_OK_Callback, handles, ProgramOptions}, <span class="string">'KeyPressFcn'</span>, {@pushbutton_KeyPressFcn, handles, ProgramOptions}); +set(handles.pushbutton_Cancel, <span class="string">'Callback'</span>, {@pushbutton_Cancel_Callback, handles, ProgramOptions}, <span class="string">'KeyPressFcn'</span>, {@pushbutton_KeyPressFcn, handles, ProgramOptions}); +set(handles.java_Password, <span class="string">'ActionPerformedCallback'</span>, {@pushbutton_OK_Callback, handles, ProgramOptions}); + +<span class="keyword">if</span> ProgramOptions.ValidatePassword + <span class="keyword">if</span> ProgramOptions.enterUserName + ObjectNext = handles.java_UserName; + <span class="keyword">else</span> + ObjectNext = handles.java_Password; + <span class="keyword">end</span>; + set(handles.java_PasswordValidate, <span class="string">'ActionPerformedCallback'</span>, {@pushbutton_OK_Callback, handles, ProgramOptions}, <span class="string">'NextFocusableComponent'</span>, ObjectNext); + set(handles.java_Password, <span class="string">'NextFocusableComponent'</span>, handles.java_PasswordValidate); +<span class="keyword">elseif</span> ProgramOptions.enterUserName + set(handles.java_Password, <span class="string">'NextFocusableComponent'</span>, handles.java_UserName); +<span class="keyword">end</span>; + +<span class="keyword">if</span> ProgramOptions.enterUserName + set(handles.java_UserName, <span class="string">'ActionPerformedCallback'</span>, {@pushbutton_OK_Callback, handles, ProgramOptions}, <span class="string">'NextFocusableComponent'</span>, handles.java_Password); +<span class="keyword">end</span>; + +setappdata(handles.figure1, <span class="string">'isCanceled'</span>, false); +</pre><h2 id="10">Wait for Completion</h2><pre class="codeinput"><span class="comment">% Wait for the user to complete entry.</span> +drawnow; +uiwait(handles.figure1); +</pre><h2 id="11">Get current information</h2><p>User either closed the window or pressed cancel or OK.</p><pre class="codeinput">isCanceled = ~ishandle(handles.figure1) || getappdata(handles.figure1, <span class="string">'isCanceled'</span>); +<span class="keyword">if</span> isCanceled + <span class="keyword">if</span> ishandle(handles.figure1) + delete(handles.figure1); + <span class="keyword">end</span>; + Password = -1; + UserName = <span class="string">''</span>; + <span class="keyword">return</span>; +<span class="keyword">end</span>; + +Password = handles.java_Password.Password'; +<span class="keyword">if</span> ProgramOptions.enterUserName + UserName = strtrim(get(handles.java_UserName, <span class="string">'Text'</span>)); +<span class="keyword">else</span> + UserName = <span class="string">''</span>; +<span class="keyword">end</span>; +delete(handles.figure1); +</pre><h2 id="12">DEFINE FUNCTIONS</h2><p>The subfunctions required by this program are in the following section.</p><pre class="codeinput"><span class="keyword">function</span> pushbutton_KeyPressFcn(hObject, eventdata, handles, ProgramOptions) + +<span class="keyword">switch</span> eventdata.Key + <span class="keyword">case</span> <span class="string">'return'</span> + Callback = get(hObject, <span class="string">'Callback'</span>); + feval(Callback{1}, hObject, <span class="string">''</span>, Callback{2:end}); +<span class="keyword">end</span>; + +<span class="keyword">function</span> pushbutton_OK_Callback(hObject, eventdata, handles, ProgramOptions) +<span class="keyword">if</span> ProgramOptions.enterUserName + <span class="comment">% Check if username is blank</span> + UserName = strtrim(get(handles.java_UserName, <span class="string">'Text'</span>)); + <span class="keyword">if</span> isempty(UserName) + strMessage = <span class="string">'Username is blank'</span>; + <span class="comment">%disp(strMessage)</span> + hError = errordlg(strMessage, <span class="string">'passwordEntryDialog'</span>); + uiwait(hError); + <span class="keyword">return</span>; + <span class="keyword">end</span>; +<span class="keyword">end</span>; + +<span class="keyword">if</span> ProgramOptions.CheckPasswordLength + <span class="comment">%Password = handles.edit_Password.Password';</span> + Password = handles.java_Password.Password'; + <span class="keyword">if</span> length(Password) < ProgramOptions.PasswordLengthMin || length(Password) > ProgramOptions.PasswordLengthMax + strMessage = sprintf(<span class="string">'Password must be between %d and %d characters'</span>, <span class="keyword">...</span> + ProgramOptions.PasswordLengthMin, <span class="keyword">...</span> + ProgramOptions.PasswordLengthMax); + <span class="comment">%disp(strMessage);</span> + hError = errordlg(strMessage, <span class="string">'passwordEntryDialog'</span>); + uiwait(hError); + <span class="keyword">if</span> ProgramOptions.ValidatePassword + set(handles.java_PasswordValidate,<span class="string">'Text'</span>, <span class="string">''</span>); + <span class="keyword">end</span>; + handles.java_Password.requestFocus + <span class="keyword">return</span>; + <span class="keyword">end</span>; +<span class="keyword">end</span>; + +<span class="keyword">if</span> ProgramOptions.ValidatePassword + <span class="comment">% Check if passwords match</span> + <span class="keyword">if</span> ~isequal(handles.java_Password.Password, handles.java_PasswordValidate.Password) + strMessage = <span class="string">'Passwords do not match. Please try again'</span>; + <span class="comment">%disp(strMessage);</span> + hError=errordlg(strMessage, <span class="string">'passwordEntryDialog'</span>,<span class="string">'modal'</span>); + uiwait(hError); + set(handles.java_Password,<span class="string">'Text'</span>, <span class="string">''</span>); + set(handles.java_PasswordValidate,<span class="string">'Text'</span>, <span class="string">''</span>); + + handles.java_Password.requestFocus + <span class="keyword">return</span>; + <span class="keyword">end</span>; +<span class="keyword">end</span>; +uiresume(handles.figure1); + +<span class="keyword">function</span> pushbutton_Cancel_Callback(hObject, eventdata, handles, ProgramOptions) +setappdata(handles.figure1, <span class="string">'isCanceled'</span>, true); +uiresume(handles.figure1); +</pre><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB® R2018a</a><br></p></div><!-- +##### SOURCE BEGIN ##### +function [Password, UserName] = passwordEntryDialog(varargin) +% PASSWORDENTRYDIALOG +% [Password, UserName] = passwordEntryDialog(varargin) +% +% Create a password entry dialog for entering a password that is visibly +% hidden. Java must be enabled for this function to work properly. +% +% It has only been tested on the Windows platform in R2008a. It should +% work in R2007a or later. +% +% The password box is created using the Java Swing component +% JPasswordField. +% +% Optional Input Arguments +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH +% +% 'enterUserName' DEFAULT: false +% Display the user name entry box. The user name entered must be at least +% one character or an error dialog is displayed. +% +% 'DefaultUserName' DEFAULT: '' +% String value of user name to populate in User Name box upon creation. +% +% 'ValidatePassword' DEFAULT: false +% Display dialog box to reenter password for validation purposes. +% +% 'CheckPasswordLength' DEFAULT: true +% Check the password length to ensure it meets the specified criteria. +% +% 'PasswordLengthMin' DEFAULT: 2 +% Minimum password length allowed. +% +% 'PasswordLengthMax' DEFAULT: 8 +% Maximum password length allowed. +% +% 'WindowName' DEFAULT: 'Login' +% Title of the password entry window. +% +% Examples +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH +% +% Create a password dialog box with the default options. +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% [Password] = passwordEntryDialog; +% +% Create a user name and password entry dialog box without password +% verification. +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% [Password, UserName] = passwordEntryDialog('enterUserName', true) +% +% Create a user name and password entry dialog box without password +% verification. Set the user name to 'jdoe' upon startup. +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% [Password, UserName] = passwordEntryDialog('enterUserName', true,... +% 'DefaultUserName', 'jdoe') +% +% Create a password dialog box with password validation +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% [Password] = passwordEntryDialog('ValidatePassword', true); +% +% Create a user name and password entry dialog box with password +% verification. +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% [Password, UserName] = passwordEntryDialog('enterUserName', true,... +% 'ValidatePassword', true) +% +% Check the length of the password to be between 5 and 8 characters +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% [Password, UserName] = passwordEntryDialog('CheckPasswordLength', true,... +% 'PasswordLengthMin', 5,... +% 'PasswordLengthMax', 8) +% +% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH- +% Copyright (C) 2007-2008, Jesse B. Lai +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU Lesser General Public License as published +% by the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU Lesser General Public License for more details. +% +% You should have received a copy of the GNU Lesser General Public License +% along with this program. If not, see <http://www.gnu.org/licenses/> + +%% History +% The history of this program is outlined in this section. +% +% 20080616 - JBL - 0.0.2 +% Started 20080612 +% +% Updated to remove requirement for uicomponent function written by Yair +% Altman. Now, the Java components are created manually and the +% undocumented feature javacomponent is used. +% +% A focus issue was worked out by using the drawnow command in a couple of +% places to allow the objects to be focused properly upon startup. +% +% 20080427 - JBL - 0.0.1 +% Started 20080425. +% +% Initial version. Uses Java to create the password entry box. An edit +% box was initially attemped with the Java frame, but was occasionally +% getting Java exceptions when trying to query the 'SelectionStart' and +% 'SelectionEnd' properties. +% +% Basic options of entering user name and password with options for +% password validation. +% +% ToDo: Maybe add valid string input argument to only allow certain +% characters. + +%% Program Information + +% ProgramName = 'passwordEntryDialog'; +% ProgramVersion = '0.0.2'; +% svnRevision = '$Revision: 184 $'; +% svnRevision = getSVNRevision(svnRevision); +% ProgramVersion = [ProgramVersion, '.' ,svnRevision]; +% +% LastChangedDate = '$LastChangedDate: 2008-06-16 09:08:17 -0600 (Mon, 16 Jun 2008) $'; +% ProgramDate = getSVNDate(LastChangedDate); + +%% Check for Existance of Java +if ~usejava('swing') + error('passwordEntryDialog: Java is required for this program to run.'); +end + +%% Parse Input Arguments +% Input arguments are parsed with the MATLAB inputParser class. + +% Create input parser object +ProgramOptionsParser = inputParser; +ProgramOptionsParser.KeepUnmatched = true; + +ProgramOptionsParser.addParamValue('enterUserName', false, @(x) islogical(x) || isnumeric(x)); +ProgramOptionsParser.addParamValue('DefaultUserName', '', @ischar); +ProgramOptionsParser.addParamValue('ValidatePassword', false, @(x) islogical(x) || isnumeric(x)); +ProgramOptionsParser.addParamValue('CheckPasswordLength', true, @(x) islogical(x) || isnumeric(x)); +ProgramOptionsParser.addParamValue('PasswordLengthMin', 2, @isnumeric); +ProgramOptionsParser.addParamValue('PasswordLengthMax', 8, @isnumeric); +ProgramOptionsParser.addParamValue('WindowName', 'Login', @ischar); + +% Parse Input Arguments +try + ProgramOptionsParser.parse(varargin{:}); +catch Error + ProgramOptionsParser.parse; + if strcmpi(Error.identifier, 'MATLAB:InputParser:ArgumentFailedValidation') + error(Error.identifier, Error.message); + end; +end; + +ProgramOptions = ProgramOptionsParser.Results; + +% Validate password length options +if ProgramOptions.CheckPasswordLength + if ProgramOptions.PasswordLengthMax < ProgramOptions.PasswordLengthMin + error('MATLAB:InputParser:ArgumentFailedValidation', 'PasswordLengthMax must be greater than PasswordLengthMin'); + end; +end; + +%% Determine GUI Size and Position +% Center the GUI on the screen. + +set(0,'Units','pixels') +Screen = get(0,'screensize'); + +PositionGUI = [0 0 300 50]; +if ProgramOptions.enterUserName + PositionGUI = PositionGUI + [0 0 0 50]; +end; +if ProgramOptions.ValidatePassword + PositionGUI = PositionGUI + [0 0 0 50]; + OffsetBottom = 43; +else + OffsetBottom = 0; +end; + +PositionGUI = [Screen(3:4)/2-PositionGUI(3:4)/2 PositionGUI(3:4)]; +PositionLeft = 10; +BoxWidth = 200; + +%% Create the GUI + +BackgroundColor = get(0,'DefaultUicontrolBackgroundcolor'); +handles.figure1 = figure('Menubar','none', ... + 'Units','Pixels', ... + 'Resize','off', ... + 'NumberTitle','off', ... + 'Name',ProgramOptions.WindowName, ... + 'Position',PositionGUI, ... + 'Color', BackgroundColor, ... + 'WindowStyle','modal'); + +% Create Password Validation Entry Box +if ProgramOptions.ValidatePassword + handles.java_PasswordValidate = javax.swing.JPasswordField(); + handles.java_PasswordValidate.setFocusable(true); + [handles.java_PasswordValidate, handles.edit_PasswordValidate] = javacomponent(handles.java_PasswordValidate, [], handles.figure1); + + set(handles.edit_PasswordValidate, ... + 'Parent', handles.figure1, ... + 'Tag', 'edit_PasswordValidate', ... + 'Units', 'Pixels', ... + 'Position',[PositionLeft 10 BoxWidth 23]); + + handles.text_LabelPasswordValidate = uicontrol('Parent',handles.figure1, ... + 'Tag', 'text_LabelPassword', ... + 'Style','Text', ... + 'Units','Pixels',... + 'Position',[PositionLeft 33 BoxWidth 16], ... + 'FontSize',10, ... + 'String','Reenter password:',... + 'HorizontalAlignment', 'Left'); +end; + +% Create Password Entry Box +handles.java_Password = javax.swing.JPasswordField(); +[handles.java_Password, handles.edit_Password] = javacomponent(handles.java_Password, [PositionLeft 10+OffsetBottom BoxWidth 23], handles.figure1); +handles.java_Password.setFocusable(true); + +set(handles.edit_Password, ... + 'Parent', handles.figure1, ... + 'Tag', 'edit_Password', ... + 'Units', 'Pixels', ... + 'Position',[PositionLeft 10+OffsetBottom BoxWidth 23]); +drawnow; % This drawnow is required to allow the focus to work + +handles.text_LabelPassword = uicontrol('Parent',handles.figure1, ... + 'Tag', 'text_LabelPassword', ... + 'Style','Text', ... + 'Units','Pixels',... + 'Position',[PositionLeft 33+OffsetBottom BoxWidth 16], ... + 'FontSize',10, ... + 'String','Key:',... + 'HorizontalAlignment', 'Left'); + +% Create OK Pushbutton +handles.pushbutton_OK = uicontrol('Parent',handles.figure1, ... + 'Tag', 'pushbutton_OK', ... + 'Style','Pushbutton', ... + 'Units','Pixels',... + 'Position',[PositionLeft+BoxWidth+5 10 30 23], ... + 'FontSize',10, ... + 'String','OK',... + 'HorizontalAlignment', 'Center'); + +% Create Cancel Pushbutton +handles.pushbutton_Cancel = uicontrol('Parent',handles.figure1, ... + 'Tag', 'pushbutton_Cancel', ... + 'Style','Pushbutton', ... + 'Units','Pixels',... + 'Position',[PositionLeft+BoxWidth+30+7 10 50 23], ... + 'FontSize',10, ... + 'String','Cancel',... + 'HorizontalAlignment', 'Center'); + +% Create User Name Edit Box +if ProgramOptions.enterUserName + handles.java_UserName = javax.swing.JTextField(); + handles.java_UserName.setFocusable(true); + [handles.java_UserName, handles.edit_UserName] = javacomponent(handles.java_UserName, [], handles.figure1); + + set(handles.edit_UserName, ... + 'Parent', handles.figure1, ... + 'Tag', 'edit_UserName', ... + 'Units', 'Pixels', ... + 'Position',[PositionLeft 53+OffsetBottom 200 23]); + set(handles.java_UserName, 'Text', ProgramOptions.DefaultUserName); + drawnow; % This drawnow is required to allow the focus to work + + handles.text_LabelUserName = uicontrol('Parent',handles.figure1, ... + 'Tag', 'text_LabelUserName', ... + 'Style','Text', ... + 'Units','Pixels',... + 'Position',[PositionLeft 76+OffsetBottom 200 16], ... + 'FontSize',10, ... + 'String','User name:',... + 'HorizontalAlignment', 'Left'); + + %uicontrol(handles.edit_UserName); + %set(handles.figure1,'CurrentObject',handles.java_UserName) + handles.java_UserName.requestFocus; % Get focus + drawnow; +else + handles.java_Password.requestFocus; % Get focus + drawnow; +end; + +%% Setup Callbacks for Objects +% Adds the callback functions for the objects in the GUI + +set(handles.pushbutton_OK, 'Callback', {@pushbutton_OK_Callback, handles, ProgramOptions}, 'KeyPressFcn', {@pushbutton_KeyPressFcn, handles, ProgramOptions}); +set(handles.pushbutton_Cancel, 'Callback', {@pushbutton_Cancel_Callback, handles, ProgramOptions}, 'KeyPressFcn', {@pushbutton_KeyPressFcn, handles, ProgramOptions}); +set(handles.java_Password, 'ActionPerformedCallback', {@pushbutton_OK_Callback, handles, ProgramOptions}); + +if ProgramOptions.ValidatePassword + if ProgramOptions.enterUserName + ObjectNext = handles.java_UserName; + else + ObjectNext = handles.java_Password; + end; + set(handles.java_PasswordValidate, 'ActionPerformedCallback', {@pushbutton_OK_Callback, handles, ProgramOptions}, 'NextFocusableComponent', ObjectNext); + set(handles.java_Password, 'NextFocusableComponent', handles.java_PasswordValidate); +elseif ProgramOptions.enterUserName + set(handles.java_Password, 'NextFocusableComponent', handles.java_UserName); +end; + +if ProgramOptions.enterUserName + set(handles.java_UserName, 'ActionPerformedCallback', {@pushbutton_OK_Callback, handles, ProgramOptions}, 'NextFocusableComponent', handles.java_Password); +end; + +setappdata(handles.figure1, 'isCanceled', false); + +%% Wait for Completion + +% Wait for the user to complete entry. +drawnow; +uiwait(handles.figure1); + +%% Get current information +% User either closed the window or pressed cancel or OK. + +isCanceled = ~ishandle(handles.figure1) || getappdata(handles.figure1, 'isCanceled'); +if isCanceled + if ishandle(handles.figure1) + delete(handles.figure1); + end; + Password = -1; + UserName = ''; + return; +end; + +Password = handles.java_Password.Password'; +if ProgramOptions.enterUserName + UserName = strtrim(get(handles.java_UserName, 'Text')); +else + UserName = ''; +end; +delete(handles.figure1); + +%% DEFINE FUNCTIONS +% The subfunctions required by this program are in the following section. + +function pushbutton_KeyPressFcn(hObject, eventdata, handles, ProgramOptions) + +switch eventdata.Key + case 'return' + Callback = get(hObject, 'Callback'); + feval(Callback{1}, hObject, '', Callback{2:end}); +end; + +function pushbutton_OK_Callback(hObject, eventdata, handles, ProgramOptions) +if ProgramOptions.enterUserName + % Check if username is blank + UserName = strtrim(get(handles.java_UserName, 'Text')); + if isempty(UserName) + strMessage = 'Username is blank'; + %disp(strMessage) + hError = errordlg(strMessage, 'passwordEntryDialog'); + uiwait(hError); + return; + end; +end; + +if ProgramOptions.CheckPasswordLength + %Password = handles.edit_Password.Password'; + Password = handles.java_Password.Password'; + if length(Password) < ProgramOptions.PasswordLengthMin || length(Password) > ProgramOptions.PasswordLengthMax + strMessage = sprintf('Password must be between %d and %d characters', ... + ProgramOptions.PasswordLengthMin, ... + ProgramOptions.PasswordLengthMax); + %disp(strMessage); + hError = errordlg(strMessage, 'passwordEntryDialog'); + uiwait(hError); + if ProgramOptions.ValidatePassword + set(handles.java_PasswordValidate,'Text', ''); + end; + handles.java_Password.requestFocus + return; + end; +end; + +if ProgramOptions.ValidatePassword + % Check if passwords match + if ~isequal(handles.java_Password.Password, handles.java_PasswordValidate.Password) + strMessage = 'Passwords do not match. Please try again'; + %disp(strMessage); + hError=errordlg(strMessage, 'passwordEntryDialog','modal'); + uiwait(hError); + set(handles.java_Password,'Text', ''); + set(handles.java_PasswordValidate,'Text', ''); + + handles.java_Password.requestFocus + return; + end; +end; +uiresume(handles.figure1); + +function pushbutton_Cancel_Callback(hObject, eventdata, handles, ProgramOptions) +setappdata(handles.figure1, 'isCanceled', true); +uiresume(handles.figure1); +##### SOURCE END ##### +--></body></html> \ No newline at end of file diff --git a/html/user_url_pw_inputdlg.html b/html/user_url_pw_inputdlg.html new file mode 100644 index 00000000000..3b58ecf50e7 --- /dev/null +++ b/html/user_url_pw_inputdlg.html @@ -0,0 +1,102 @@ + +<!DOCTYPE html + PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <!-- +This HTML was auto-generated from MATLAB code. +To make changes, update the MATLAB code and republish this document. + --><title>user_url_pw_inputdlg</title><meta name="generator" content="MATLAB 9.4"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2019-03-21"><meta name="DC.source" content="user_url_pw_inputdlg.m"><style type="text/css"> +html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0} + +html { min-height:100%; margin-bottom:1px; } +html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; } +html body td { vertical-align:top; text-align:left; } + +h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; } +h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; } +h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; } + +a { color:#005fce; text-decoration:none; } +a:hover { color:#005fce; text-decoration:underline; } +a:visited { color:#004aa0; text-decoration:none; } + +p { padding:0px; margin:0px 0px 20px; } +img { padding:0px; margin:0px 0px 20px; border:none; } +p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; } + +ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; } +ul li { padding:0px; margin:0px 0px 7px 0px; } +ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; } +ul li ol li { list-style:decimal; } +ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; } +ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; } +ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; } +ol li ol li { list-style-type:lower-alpha; } +ol li ul { padding-top:7px; } +ol li ul li { list-style:square; } + +.content { font-size:1.2em; line-height:140%; padding: 20px; } + +pre, code { font-size:12px; } +tt { font-size: 1.2em; } +pre { margin:0px 0px 20px; } +pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; } +pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; } +pre.error { color:red; } + +@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } } + +span.keyword { color:#0000FF } +span.comment { color:#228B22 } +span.string { color:#A020F0 } +span.untermstring { color:#B20000 } +span.syscmd { color:#B28C00 } + +.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; } +.footer p { margin:0px; } +.footer a { color:#878787; } +.footer a:hover { color:#878787; text-decoration:underline; } +.footer a:visited { color:#878787; } + +table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; } +table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; } + + + + + + </style></head><body><div class="content"><pre class="codeinput"><span class="keyword">function</span> [url, user, pw] = user_url_pw_inputdlg +<span class="comment">%user_url_pw_inputdlg</span> +<span class="comment">% Return the URL, user name and password for the openBIS server</span> + +prompt = {<span class="string">'openBIS URL:'</span>, <span class="string">'openBIS user:'</span>}; +title = <span class="string">'openBIS connection details'</span>; +definput = {<span class="string">'https://XYZ.ethz.ch/openbis:8443'</span>, <span class="string">''</span>}; +answer = inputdlg(prompt, title, 1, definput); + +url = answer{1}; +user = answer{2}; + +pw = passwordEntryDialog(<span class="string">'CheckPasswordLength'</span>,0); + +<span class="keyword">end</span> +</pre><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB® R2018a</a><br></p></div><!-- +##### SOURCE BEGIN ##### +function [url, user, pw] = user_url_pw_inputdlg +%user_url_pw_inputdlg +% Return the URL, user name and password for the openBIS server + +prompt = {'openBIS URL:', 'openBIS user:'}; +title = 'openBIS connection details'; +definput = {'https://XYZ.ethz.ch/openbis:8443', ''}; +answer = inputdlg(prompt, title, 1, definput); + +url = answer{1}; +user = answer{2}; + +pw = passwordEntryDialog('CheckPasswordLength',0); + +end +##### SOURCE END ##### +--></body></html> \ No newline at end of file diff --git a/pybis_example.ipynb b/pybis_example.ipynb index 3ef7dcd4374..e14d9d9b2fb 100644 --- a/pybis_example.ipynb +++ b/pybis_example.ipynb @@ -34,7 +34,7 @@ "metadata": {}, "outputs": [], "source": [ - "username = 'hluetcke'\n", + "username = 'h'\n", "pw = getpass.getpass()" ] }, @@ -280,7 +280,7 @@ "metadata": {}, "outputs": [], "source": [ - "experiment = o.new_experiment(type='METHODS', code='METH123456', project='/MATLAB_TEST/TEST_PROJECT')" + "experiment = o.new_experiment(type='UNKNOWN', code='EXP123456', project='/SIS_HLUETCKE/DEMO')" ] }, { @@ -297,14 +297,27 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "project = o.new_project('SIS_HLUETCKE', 'test_project', 'boring project')" + ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "project.save()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "o.get_objects('SIS_HLUETCKE/')" + ] }, { "cell_type": "markdown", @@ -433,7 +446,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/user_url_pw_inputdlg.m b/user_url_pw_inputdlg.m index 48a4af18cb1..80d294a8b45 100644 --- a/user_url_pw_inputdlg.m +++ b/user_url_pw_inputdlg.m @@ -1,4 +1,6 @@ function [url, user, pw] = user_url_pw_inputdlg +%user_url_pw_inputdlg +% Return the URL, user name and password for the openBIS server prompt = {'openBIS URL:', 'openBIS user:'}; title = 'openBIS connection details'; -- GitLab