Can't create an roSGScreen object in Brightscript - oop

I am trying to create another screen and show it when the user clicks a button
sub showLiveScreen()
print "Attempting to show the live screen"
screen2 = CreateObject("roSGScreen")
m.port2 = CreateObject("roMessagePort")
screen2.setMessagePort(m.port2) 'screen2 is invalid
scene2 = screen2.CreateScene("LiveScene")
screen2.show()
while(true)
msg = wait(0, m.port2)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then return
end if
end while
end sub
But it won't allow me to create a roSGScreen object here, even though this works in my main. What could I be doing wrong?

Creating a new Screen this way is only necessary if You are using non-SceneGraph SDK(which is old SDK and I don't recommend using it).
On the other hand, You can only create a new screen insade your main thread! You can't create a new screen from render/SceneGraph thread and from what I understand that's what you are trying to do.

Related

UWP - Validation on ContentDialog's PrimaryButtonClick?

My ContentDialog is styled like a login form. It verifies password via connection thru SQLite. So in the Primary button's auto-generated Click event I have something like below (I made it Async btw):
Dim deferral As ContentDialogButtonClickDeferral = args.GetDeferral
If Await conn.Table(Of UserAccount).Where(Function(a) a.Username = UsernameTextBox.Text).CountAsync = 0 Then
args.Cancel = True
Dim x As New Windows.UI.Popups.MessageDialog("Username does not exist!")
Await x.ShowAsync
Else
'Other conditions
End If
deferral.Complete()
Some researching got me to think the Deferral is needed for Async situations (to no avail). Currently, with the above code I am getting a Reflection.TargetInvocationException on the Await line.
What I want to achieve is display a MessageDialog if username does not exist; the ContentDialog remaining onscreen for the user to correct himself.
Thanks!
Replace the "UsernameTextBox.Text" with a hardcoded value and it should work.
Maybe bind the textbox with a TwoWay mode into a variable and then use that variable in that statement.

Checking values in a parent object

Recently, I have been working on a game project and decided to learn how to make a gui from scratch in love2d while I was at it. I decided to use OOP where I had menu objects and button objects within the menu objects. I had a problem where I only wanted to draw the buttons only if the menu was active. The easiest/best way to do this is probably to have a function in the menu object that checks if the menu is active and draw the buttons if it is like this...
menu = {
-- menu stuff
button = require("path")
active = false,
buttons = {}
}
function menu.newButton()
--create new button object from button table
end
function menu:drawButton()
if self.active then
for k,v in pairs(buttons)
menu.buttons[k]:draw() -- some draw function that sets the size, pos, and color of the button
end
end
end
This got me wondering though. Is there some way to check values in the menu's table from a function located in the button's table?
You can use composition to access properties of Menu object from a Button. To do that you would need to pass a reference to the menu object when constructing every new Button. For instance:
Button = {}
function Button.new (menu)
return setmetatable({menu = menu}, {__index = Button})
end
function Button:getMenuName()
return self.menu.name
end
menu = {
name = "menu1",
buttons = {},
}
function menu:newButton ()
local button = Button.new(self)
table.insert(self.buttons, button)
return button
end
local btn = menu:newButton()
print(btn:getMenuName())
Would print the property name of menu from object btn.

appcelerator how close the window of index from another window

everyone
I am using titanium with alloy, I have two windows which are index.js and main.js.
The window of index.js will be opened when the app run, there is a button in index, main will be opened if someone click the button. Main have another button which is used to close the index.
As you see, I am trying to close index window in main window.
Everything works fine in IOS, but when I test it in Android, I found a strange problem: when I click the button in main.js to close index window, all windows(both of index and main) are closed.
I tried many methods, like use Ti.APP.trigger/Ti.APP.addEventListener and send $.index or a callback function to main.js.
Could anyone help me, thanks.
in index.js use this
$.index.exitOnClose = false
Your solution is to set this property : exitOnClose = false as answered by #genocsb. It's available only on Android.
Actually, this property tells that which window should close the app upon closing the window itself. So, by default, the very first window has the its property exitOnClose = true.
In your case, do something like this:
- index.js
Alloy.Globals.Index = $.index;
Alloy.Globals.Index.open();
// If you will do this and press back button on index screen, then you will land to splash screen.
// Alloy.Globals.Index.exitOnClose = false;
- main.js
$.button.addEventListener('click', function (){
$.main.exitOnClose = true; // setting it to true will cause your app to close from main.xml screen on back button press
Alloy.Globals.Index.exitOnClose = false; // setting it to false here will ensure that you will not land to splash screen if back button is pressed.
Alloy.Globals.Index.close();
Alloy.Globals.Index = null;
});

Windows Store App Search Contract Blank Screen

I recently added the search contract to my app. It is working great! But, whenever I search in the app when it is not running, it only starts with a blank screen. I did the part to add search results even in OnSearchActivated method. But even if I remove the code that I added, the blank screen persists. I created a blank project and added the search contract to it. And it is working in it even when the app is not running. The issue seems to be with my app only. I cannot debug it because it is something that runs when the app is not even running. Tell me a solution.
Code in OnSearchActivated and OnLaunched
Protected Overrides Async Sub OnSearchActivated(args As Windows.ApplicationModel.Activation.SearchActivatedEventArgs)
Dim previousContent As UIElement = Window.Current.Content
Dim frame As Frame = TryCast(previousContent, Frame)
If frame Is Nothing Then
frame = New Frame
Common.SuspensionManager.RegisterFrame(frame, "AppFrame")
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
Try
Await Common.SuspensionManager.RestoreAsync()
Catch ex As Common.SuspensionManagerException
End Try
End If
End If
frame.Navigate(GetType(SearchResultsPage1), args.QueryText)
Window.Current.Content = frame
Window.Current.Activate()
End Sub
Protected Overrides Async Sub OnLaunched(args As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
AddHandler SearchPane.GetForCurrentView.SuggestionsRequested, AddressOf OnSearchPaneSuggestionsRequested
'Contains definition of arrays ExNam, ExAbbr, ExInst, etc. removed from here to shorten the code and focus on its logic
If rootFrame Is Nothing Then
rootFrame = New Frame()
Train_Thy_Brain.Common.SuspensionManager.RegisterFrame(rootFrame, "appFrame")
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
Await Train_Thy_Brain.Common.SuspensionManager.RestoreAsync()
End If
Window.Current.Content = rootFrame
End If
If rootFrame.Content Is Nothing Then
If Not rootFrame.Navigate(GetType(Instructions), args.Arguments) Then
Throw New Exception("Failed to create initial page")
End If
End If
Window.Current.Activate()
End Sub
'Also the namespace definitions are done at the top so they are not the issues neither.
There is a solution to debug your app : in VS2012, Right-click on your project in the Solution Explorer, then go to the Debug tab and in the Start Action section, check "Do not launch, but debug my code when it starts".
Now you can start your app from the Search Contract even if it is not running yet and debug it!
Now for your problem, I would suggest you to check whether the data is loaded before you actually search for something.
You might be hitting the search activation with empty query string. Check your search activation handler, whether you are handling the blank query text case or not?
protected override void OnSearchActivated(SearchActivatedEventArgs args)
{
// your app initialization code here.
Frame frame = (Frame)Window.Current.Content;
if (!string.IsNullOrEmpty(args.QueryText))
{
frame.Navigate(typeof(SearchResultsPage), args.QueryText);
}
else
{
// navigate to your app home page if the query text is empty.
frame.Navigate(typeof(Home), null);
}
Window.Current.Activate();
}

Best way to combine Play and Pause button?

this is more of an advise thread I guess.
I've been wondering how one could create a button which display "play" when it's not pressed. And then shows "pause" once it's pressed. And visa versa when it's pressed again.
I had a similar problem when trying to create an expand panel button, but that was easy because I could just set a variable to true or false if PanelCollapsed was true.
But in this case I couldn't find any property in a button that I could query.
So I came up with this but I can't help thinking that this is a rather unsmart way of doing it?
If isPlay = True Then
If isPaused = False Then
btnPlay.Image = Image.FromFile("iconPause.png")
isPaused = True
isPlay = False
End If
GoTo Endline
End If
If isPlay = False Then
If isPaused = True Then
btnPlay.Image = Image.FromFile("iconPlay.png")
isPaused = False
isPlay = True
End If
End If
Endline:
How about using only one variable and code like this:
If isPlay Then
btnPlay.Image = Image.FromFile("iconPause.png")
else
btnPlay.Image = Image.FromFile("iconPlay.png")
End If
isPlay = not isPlay
You can use the "Tag" property. Its type is "object" so you can use any object you want, but in your case a string will do:
If Button1.Tag = "Pause" Then
Button1.Image = Image.FromFile("iconPlay.png")
Button1.Tag = "Play"
Else
Button1.Image = Image.FromFile("iconPause.png")
Button1.Tag = "Pause"
End If
Most .NET WinForm controls have a 'Tag' property (a button has one). You can set the Tag to be anything you want. An easy way to do this is to set the 'Tag' property to a boolean with the state of the button.
Just an idea...sure there are many other approaches.
UPDATE:
Otherwise, you can maintain the state of the button in your application as its own member variable. This might have several advantages because you can pass this state to other controls that might need it. The only weakness with this approach is that the state must be maintained separately.
If you have a fairly straight-forward implementation, use the Tag property.
A contrary opinion ...
... while other answers have given you some techniques to achieve your desired result, I'm going to ask you to reconsider your UI design.
Dual state buttons - ones that alternate purpose when clicked - can be a source of user frustation.
Here are two scenarios.
Scenario #1 ... if the users machine is under load (for any reason), there may be a perceptible delay between the users actual click on your button and when your click handler is executed.
Normally the time between click and handler is a few milliseconds or less, but it can run to several seconds. If this happens when the user clicks on a dual state button, they are likely to click the button again. Net effect, when the application catches up, is to toggle on, then immediately off again.
Scenario #2 ... many users habitually double click everything. Even experienced users who've been using computers for years may have this weird habit. When they try to press a dual state button, guess what happens ... the action toggles on, then immediately off again.
There are at least two solutions ...
Solution #1 ... use two buttons, one for "On", one for "Off".
Solution #2 ... write some debouncing code to suppress the effect of a second click if processed immediately (ie: < 75ms) after the first.
I don't personally use Visual Basic, but I do know that Buttons in Windows Forms have a property called 'Tag'. It is of the generic object type, so you can save whatever state you want, and just use casting to get the value back out.
How about using the "Image" property?
Rem form initialization
ImagePlay = Image.FromFile("iconPlay.png")
ImagePause = Image.FromFile("iconPause.png")
Button1.Image = ImagePlay
.
.
.
Rem on button1 click
If Button1.Image = ImagePlay Then
Button1.Image = ImagePause
Else
Button1.Image = ImagePlay
End If