I have a problem.
I created a telegram bot under python3 with telepot and I use a custom keyboard.
the problem is that when i press a button, the custom keyboard is hidden by the phone keypad.
is it possible to temporarily lock the custom keyboard open or block the phone keyboard?
I already tested one_time_keyboard and it didn't work.
markupmainmenuadmin = ReplyKeyboardMarkup(keyboard=[["menu 1"],["info 1"],["info 2"],["info 3"],["Admin"]],resize_keyboard = True,one_time_keyboard = True)
[...]
bot.sendMessage(chat_id,str(textdb.get(query.nom == 'MainMenu2').get("text")),disable_web_page_preview=True, reply_markup=markupmainmenuadmin, parse_mode= 'Markdown')
it only happens when you stay on the same keyboard.
markupmainmenuadmin =InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text="menu 1", callback_data='0')],[InlineKeyboardButton(text="info 1", callback_data='1')],[InlineKeyboardButton(text="info 2", callback_data='2')],[InlineKeyboardButton(text="info 3", callback_data='3')],[InlineKeyboardButton(text="Admin", callback_data='4')]])
Related
I wan to create a file for my program that users open up and choose their options before running the calculation in a VI or other editor. Kind of like the menu in VI where you can highlight a word and expand/change to that topic. Only I want to let then highlight an option and see all the possible choices and be allowed to choose one. Is there a way to create such a file/capability?
Not certain what you mean, but you could create a simple GUI in Python like this that lets your users select parameters from lists and then writes the "settings" file for the FORTRAN program and starts it when a button is pressed:
#!/usr/local/bin/python3
from guizero import App, ListBox, Text, PushButton
def StartThatPuppy():
print("Starting FORTRAN...")
# Write currently selected settings to config file
# subprocess.call('/Users/fred/program.exe')
app = App(title="FORTRAN Parameter Setup", width=300, height=200)
t=Text(app, text="Select optimisation method")
listbox = ListBox(app,
items=["Method A", "Method B", "Method C (beta)", "Naive Method"],
selected="Method B",
scrollbar=True)
listbox.height=3
listbox.width=20
t=Text(app, text="Select threshold")
listbox = ListBox(app,
items=["1%", "2%", "5%", "10%"],
selected="5%",
scrollbar=True)
listbox.height=3
listbox.width=20
button = PushButton(app, text="Start FORTRAN", command=StartThatPuppy)
app.display()
That looks like this:
More examples and documentation are here.
Alternatively, if you want something textual, without needing a GUI, you could use whiptail like raspi-config uses on the RaspberryPi:
Another option might be dialog, documentation here
That could look like this:
dialog --title "FORTRAN Parameter Setup" "$#" \
--checklist "You can choose your threshold here.\n\
Press SPACE to toggle an option on/off. \n\n\
What threshold do you want?" 20 61 5 \
"1%" "Default threshold" ON \
"2%" "Less sensitive" off \
"5%" "Can be noisy" off \
"Unlimited" "Potentially too many results" off
retval=$?
I want to show the text from the 'Yes' and the 'No' button in the informative text of a QMessageBox, but I don't see how I can get these labels from the buttons.
from PyQt5.QtWidgets import *
import sys
app = QApplication(sys.argv)
msgbox = QMessageBox()
msgbox.setStandardButtons(msgbox.Yes | msgbox.No)
info_text = "Click '{yes}' to confirm. Click '{no}' to abort."
msgbox.setInformativeText(info_text)
if msgbox.exec_() == msgbox.Yes:
print("Confirmed")
else:
print("Aborted")
By calling setStandardButtons, the button order and the button labels will be set to the default for the current operating system and the current language setting. How can I obtain these defaults so that I can use them for the slots in the string info_text?
I thought about using the buttons attribute from the QMessageBox object, which is a list of QPushButton objects. I can read the labels from there, but I don't see how I could determine whether the first element in the list is the Yes or the No button.
Okay, I was being stupid: along side the buttons attribute, there is also the button() method, which takes as its argument the button type that I want to retrieve. I can then use text() to get the label. Finally, the hotkey marker & has to be stripped from the label:
info_text = "Click '{yes}' to confirm. Click '{no}' to abort.".format(
yes=msgbox.button(msgbox.Yes).text().replace("&", ""),
no=msgbox.button(msgbox.No).text().replace("&", ""))
msgbox.setInformativeText(info_text)
I have a script that enables a Power supply after the user click "ONLY ONE TIME" the "START TEST" button, right after, I disable the button to avoid the "double click, however, I have noticed that "some how" if user perform a "double click" my application launch a second operation.
def starttest():
Button(main, text="START TEST", font=("Tahoma", 21), height=1, width=24,
command=starttest, state=DISABLED).place(x=55,y=40)
PS = serial.Serial('COM1', 9600, timeout=.1)
##my code here ...
Does anyone have an idea what should I do to prevent this happen?
Each time you call starttest() function by pressing the inherent button, a new button widget is created: that is why it looks like you are able to click indefinitely on the falsely "same" button.
You should create that button somewhere else in your program:
...
power_supply_btn = Button(... text="START TEST", command=starttest ...)
power_supply_btn.place(x=55,y=40)
...
Then configure the state of that button in your starttest() callback using the configure() function:
def starttest():
global power_supply_btn
power_supply_btn.configure(state=DISABLED)
I have a report where, once the user clicks a SAVE button it fires a script. Can I do a dialog box where once the user clicks SAVE, A dialog with "Confirm save ... Yes? No? " pops up and when the user clicks Yes it fires the script? I would like this to work on both the web player and desktop
You can use the following iron python script for solving this:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox, MessageBoxButtons
from System.Windows.Forms import DialogResult
dialogResult = MessageBox.Show("Some question", "Some Title", MessageBoxButtons.YesNo)
if(dialogResult == DialogResult.Yes):
MessageBox.Show("The answer is YES")
else:
MessageBox.Show("The answer is NO")
Can not find any reference on how to close application by the "X" button. I'm programming using XCB and want to close the program by the "X" button. I looked and can't find anything about it. I know how to close by pressing a button. Also, by pressing the "X" button the window looks like it closes but doesn't.
I struggled on this topic some time ago as well.
Look at http://marc.info/?l=freedesktop-xcb&m=129381953404497 .
The key is to store the cookie for the WM_DELETE_WINDOW in a separate cookie...
xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, 16, "WM_DELETE_WINDOW");
xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0);
and in the event loop compare the client_message with the cookie2
case XCB_CLIENT_MESSAGE:
{
if((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) ...
}