Automatic Conversion Depending on Units in ComboBox
I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.
Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.
python time
add a comment |
I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.
Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.
python time
add a comment |
I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.
Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.
python time
I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.
Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.
python time
python time
asked Jan 3 at 1:40


Arci Jeirico MalabananArci Jeirico Malabanan
275
275
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).
If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:
- Declare a flag which shall store whether or not the base value has been entered (initially false)
- Declare a variable to store the base value
- Hook onto when the component is changed.
- When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.
- Do your calculations, etc and update the component programatically
- Once you have updated the component programatically, reset the flag to false.
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015337%2fautomatic-conversion-depending-on-units-in-combobox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).
If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:
- Declare a flag which shall store whether or not the base value has been entered (initially false)
- Declare a variable to store the base value
- Hook onto when the component is changed.
- When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.
- Do your calculations, etc and update the component programatically
- Once you have updated the component programatically, reset the flag to false.
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
add a comment |
I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).
If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:
- Declare a flag which shall store whether or not the base value has been entered (initially false)
- Declare a variable to store the base value
- Hook onto when the component is changed.
- When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.
- Do your calculations, etc and update the component programatically
- Once you have updated the component programatically, reset the flag to false.
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
add a comment |
I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).
If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:
- Declare a flag which shall store whether or not the base value has been entered (initially false)
- Declare a variable to store the base value
- Hook onto when the component is changed.
- When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.
- Do your calculations, etc and update the component programatically
- Once you have updated the component programatically, reset the flag to false.
I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).
If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:
- Declare a flag which shall store whether or not the base value has been entered (initially false)
- Declare a variable to store the base value
- Hook onto when the component is changed.
- When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.
- Do your calculations, etc and update the component programatically
- Once you have updated the component programatically, reset the flag to false.
edited Jan 3 at 2:11
answered Jan 3 at 1:56
user10859576
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
add a comment |
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
Thank you for the suggestion. Will implement it asap.
– Arci Jeirico Malabanan
Jan 3 at 2:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015337%2fautomatic-conversion-depending-on-units-in-combobox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown