DM script to close dialog window - user-interface

I am looking for a proper way to close a UI window.
The following code works for GMS 1.x.
Class mainUI:uiframe {
void CloseMe(object self){
DocumentWindow win=self.GetFrameWindow();
if(win.WindowIsValid()) win.WindowClose(0);
}
}
But this code crashes DigitalMicrograph consistently under GMS 2.33.

As Mike pointed out in the comment: The answer is to use dlg.Close() where dlg would be your dialog object.
Here is an example for GMS 3.2. ( See also this for GMS 3.1 )
class myDlg : UIframe
{
void OnClose( object self )
{
self.Close()
}
object InitAndLaunch( object self )
{
TagGroup dlg, dlgItems
dlg = DLGCreateDialog( "test", dlgItems )
dlgItems.DLGAddElement( DLGCreatePushButton( "Close", "OnClose" ) )
self.Init(dlg)
self.Display( "Test" )
return self
}
}
Alloc(myDLG).InitAndLaunch()

Related

Why can't Vala connect signals to delegates?

I used to think that a delegate behaves like a method reference in Vala. However, I don't understand why the following code doesn't work:
class Bar {
public signal void bar_signal();
}
class Foo : Object {
public Foo( int i, Bar bar ) {
bar.bar_signal.connect( bar_handler( i + 1 ) );
}
public delegate void Handler();
private static Handler bar_handler( int j ) {
return () =>
{
stdout.printf( "handler: %d\n", j );
};
}
}
public static void main( string[] args ) {
Bar bar = new Bar();
new Foo( 1, bar ); // will be finalized immediately
bar.bar_signal();
}
The idiom of this code is actually quite typical in JavaScript, which makes heavy use of closures. Sadly, valac says:
Test.vala:8.33-8.45: error: Argument 1: Cannot convert from Foo.Handler to Bar.bar_signal
At first, I thought that this might be due to the following incompatibility of delegate types:
Instance and static delegate instances are not interchangeable.
However, the error doesn't change if I put a static into the declaration of the delegate.
I searched the web but only came across an old mailing list entry from 2009, which says that this is a bug in Vala. Is that right? And if so: How can it be that this bug still isn't fixed, 7 years later?
It is indeed a known bug: https://bugzilla.gnome.org/show_bug.cgi?id=604781
A workaround is to invoke it using a closure:
bar.bar_signal.connect( () => { bar_handler( i + 1 ); } );

How to maximize PopupWindowAction after popup?

Can PopupWindowAction be maximized after popup? I tried to override Invoke method but it doesn't work
protected override void Invoke(object parameter)
{
...
if (this.IsModal)
{
wrapperWindow.ShowDialog();
}
else
{
wrapperWindow.Show();
}
wrapperWindow.WindowState = WindowState.Maximized;
}
But it doesn't work
I used this class, and it worked fine for me:
public class MaximizedPopupWindowAction : PopupWindowAction
{
protected override Window GetWindow( INotification notification )
{
var window = base.GetWindow( notification );
window.SizeToContent = SizeToContent.Manual;
window.SourceInitialized += ( s, e ) => window.WindowState = WindowState.Maximized;
return window;
}
}

Xamarin Android Google Places Api AutoComplete broken

I'm trying to get the basic autocomplete functionality from Google's Places Api working with Xamarin Android.
I'm using version 25.0.0.0 of Xamarin's Google Play Services - Location lib.
I've managed to get to the point of returning results of a query while following this example code
This is the Fragment I'm using to test the code
public class PlaceAutocomplete: BaseFragment, IGoogleApiClientOnConnectionFailedListener {
IGoogleApiClient client;
public override void OnCreate( Bundle savedInstanceState ) {
base.OnCreate( savedInstanceState );
client = new GoogleApiClientBuilder( Activity )
.EnableAutoManage( Activity as BaseFragmentActivity, 0, this )
.AddOnConnectionFailedListener( OnConnectionFailed )
.AddApi( Places.GEO_DATA_API )
.Build();
}
public override View OnCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
Places.GeoDataApi.GetAutocompletePredictions( client, "cul",
new LatLngBounds( new LatLng( 33.515071, -118.796427 ), new LatLng( 34.435985, -117.127371 ) ), null )
.SetResultCallback<AutocompletePredictionBuffer>( AutocompleteResult );
return base.OnCreateView( inflater, container, savedInstanceState );
}
public void AutocompleteResult( AutocompletePredictionBuffer buffer ) {
if( !buffer.Status.IsSuccess ) {
Toast.MakeText( Activity, buffer.Status.StatusMessage, ToastLength.Long ).Show();
return;
}
var a = new List<IAutocompletePrediction>();
for( var i = 0; i < buffer.Count; i++ ) {
var item = buffer.Get( i );
if( item is IAutocompletePrediction ) {
a.Add( (IAutocompletePrediction) item );
} else {
//all the results go in here
}
}
Toast.MakeText( Activity, a.Count.ToString(), ToastLength.Long ).Show();
}
public void OnConnectionFailed( ConnectionResult result ) {
}
}
There are 5 returned results from GetAutocompletePredictions method but all of them of type named com.google.android.gms.location.places.internal.zzb, cannot be cast to IAutocompletePrediction and I did not find any way to use them.
Did I do something wrong or this part of Xamarin's Google Play library is not fully implemented?
Edit - New Information
This is not a bug. The IAutocompletePrediction is not currently implemented by Xamarin so you must cast it like this
item.JavaCast<IAutocompletePrediction>()
in order to use it.
Older informaton
I've talked to Xamarin Support and they've confirmed that this is a bug.
More info on the bug fix can be found here https://bugzilla.xamarin.com/show_bug.cgi?id=31878
As of
Xamarin 4.0.0.1717 /
Xamarin.Android 6.0.0.35 /
Xamarin Google Play Services Location component v 27.0.0.0
, it seems there's been a bit of work in this space.
The IEnumerable interface now provides a way to get a typed response, and the following snippet (replacing part of AutocompleteResult) works:
var a = new List<IAutocompletePrediction>();
String t = "";
foreach (IAutocompletePrediction x in buffer)
{
a.Add(x);
t += "\n" + x.GetFullTextFormatted(new StyleSpan(TypefaceStyle.Normal)).ToString();
}
Toast.MakeText(Activity, t /* a.Count.ToString() */, ToastLength.Long).Show();

QML Loader not shows changes on .qml file

