如何隐藏命令按钮(CBA)

本文介绍了一种在掌上法律词典应用中隐藏特定命令按钮的方法。通过在法律法规内容显示界面对应的视图DoActivateL方法中加入特定代码,实现了只显示返回命令按钮的功能。

     在有些情况下需要隐藏已经存在的CBA(Command Button Area命令按钮区域)的某一命令按钮。比如,“选项----返回”,有时候需要将“选项”命令按钮以及选项下的菜单全部隐藏。

    在上月的项目开发中,遇到了这样一个问题: 

    我做的是掌上法律词典,分成三个独立模块:法律法规、法律词库 和 使用说明。其中,法律词库是对某一个法律词条进行简短的解释,从法律词条解释界面可以跳转到该词条对应的法律法规显示界面中去。由于法律法规界面中的CBA为“选项---返回”,而我从法律词条解释界面跳转到该页面后,只需要让他显示右边的命令按钮“返回”。因此,需要屏蔽掉“选项”命令键。

    对于这个问题,可以采用下面的代码来实现:

#include "avkon.hrh"    //头文件

CEikButtonGroupContainer   *cba   =   CEikButtonGroupContainer::Current(); 
cba-> MakeCommandVisible(EAknSoftkeyOptions,false); 

 

    针对我上面的具体问题,可将上面的代码放在法律法律法规内容显示界面对应的视图的

                DoActivateL  (  const TVwsViewId &  aPrevViewId,  
                  TUid  aCustomMessageId,  
                  const TDesC8 &  aCustomMessage 
                 ) 
   方法里面,判断前一个视图的Id是否是法律词条解释界面对应的视图Id,如果是则调用上面的处理代码。

       同时,还需要加上一个判断,如果当前视图Id是从法律法规目录视图的Id,则调用如下的代码:(如果忽略这一点的话,再进入法律法规内容显示界面时,“选项”命令键就会一直是关闭的,因此要予以注意!)

CEikButtonGroupContainer   *cba   =   CEikButtonGroupContainer::Current(); 
cba-> MakeCommandVisible(EAknSoftkeyOptions,true); 

