I create an executable based on a gui with several functions and files, and if I open the executable in the installation folder or using the desktop shortcut everything works fine. If I open through the starting menu, the executable doesn't incorporate the images and doesn’t run. What I can do to prevent this issue? Is it possible to prevent the shortcut in the windows starting menu?
I found a solution here:
You can use the following function to get the folder of the executed exe file:
function currentDir = getcurrentdir()
if isdeployed % Stand-alone mode.
[status, result] = system('path');
currentDir = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % MATLAB mode.
currentDir = pwd;
end
Call the function and use cd in the GUI opening function:
currentDir = getcurrentdir();
cd(currentDir);
I created a guide testing application, and used deploytool for compiling and packaging for external deployment.
For testing, I added a text label to the GUI (Tag name: text2).
In the GUI opening function I added the following code:
% --- Executes just before GuideApp is made visible.
function GuideApp_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.text2.String = 'Starting...';
pause(1);
currentDir = getcurrentdir();
%Set the label's text to display currentDir.
handles.text2.String = currentDir;
%Change directory to the directory of the exe file.
cd(currentDir);
%Create a file in the directory (just for testing):
f = fopen('currentDir.txt', 'w');fprintf(f, '%s\r\n', currentDir);fclose(f);
% Update handles structure
guidata(hObject, handles);
The above solution is working correctly:
The text of label displays the path of the exe file.
currentDir.txt file is created in the path of the exe file.
Related
I have a Xamarin application running on Windows, and I have a method which includes an opening of a pdf file like this:
var psi = new ProcessStartInfo
{
FileName = "cmd",
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
CreateNoWindow = true,
Arguments = $"/c start {filename}"
};
Process.Start(psi);
When this executes, the windows opens a dialog with the following message:
Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.
The filename is a pdf file located in the LocalApplicationData, and I also have a database there, and the application is normally creating a database there and manipulates with it, so it should have a permission to access that folder. Also, when I run that pdf with double-click outside the application, the pdf opens normally with Chrome. How to solve this?
Unless you have a file there called "cmd" this won't work, as you have declared your filename as a string with the value "cmd".
Is it possible to use the GUI library in JythonMusic to create an open/save file dialog. If not is it possible to use an open file window in Tkinter or PyQT in conjunction with jythonMusic?
JythonMusic's GUI library is built on top of Java Swing. So, in principle, you can access all Swing functionality.
The code below does what you ask (and demonstrates the approach).
Do notice how readable the code is, compared to the Java original - http://www.java2s.com/Code/Java/Swing-JFC/DemonstrationofFiledialogboxes.htm
This is partially due to the economy of Python syntax, but also due to the JythonMusic GUI library, which was designed to simplify GUI creation (for most tasks).
# openFileDialogDemo.py
#
# Demonstrates how to create an open/save file dialog in Jython Music.
#
# Based on http://www.java2s.com/Code/Java/Swing-JFC/DemonstrationofFiledialogboxes.htm
#
from gui import *
# create display to hold open button
d = Display("Open Dialog Demo", 200, 50)
filename = None # holds selected filename (if any)
directory = None # holds directory of selected filename (if any)
# set up what to do when open button is pressed
def openButtonAction():
global filename, directory # we will update these
chooser = JFileChooser() # the open dialog window
# here is the only tricky part - accessing the GUI Display's internal JFrame, d.display
returnValue = chooser.showOpenDialog( d.display )
# check what choice user made, and act appropriately
if returnValue == JFileChooser.APPROVE_OPTION:
filename = chooser.getSelectedFile().getName()
directory = chooser.getCurrentDirectory().toString()
print "Filename =", filename
print "Directory =", directory
elif returnValue == JFileChooser.CANCEL_OPTION:
print "You pressed cancel"
# create open button and add it to display
openButton = Button("Open", openButtonAction)
d.add(openButton, 70, 12)
Hope this helps.
In Xcode 7, you can create 'Run Script' phases in the Build Phases tab. At the bottom of the area, there's an 'Input Files' section and an 'Output Files' section.
I have a script that generates a .cpp file at $(DERIVED_FILE_DIR)/myfile.cpp. The file is listed in the 'Output Files' section of the phase. However, it appears that it's not compiled into my program, as the symbol that it defines are identified as missing by the linker.
How can I tell Xcode to compile this file as well?
One possible solution (which feels like a hack) is to insert the built file into the project, set its location (in the Identity and Type section of the Utilities bar) and then edit its location in the project file with a text editor for computer independence. In my case, the file entry (with newlines for readability) now looks like:
DC40C4121C7FC98F0087702A /* bindings.cpp */ = {
isa = PBXFileReference;
lastKnownFileType = sourcecode.cpp.cpp;
name = myfile.cpp;
path = "$(DERIVED_FILE_DIR)/myfile.cpp";
sourceTree = "<absolute>";
};
This is interpreted by the file browser as a file whose absolute path is literally $(DERIVED_FILE_DIR)/myfile.cpp (and the file always shows in red in the project explorer), but the build system will grab the file from the correct location.
I want to create short cut for my executable in windows startup menu. I can get the startup folder path and my executable full path but it seems I can use QFile::link() but I don't know how can create that in the startup folder?
QString starupFolder = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Startup";
QString appPath = qApp->applicationDirPath() + "/DataSync.exe";
Now I could possibly do this:
QFile file;
file.setFileName( appPath );
file.link("DataApp");
Maybe I am rusty today but how do I actually save/create the link like on file system and specially to startup menu in windows?
I try to create "Save as..." dialog in Mac OS X. But I don't want to use QFileDialog::getSaveFileName() function, because dialog that created by this function is NOT truly-native in Mac OS X Lion. So I decide to create dialog as QFileDialog object:
auto export_dialog( new QFileDialog( main_window ) );
export_dialog->setWindowModality( Qt::WindowModal );
export_dialog->setFileMode( QFileDialog::AnyFile );
export_dialog->setAcceptMode( QFileDialog::AcceptSave );
All works fine, except one problem. I cannot set default name for saved file, so user must type this name manually every time. I know that function QFileDialog::getSaveFileName() allows to set default filename via third argument, dir (http://qt-project.org/doc/qt-4.8/qfiledialog.html#getSaveFileName). But how to set this default name without this function?
I can set default suffix for saved file via QFileDialog::setDefaultSuffix() function, but I need to set whole default name, not only default suffix.
I've tried to use QFileDialog::setDirectory() function, but it sets only directory where to save, without name of saved file.
I use Qt 4.8.1 on Mac OS X Lion.
I have found that using selectFile("myFileName"); only works if the file actually exists. In my case, the intent is to create a new file with the option of overwriting an existing file.
The solution that worked for me (Qt 5.3.2) was as follows:
QFileDialog svDlg;
QString saveFileName = svDlg.getSaveFileName(this, caption, preferredName, filter);
In the above example, preferredName is a QString that contains "C:/pre-selected-name.txt"
Restating what was in the comments for future visitors, the following line puts "myFileName" as the default name in the QFileDialog:
export_dialog->selectFile("myFileName");
Discussion: http://www.qtcentre.org/threads/49434-QFileDialog-set-default-name?highlight=QFileDialog
Not-so-helpful docs: http://qt-project.org/doc/qt-4.8/qfiledialog.html#selectFile
QString dir = QDir::homePath();
QString name = "test.txt";
QFileDialog::getSaveFileName(nullptr, tr("save file"), dir + "/" + name, tr("TXT (*.txt)"));
If you set "dir" argument, and dir is "file"(exist or not), in windows you will have default name.
With the current QT-version (5.x) you can set your preferred file-name with the argument directory in the QFileDialog.getSaveFileName() function call:
QFileDialog.getSaveFileName( directory = 'preferredFileName.txt' )
docs: http://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName