Single dialog for "open file" and "create new document" - qt

Is it possible to use some form of QFileDialog to get a native (MacOS) dialog like the one below, where besides selecting a file, the user can choose to create a new document? I believe I have read all available documentation on the topic, but I could not find an answer.
(Note: This is the initial pick-a-file-or-create-a-new-one from Keynote. I am trying to replicate this behaviour).
EDIT As requested, I include some code. THis is standard pyqt5 boilerplate.
import PyQt5
from PyQt5.QtWidgets import QApplication, QFileDialog
app = QApplication(sys.argv)
filedialog = QFileDialog(None)
filedialog.setDefaultSuffix("texd")
filedialog.setNameFilter("TeX Document Bundle (*.texd);; TeX Template Bundle (*.textemplate)")
filedialog.setOption(QFileDialog.ReadOnly)
selected = filedialog.exec()
if selected:
filename = filedialog.selectedFiles()[0]
print(filename)
print(selected)
return

Related

Got "Run-time error '31602'" when running DoCmd.RunSavedImportExport

Try to create an one-click button to import multiple tables from Oracle. Following is the code behind the On Click event of the button (with one table for now):
Private Sub Command0_Click()
If Not IsNull(DLookup("Name", "MSysObjects", "Name='FCR_LABOR_COST_SUMMARY1'")) Then
DoCmd.DeleteObject acTable, "FCR_LABOR_COST_SUMMARY1"
End If
DoCmd.RunSavedImportExport ("Import-FCR_LABOR_COST_SUMMARY1")
End Sub
Encountered the an error "Run-time '31602': The specification with the specified index does not exist. Specify a different index. 'Import-FCR_LABOR_COST_SUMMARY1'." when running "DoCmd.RunSavedImportExport"
The source table does not have any index on it. No need to have any index on the target table. Look like Access is trying to enforce an index on the target table. Is there anyway to turn this off? I'm new to Access and VB, please provide advice and directions on how to resolve this. Thanks.
To save a specication follow this document:
Create an import or export specification
1. Start the import or export operation from Access.
2. The import and export wizards are available on the External Data tab. The import wizards are in the Import & Link group, and the export wizards are in the Export group.
3. Follow the instructions in the wizard. After you click OK or Finish, and if Access successfully completes the operation, the Save Import Steps or Save Export Steps page appears in the wizard.
4. On the wizard page, click Save import steps or Save export steps to save the details of the operation as a specification.
5. Access displays an additional set of controls. This figure shows the dialog box with those controls available.
6. The Save Import Steps dialog box
In the Save as box, type a name for the specification.
In the Description box, type a description to help you or other users identify the operation at a later time.
7. To create an Outlook task that reminds you when it is time to repeat this operation, click Create Outlook Task.
8. Click Save Import or Save Export to save the specification. Access creates and stores the specification in the current database.
9. If you clicked Create Outlook Task on either the Save Import Steps or Save Export Steps page of the wizard, an Outlook Task window appears. Fill in the details of the task and then click Save & Close.
If the saved import or export specification you choose for the Saved Import Export Name argument is deleted after the macro is created, Access displays the following error message when the macro is run:
The specification with the specified index does not exist. Specify a different index. 'specification name'.
From: https://support.office.com/en-us/article/runsavedimportexport-macro-action-41c366d8-524e-4c7e-847d-c2cf7abb2049

Pre-compile QML files under Qt Quick Controls

I am importing 2 QML files that come with Qt Controls - ScrollBar.qml and Button.qml in my project. I pre-compile all .qml files that I wrote to reduce application launch time. Is there a way to pre-compile these 2 QML files that come as part of the package?
I tried to remove these files from the qml/QtQuick/Controls/ path and placed them in the same folder as my .qml files but it still failed to load. When I reference ScrollBar in my code, it always tries to load ScrollBar.qml from qml/QtQuick/Controls/ path.
Does any one know if it is possible to pre-compile these QMLs at all? If yes, has any one successfully done it?
Appreciate any help. Thank you.
I'm assuming that you're referring to the Qt Quick Compiler as pre-compiling. The simplest way would just be to build the entire Qt Quick Controls module with the Qt Quick Compiler.
If you need to have it within your project, you could try adding an import that contains the Qt Quick Controls import. QQmlEngine::addImportPath() says:
The newly added path will be first in the importPathList().
That statement seems to imply that order matters, and the code confirms it:
QStringList localImportPaths = database->importPathList(QQmlImportDatabase::Local);
// Search local import paths for a matching version
const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(uri, localImportPaths, vmaj, vmin);
for (const QString &qmldirPath : qmlDirPaths) {
QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
if (!absoluteFilePath.isEmpty()) {
QString url;
const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1);
if (absolutePath.at(0) == Colon)
url = QLatin1String("qrc://") + absolutePath.mid(1);
else
url = QUrl::fromLocalFile(absolutePath.toString()).toString();
QQmlImportDatabase::QmldirCache *cache = new QQmlImportDatabase::QmldirCache;
cache->versionMajor = vmaj;
cache->versionMinor = vmin;
cache->qmldirFilePath = absoluteFilePath;
cache->qmldirPathUrl = url;
cache->next = cacheHead;
database->qmldirCache.insert(uri, cache);
*outQmldirFilePath = absoluteFilePath;
*outQmldirPathUrl = url;
return true;
}
}
Your project structure might look something like this:
myproject/
qml/
main.qml
QtQuick/
Controls/
Button.qml
ScrollBar.qml
qmldir
In main.cpp you'd set the path to the qml directory (note that the path will be different depending on whether you're doing an in-source build or a shadow build of your project, so you may want to use a resource file to simplify things):
engine.addImportPath("path/to/qml");
Note that the controls import other types. For example, Button uses the Settings singleton, which comes from the QtQuick.Controls.Private import, so you'd need to copy that into the qml directory, too. Settings loads a certain style for the button (ButtonStyle), which could be any of the styles in this folder, depending on which style is in use.
In short, you need to copy all of the potential dependencies of the QML files you're using.

