I'm having a trouble while implementing a log-in system in an interface I'm creating:
I want it to have two type of user: admin and user, so depending on what you choose you input your credentials and then if they're correct the system opens either the admin interface or the user interface.
My problem is that given the knowledge I have right now, I have to have a "mother window" while executing tkinter which is the first windows that opens when you run the program, in this case that mother window would be the log-in window, the thing is that if I close that log-in window once the user inputs his/her credentials, then the whole program doesn't work.
Is there a solution for this?
The simplest solution is to create two functions or two classes, one for the login window and one for the main window. Have these functions or classes return a single frame that contains everything needed for that part of the code.
Then, call the first function or class to login in, then destroy it and call the second function or class. When you destroy a frame, all of its children are also automatically destroyed.
Related
I know that using multiple tk.Tk() in a single app is a bad practice and if I want to create multiple windows I should use tk.Toplevel() instead. But what if I destroy the previous tk.Tk() instance and then call other instance? Technically the first endless loop has ended, so I should be fine, right?
For example, I've written an application that starts off with login screen and then I move to, let's say, "mainwindow" and this is the screen the user will be watching the most often. Login screen is only a one-time thing when starting the app and user will not return to it again (unless he closes the "mainwindow" and runs the app again). Would it be more logical to call tk.Tk() on login window and after choosing "login" button destroy login window and then call "mainwindow" as tk.Tk()?
Technically, I could just withdraw the login window and create all windows as children of the login window using tk.Toplevel (and the flow would be loginwindow -> mainwindow -> otherwindows), but I wonder - is keeping windows whitdrawn when you won't need them again a good practice?
You can actually create as many windows as you want.
This code right here does perfectly work for me. You just create several objects from one class.
from tkinter import *
windows = []
for x in range(5):
windows.append(Tk())
Button(windows[-1], text='Destroy this window', command=windows[-1].destroy).pack()
windows[-1].mainloop()
So, you can destroy one window, then create another, or even make them work at the same time.
My bot is based on core-bot sample and has an interrupt function which can be invoked by certain intents during dialogs. If I'm in a dialog, and then the interrupt starts a dialog, they are both invoked via dc.beginDialog and there are on a single level in the dialog stack. For example, it would look like this
[ { id: 'viewOrderDialog', state: { dialogs: [Object] } },
{ id: 'interruptDialog', state: { dialogs: [Object] } } ]
So I can somewhat easily get the active dialog by getting the ID of the last element in the array. However, in my process I can start additional dialogs from, in this case, interruptDialog. Those are started from within a waterfall via step.beginDialog. In that case, they are no longer at the same level as the other dialogs (started from dc instead of step). I have to get into state.dialogs.dialogStack to find the id, which then can become nested again if that dialog calls another. Here is an example of what dc.activeDialog can end up looking like:
{"id":"interruptDialog","state":{"dialogs":{"dialogStack":[{"id":"waterfallDialog","state":{"options":"expediteOrder","values":{"instanceId":"d61d748e-af45-cea0-9188-63904de21dfc"},"stepIndex":0}},{"id":"escalationDialog","state":{"dialogs":{"dialogStack":[{"id":"waterfallDialog","state":{"options":{},"values":{"instanceId":"6e755278-d636-dd76-3b47-eb43e3eda1c7"},"stepIndex":2}},{"id":"emailDialog","state":{"dialogs":{"dialogStack":[{"id":"waterfallDialog","state":{"options":{},"values":{"instanceId":"87f08019-ff59-ce03-ccab-7914fb0b553b"},"stepIndex":1}},{"id":"emailPrompt","state":{"options":{"prompt":"Which email address do you want us to reply to?"},"state":{}}}]}}}]}}}]}}}
I could get down to the lowest level, which in this case is emailPrompt, but it seems it would take an inordinate amount of overhead to check and see if each level of dialogs/dialogStack was an array. (And yes, I should probably name my waterfall dialogs something other than waterfallDialog). I was hoping there would be an easy way to just get the most recent dialog off the stack, but I couldn't find anything to give me that information.
In a less general sense, I'm specifically trying to add a condition to the interrupt to prevent it from being invoked within certain dialogs. I have a step where user can write an email body, and if they write something about expediting an order, the interrupt is activating. In this specific case I decided to solve it by converting dc.activeDialog to a string and then checking to see if it includes 'emailDialog'. Then I add a condition for !activeDialog.includes('emailDialog'). Works fine for this case, but I asked the more general question because this may not be a good solution in other cases where I need to know which dialog I am in.
I can provide code snippets if needed, but the code itself isn't really important. I'm just trying to determine the best way to get the id of the currently active dialog from the dialog context.
The reason you're seeing nested dialog stacks is because you're using component dialogs.
If your interruptions are always performed on the root dialog context and that's where your interrupt dialogs get added, then there should be no need to dig into the nested dialog stacks. Because the interrupt dialog will always be in the root dialog stack you can just check your root dialog context to see if the active dialog is an interrupt dialog.
I don't know of any builtin way to determine the innermost active dialog, but if that's really what you want to do then it shouldn't be hard to create a recursive function to do it:
getInnermostActiveDialog(dc) {
var child = dc.child;
return child ? this.getInnermostActiveDialog(child) : dc.activeDialog;
}
It should be noted that the Core Bot sample makes only specific dialogs interruptible by having them extend a common base dialog class and then handling interruptions from within the dialog instead of from the bot class. You might want to follow that example by having dialogs "opt in" to interruptibility rather than having the interrupt dialog "opt out."
I am new to coded UI, is it good practice to initialize Browser Window in each method of test case. For example i have two methods in my test case, I am trying to find control in each method, for that i write browser window in each method, can i write like that.
I don't see an issue with that approach.
Are you trying to reduce code/setup statements?
It really depends, you could have a test class with many test methods. however have a method attributed with ClassInitialize to launch the browser one time (and set the option to not destroy the window after each test) and keep reusing the same window. Then, possibly, have a method to close the window attributed with ClassCleanup.
Then in a test, you should only potentially need to use the NavigateTo method at the start of your tests to be on the right page.
Do you have test requirements dealing with sessions or saved data?
You may need to actively close down a window after a test and programmatically empty caches. Then in this aspect, I would be using BrowserWindow.Launch typically and letting CodedUi automatically destroy the window if i forgot to call close on the window.
I have an accessibility requirement that states:
"Verify that, upon input within the stated UI component, the user input does not force a change of context unless the user has been previously advised through messaging.
-- Change of context = That no change occurs in the user agent, viewport, focus of that particular element, or content changes that impact meaning."
WCAG give an example of a failure to be a "pop-up window". To non-developers, I am thinking that a on-screen modal could be perceived as a pop-up window. Does anyone else agree?
We literally have dozens of modals all over the site I am working on and need to make sure before I start throwing aria-labels all over the place.
Yes, it is a change of context. In operating systems, this is communicated to users through the user of the ellipsis (...) at the end of the name e.g. a button with the text "Save..." can be expected to popup a dialog, whereas a button with the text "Save" will be expected to just save.
You can use aria-haspopup="true" on a button, in combination with a convention like the ellipsis to convey this in an accessible manner. http://www.w3.org/TR/wai-aria/states_and_properties#aria-haspopup
I've created an application with lwuit on java-me, however, each time the user receives a phone call the applications is minimized and when the user restores it, the first Form is shown again (a splash form). How can I avoid the application from starting again?
Try overriding onHideNotify() and onShowNotify(), In hideNotify, store the last shown form to a variable and display that in onShowNotify()