I have main.qml and dynamic.qml files that i want to load dynamic.qml on main.qml using Loader {}.
Content of dynamic.qml file is dynamic and another program may change its content and overwrite it.
So i wrote some C++ code for detecting changes on file and fires Signal.
My problem is that I don't know how can i force Loader to reload file.
This is my current work:
MainController {
id: mainController
onInstallationHelpChanged: {
helpLoader.source = "";
helpLoader.source = "../dynamic.qml";
}
}
Loader {
id: helpLoader
anchors.fill: parent
anchors.margins: 60
source: "../dynamic.qml"
}
I think that QML Engine caches dynamic.qml file. So whenever I want to reload Loader, it shows old content. Any suggestion?
You need to call trimComponentCache() on QQmlEngine after you have set the Loaders source property to an empty string. In other words:
helpLoader.source = "";
// call trimComponentCache() here!!!
helpLoader.source = "../dynamic.qml";
In order to do that, you'll need to expose some C++ object to QML which has a reference to your QQmlEngine (lots of examples in Qt and on StackOverflow to help with that).
trimComponentCache tells QML to forget about all the components it's not current using and does just what you want.
Update - explaining in a bit more detail:
For example, somewhere you define a class that takes a pointer to your QQmlEngine and exposes the trimComponentCache method:
class ComponentCacheManager : public QObject {
Q_OBJECT
public:
ComponentCacheManager(QQmlEngine *engine) : engine(engine) { }
Q_INVOKABLE void trim() { engine->trimComponentCache(); }
private:
QQmlEngine *engine;
};
Then when you create your QQuickView, bind one of the above as a context property:
QQuickView *view = new QQuickView(...);
...
view->rootContext()->setContextProperty(QStringLiteral("componentCache", new ComponentCacheManager(view->engine());
Then in your QML you can do something like:
helpLoader.source = "";
componentCache.trim();
helpLoader.source = "../dynamic.qml";
I was hoping for a pure QML solution. I noticed that loader.source is a url (file:///) and remembered how with HTML, you can avoid HTTP caching using ?t=Date.now() in your requests. Tried adding ?t=1234 to the end of loader.source, and sure enough, it works.
import QtQuick 2.0
Item {
Loader {
id: loader
anchors.fill: parent
property string filename: "User.qml"
source: filename
function reload() {
source = filename + "?t=" + Date.now()
}
}
Timer {
id: reloadTimer
interval: 2000
repeat: true
running: true
onTriggered: {
loader.reload();
}
}
}
I also wrote another example that will check for changes in the file contents before triggering a reload using an XMLHttpRequest.
import QtQuick 2.0
Item {
Loader {
id: loader
anchors.fill: parent
property string filename: "AppletUser.qml"
property string fileContents: ""
source: ""
function reload() {
source = filename + "?t=" + Date.now()
}
function checkForChange() {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4) {
if (loader.fileContents != req.responseText) {
loader.fileContents = req.responseText;
loader.reload();
}
}
}
req.open("GET", loader.filename, true);
req.send();
}
onLoaded: {
console.log(source)
}
Timer {
id: reloadTimer
interval: 2000
repeat: true
running: true
onTriggered: loader.checkForChange()
}
Component.onCompleted: {
loader.checkForChange()
}
}
}

Silently use Microsoft XPS Document Writer printer to create XPS

For some days now I've been battling with printing XPS to file without the dialog.
I've read posts on the matter in CodeGuru and by Feng Yuan (MSDN), along with many discussion topics here and I am still lost.
Specifically my scenario is that I have a 3rd party API that I must use, and it prints to the default printer (say Microsoft XPS Document Writer). I want to be able to "apply" a filename prior to the printing procedure, and of course not to have dialog.
I've tried working with WinDDK - XPSDRV and LOCALMON samples but wasn't able to figure out exactly how to manipulate the code to achieve my goals. (or even fully understand if I need a new printer driver or a new port type)
I ran into the same need. Following is some of the logic that provides the desired functionality for me:
//
// PrintDocument_inst
//
this.PrintDocument_inst.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.k_line_PrintPage);
private void Print( string align_file_name )
{
if ( plot_metafile == null )
{
MessageBox.Show( "you need to load offset data before printing a plot" );
return;
}
try
{
PrintDocument_inst.DefaultPageSettings = PageSettings_inst;
PrintDialog_inst = new PrintDialog( );
PrintDialog_inst.Document = PrintDocument_inst;
PrintDialog_inst.UseEXDialog = true; // this must be set true or dialog won't show on 64 bit Vista
PrintDialog_inst.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
PrintDialog_inst.PrinterSettings.PrintToFile = true;
PrintDialog_inst.PrinterSettings.PrintFileName = align_file_name;
i_page_to_print_next = 1;
n_pages_still_to_print = 1;
PrintDocument_inst.Print( );
}
catch ( Exception e )
{
MessageBox.Show( e.ToString( ) );
}
finally
{
}
} // end of function Print( string align_file_name )
//PrintPage event handler
private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)
{
int leftMargin = ppea.MarginBounds.Left;
int topMargin = ppea.MarginBounds.Top ;
try
{
float _scale_f;
if ( PrintDialog_inst != null )
{
string str_printer_name = PrintDialog_inst.PrinterSettings.PrinterName.ToString ( );
if ( str_printer_name.CompareTo ( "Adobe PDF" ) == 0 )
{
_scale_f = 0.61F; // 0.85F;
}
else
{
_scale_f = 0.59F; // 0.82F;
}
}
else // case of print preview
{
_scale_f = 0.59F; // 0.82F;
}
if ( _scale_f != 1.0F ) ppea.Graphics.ScaleTransform ( _scale_f, _scale_f );
ppea.Graphics.DrawImage ( plot_metafile, leftMargin, topMargin );
ppea.HasMorePages = ( --n_pages_still_to_print > 0 ? true : false );
}
finally
{
}
} // end of private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)
You will delete filters in pipeline xml and also related dll's in inf file. But yet, as I did, i guess you will face problem of printing canvas (graphics). I wasn't able to convert / transform this canvas to glyphs to get the contents of it.
If you had further issues, let me know
Kind Regards

Resources