import os from tkinter import * from tkinter.messagebox import * import psutil root = Tk() root.geometry('280x320') root.title('再见极域') root.wm_attributes('-topmost', 1) root.resizable(False, False) root.configure(bg = '#1E1E1E') font1 = ('微软雅黑', 9) font2 = ('Courier New', 16, 'bold') font3 = ('微软雅黑', 10) ICED = False TOP = True CON = True Label(root, text = '极域状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 0, y = 10, width = 140, height = 20) Label(root, text = '广播状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 140, y = 10, width = 140, height = 20) Label(root, text = '键盘状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 0, y = 70, width = 140, height = 20) Label(root, text = '置顶状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 140, y = 70, width = 140, height = 20) la = Label(root, bg = '#1E1E1E', font = ('Courier New', 13, 'bold')) lb = Label(root, bg = '#1E1E1E', font = font2) lc = Label(root, text = 'OPENED', fg = 'lime', bg = '#1E1E1E', font = font2) ld = Label(root, text = 'ON', fg = 'lime', bg = '#1E1E1E', font = font2) la.place(x = 0, y = 30, width = 140, height = 45) lb.place(x = 140, y = 30, width = 140, height = 45) lc.place(x = 0, y = 90, width = 140, height = 45) ld.place(x = 140, y = 90, width = 140, height = 45) def cba1(): ba.config(fg = '#660000', bg = 'red', activeforeground = 'red', activebackground = '#660000', text = '上键盘锁', command = cba2) lc.config(text = 'OPENED', fg = 'lime') #--------------------------- #----------开键盘锁---------- #--------------------------- def cba2(): ba.config(fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', text = '开键盘锁', command = cba1) lc.config(text = 'LOCKED', fg = 'red') #--------------------------- #----------上键盘锁---------- #--------------------------- ba = Button(root, text = '上键盘锁', borderwidth = 0, bg = 'red', font = font3, activeforeground = 'red', activebackground = '#660000', relief = GROOVE, fg = '#660000', command = cba2) ba.place(x = 10, y = 140, width = 125, height = 45) def cbb1(): bb.config(fg = '#660000', bg = 'red', activeforeground = 'red', activebackground = '#660000', text = '取消置顶', command = cbb2) ld.config(text = 'ON', fg = 'lime') TOP = 1 root.wm_attributes('-topmost', 1) def cbb2(): bb.config(fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', text = '置顶窗口', command = cbb1) ld.config(text = 'ON', fg = 'red') TOP = 0 root.wm_attributes('-topmost', 0) bb = Button(root, text = '取消置顶', borderwidth = 0, bg = 'red', font = font3, activeforeground = 'red', activebackground = '#660000', relief = GROOVE, fg = '#660000', command = cbb2) bb.place(x = 145, y = 140, width = 125, height = 45) # 这三个功能暂时没弄 def cbc(): bc['state'] = 'disabled' bd['state'] = 'normal' be['state'] = 'normal' #--------------------------- #-----------窗口化---------- #--------------------------- def cbd(): bc['state'] = 'normal' bd['state'] = 'disabled' be['state'] = 'normal' #--------------------------- #-----------最小化---------- #--------------------------- def cbe(): bc['state'] = 'normal' bd['state'] = 'normal' be['state'] = 'disabled' #--------------------------- #----------复原窗口---------- #--------------------------- bc = Button(root, text = '窗口化', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbc) bc.place(x = 10, y = 195, width = 76, height = 45) bd = Button(root, text = '最小化', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbd) bd.place(x = 96, y = 195, width = 76, height = 45) be = Button(root, text = '复原窗口', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbe) be['state'] = 'disabled' be.place(x = 182, y = 195, width = 88, height = 45) def cbf(): os.system('taskkill /im StudentMain.exe /f') showinfo('成功', '操作成功执行!') # ntsd 需要事先放到下面这个路径 def cbg(): os.system('C:\\Windows\\Temp\\ntsd.exe -c q -pn StudentMain.exe') showinfo('成功', '操作成功执行!') def cbh1(): global ICED s = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo) for i in s: if i['name'] == 'StudentMain.exe': p = i['pid'] break pro = psutil.Process(p) pro.suspend() ICED = True bh.config(fg = '#660000', bg = 'red', text = '解冻极域', activeforeground = 'red', activebackground = '#660000', command = cbh2) def cbh2(): global ICED s = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo) for i in s: if i['name'] == 'StudentMain.exe': p = i['pid'] break pro = psutil.Process(p) pro.resume() ICED = False bh.config(fg = '#006600', bg = 'lime', text = '冻结极域', activeforeground = 'lime', activebackground = '#006600', command = cbh1) bf = Button(root, text = 'TASKKILL', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbf) bf.place(x = 10, y = 255, width = 80, height = 45) bg = Button(root, text = 'NTSD', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbg) bg.place(x = 100, y = 255, width = 80, height = 45) bh = Button(root, text = '冻结极域', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbh1) bh.place(x = 190, y = 255, width = 80, height = 45) FUCKED = False def fla(): global ICED, FUCKED, CON s = [] k = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo['name']) k.append(pinfo) if 'StudentMain.exe' in s: if CON: la.config(font = ('Courier New', 13, 'bold')) CON = False for i in k: if i['name'] == 'StudentMain.exe': we = i['pid'] break if ICED: la.config(text = 'ICED', fg = 'yellow') lb.config(text = 'ICED', fg = 'yellow') else: la.config(text = f'ON\npid={we}', fg = 'red') lb.config(text = 'UNKNOWN', fg = 'yellow') if FUCKED: bc['state'] = 'normal' bd['state'] = 'normal' be['state'] = 'disabled' bf['state'] = 'normal' bg['state'] = 'normal' bh['state'] = 'normal' FUCKED = False else: CON = True la.config(text = 'OFF', fg = 'lime') lb.config(text = 'OFF', fg = 'lime') bc['state'] = 'disabled' bd['state'] = 'disabled' be['state'] = 'disabled' bf['state'] = 'disabled' bg['state'] = 'disabled' bh['state'] = 'disabled' la.config(font = font2) FUCKED = True if TOP: root.attributes('-topmost', 1) root.after(700, fla) root.after(500, fla) root.mainloop()
最新发布
09-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值