0001 function sqlResultsGUI(results, fields, query)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 leftMargin = 10;
0013 bottomMargin = 100;
0014 topMargin = 20;
0015
0016 btnHeight = 20;
0017 btnWidth = 60;
0018 btnGap = 20;
0019
0020 Color = [240 240 240]/255;
0021 Height = 600;
0022 Width = 800;
0023
0024 Screen = get(0,'screensize');
0025 Position = [Screen(3)/2 - Width/2 Screen(4)/2-Height/2 Width Height];
0026
0027
0028 gui.main = figure('HandleVisibility','on',...
0029 'IntegerHandle','off',...
0030 'Menubar','none',...
0031 'NumberTitle','off',...
0032 'Name','Query Results',...
0033 'Tag','main',...
0034 'Color',Color,...
0035 'Resize', 'off',...
0036 'Position',Position);
0037
0038
0039
0040 Tleft = leftMargin;
0041 Twidth = Width - 2*leftMargin;
0042 Theight = 100;
0043 Tbottom = Position(4) - Theight - 20;
0044 sth = uicontrol(gui.main,'Style','text',...
0045 'String',query,...
0046 'Fontsize', 14,...
0047 'BackgroundColor',Color,...
0048 'HorizontalAlignment', 'left',...
0049 'Position',[Tleft Tbottom Twidth Theight]);
0050
0051
0052
0053 Tleft = leftMargin;
0054 Twidth = Width - 2*leftMargin;
0055 Theight = 400;
0056 Tbottom = 100;
0057 t = muitable(gui.main, results, fields, 'Position',...
0058 [Tleft Tbottom Twidth Theight]);
0059 set(t, 'Editable', 0);
0060
0061 get(gui.main)
0062 setappdata(gui.main, 'table', t);
0063
0064
0065
0066 btn = uicontrol(gui.main,...
0067 'Style','pushbutton',...
0068 'String','Export',...
0069 'Tag', 'exportBtn',...
0070 'Callback', {@exportBtn_Callback, gui, results, fields}, ...
0071 'Position',[leftMargin leftMargin btnWidth btnHeight]);
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 function exportBtn_Callback(hObject, eventdata, gui, results, fields)
0082
0083
0084 t = getappdata(gui.main, 'table');
0085 table = get(t.Table);
0086
0087 rows = table.SelectedRows + 1;
0088 cols = table.SelectedColumns + 1;
0089 res = results(rows, cols);
0090 nResults = size(res, 1);
0091
0092
0093 [filename, pathname, filteridx] = uiputfile('*.txt', 'Select export file');
0094
0095 fd = fopen(filename, 'w+');
0096
0097
0098 fprintf(fd, '# ');
0099 fprintf(fd, '%s\t|\t', fields{cols});
0100 fprintf(fd, '\n');
0101
0102
0103 for j=1:nResults
0104 for k=1:size(res,2)
0105 r = res{j,k};
0106 if ischar(r)
0107 fprintf(fd, '%s\t\t', char(r));
0108 elseif isnumeric(r)
0109 fprintf(fd, '%f\t\t', r);
0110 else
0111 error('### Unknown data format.');
0112 end
0113 end
0114 fprintf(fd, '\n');
0115 end
0116 fclose(fd);
0117
0118 edit(filename);
0119
0120
0121
0122 function resizeMain(hObject, eventdata, leftMargin, bottomMargin, topMargin)
0123
0124
0125 t = getappdata(hObject, 'table');
0126 fs = get(hObject, 'Position');
0127 pos = get(t, 'Position');
0128
0129 set(t, 'Position', [pos(1) pos(2) fs(3)-2*leftMargin fs(4)-bottomMargin-topMargin]);
0130
0131
0132