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', 'on',...
0036 'Position',Position,...
0037 'ResizeFcn', {@resizeMain, leftMargin, bottomMargin, topMargin});
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 setappdata(gui.main, 'table', t);
0062
0063
0064
0065 btn = uicontrol(gui.main,...
0066 'Style','pushbutton',...
0067 'String','Export',...
0068 'Tag', 'exportBtn',...
0069 'Callback', {@exportBtn_Callback, gui, results, fields}, ...
0070 'Position',[leftMargin leftMargin btnWidth btnHeight]);
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 function exportBtn_Callback(hObject, eventdata, gui, results, fields)
0081
0082
0083 t = getappdata(gui.main, 'table');
0084 table = get(t.Table);
0085
0086 rows = table.SelectedRows + 1;
0087 cols = table.SelectedColumns + 1;
0088 res = results(rows, cols);
0089 nResults = size(res, 1);
0090
0091
0092 [filename, pathname, filteridx] = uiputfile('*.txt', 'Select export file');
0093
0094 fd = fopen(filename, 'w+');
0095
0096
0097 fprintf(fd, '# ');
0098 fprintf(fd, '%s\t|\t', fields{cols});
0099 fprintf(fd, '\n');
0100
0101
0102 for j=1:nResults
0103 for k=1:size(res,2)
0104 r = res{j,k};
0105 if ischar(r)
0106 fprintf(fd, '%s\t\t', char(r));
0107 elseif isnumeric(r)
0108 fprintf(fd, '%f\t\t', r);
0109 else
0110 error('### Unknown data format.');
0111 end
0112 end
0113 fprintf(fd, '\n');
0114 end
0115 fclose(fd);
0116
0117 edit(filename);
0118
0119
0120
0121 function resizeMain(hObject, eventdata, leftMargin, bottomMargin, topMargin)
0122
0123
0124 t = getappdata(hObject, 'table');
0125 fs = get(hObject, 'Position');
0126 pos = get(t, 'Position');
0127
0128 set(t, 'Position', [pos(1) pos(2) fs(3)-2*leftMargin fs(4)-bottomMargin-topMargin]);
0129
0130
0131