Folder browser dialog in Qt

Is there any way to open a folder browser dialog in Qt? When I use QFileDialog with Directory file mode, even if I specify the ShowDirsOnly option, I get the standard file dialog. I would prefer to use a dialog that asks the user to choose a directory from a directory tree.
Here's the PySide code I'm using:
from PySide import QtGui
app = QtGui.QApplication([])
dialog = QtGui.QFileDialog()
dialog.setFileMode(QtGui.QFileDialog.Directory)
dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
dialog.exec_()
And here's the result I get on Windows 7:
It appears that the order in which you call setFileMode() and setOption() matters. Make sure you're calling setFileMode() first:
QFileDialog dialog;
dialog.setFileMode(QFileDialog::Directory);
dialog.setOption(QFileDialog::ShowDirsOnly);
...
I know, that my answer is some tricky and looks like little hack, but the QFileDialog static methods like getExistingDirectory() use the native dialog, so only limited customization is possible.
However, if you create a QFileDialog instance, you get a dialog that can
be customized -- as long as you're happy messing with a live dialog.
For example, this should show a tree view with expandable directories that
you can select (hope, it must be not a problem port this code to PySide):
QFileDialog *fd = new QFileDialog;
QTreeView *tree = fd->findChild <QTreeView*>();
tree->setRootIsDecorated(true);
tree->setItemsExpandable(true);
fd->setFileMode(QFileDialog::Directory);
fd->setOption(QFileDialog::ShowDirsOnly);
fd->setViewMode(QFileDialog::Detail);
int result = fd->exec();
QString directory;
if (result)
{
directory = fd->selectedFiles()[0];
qDebug()<<directory;
}
Got that method from here
Try this line of code, it show you a folder browse dialog:
ui->txtSaveAddress->setText(folderDlg.getExistingDirectory(0,"Caption",QString(),QFileDialog::ShowDirsOnly));
This worked for me:
def getDir(self):
dialog = QtGui.QFileDialog()
dialog.setFileMode(QtGui.QFileDialog.Directory)
dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
directory = dialog.getExistingDirectory(self, 'Choose Directory', os.path.curdir)

SQLite Database and TLF Text in Flash CS5

I encountered the following problem when working with the built-in sqlite database and using TLF TextFields in Flash CS5
When I tried to use TLF TextFields alone, I don't face any probelem,
but when I start using a database connectivity code, the TLF TextFields placed on the stage are not shown, but instead, the SWF file is showing the built-in preloader with five dots looping.
I tried changing the default Linkage in ActionScript 3 Settings to Merge Mode, but in this case nothing is shown, not the textfields, neither the preloader.
I think the problem is related to loading the TLF Text Engine, but I couldn't figure out what to do.
The following is my code placed in first frame:
==========================================
import flash.data.SQLConnection;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;
var conn:SQLConnection = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openHandler);
conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);
// The database file is in the application directory
var folder:File = File.applicationDirectory;
var dbFile:File = folder.resolvePath("DBSample.db");
conn.openAsync(dbFile);
function openHandler(event:SQLEvent):void
{
trace("the database was created successfully");
}
function errorHandler(event:SQLErrorEvent):void
{
trace("Error message:", event.error.message);
trace("Details:", event.error.details);
}
stop();
==========================================
and I am using one TLF TextField on the stage for later use.
Publish Settings>> Player: AIR 2.6
The file textLayout_2.0.0.232.swz exists in the same appication directory.
and not to forget, when I test the file using Contol Panel >> Test in Air Debug Launcher (Desktop) the file is working correctly.
but when I open the generated SWF file, the problem appears.
I already reviewed many articles but no one is closed to this problem.
I hope that I find some help
Thanks.

How to enter the text in the Text Field in Android Emulator Using Monkey runner

I am using monkey runner.
I have on Screen 1 and I need to fill the form of the page and submit.
I need to take the focus to the first field and need to enter the text.
How to give the focus to any text field or can i type any way?
Please let me know..
REgards,
Chandra
Yes, one can focus on a text field and type text in that field.
I did it using Python. Followings are relevant lines from my code:
import os, subprocess
import sys
import time
import random
import string
import re
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
#connect to the device
device = MonkeyRunner.waitForConnection(99, "emulator-5554")
Then, launch the relevant activity and move to the text field using the press function.
device.press ('KEYCODE_DPAD_DOWN', MonkeyDevice.DOWN_AND_UP)# move down
Normally, when you reach a text field then focus is already there, but if it is not then click the field.
device.press ('KEYCODE_DPAD_CENTER', MonkeyDevice.DOWN_AND_UP)#click the field
Now, one can type the text using the type function.
device.type('text')

Resources