How to use _insertItem method in fMBT

Best Python code snippet using fMBT_python

utils.py

Source:utils.py Github

copy

Full Screen

...37 self.historyFile.close()38 def _removeLastItem(self) -> None:39 pass40 41 def _insertItem(self, index:int, item:Any) -> None:42 pass43 44 def addItemToHistory(self, item:str) -> None:45 item = item.strip(" \n\t")46 itemNode= dom.Element("item")47 text = self.tree.createTextNode(item) # type: str48 itemNode.appendChild(text) # type: List[str]49 items = self.tree.getElementsByTagName("item")50 if len(items) >= self.maxSize :51 self.tree.firstChild.removeChild(items[-1])52 self._removeLastItem()53 items = self.tree.getElementsByTagName("item")54 if not items :55 self.tree.firstChild.appendChild(itemNode)56 else :57 for n in items :58 if self._getText(n) == item :59 return60 self.tree.firstChild.insertBefore(itemNode,items[0])61 self._insertItem(0,item)62 def save(self) -> None:63 historyFile = open(self.fileName, "w") 64 self.tree.writexml(historyFile, "", "", "") 65 historyFile.close()66 67class ItemHistoryStringList(ItemHistory):68 """ Class for storing text items in a list """69 def __init__(self, stringList:List[str], fileName:str, maxSize:int ):70 ItemHistory.__init__(self, fileName, maxSize )71 self.stringList = stringList # type: List[str]72 items = self.tree.getElementsByTagName("item")73 for node in items :74 text = self._getText(node) # type: str75 self.stringList += [text] 76 def _removeLastItem(self) -> None:77 if self.stringList :78 del self.stringList[-1:]79 80 def _insertItem(self, index:int, item:str) -> None:81 self.stringList.insert(index, item)82 83 84class ItemHistoryMenu(ItemHistory):85 """ Class for storing the history of items added to a QMenu """86 87 def __init__(self, fileName:str, maxSize:int, menu:Any, callbackMethod:Any ):88 ItemHistory.__init__(self, fileName, maxSize )89 self.menu = menu90 self.callbackMethod = callbackMethod91 items = self.tree.getElementsByTagName("item")92 self.actionGroup = QActionGroup(None)93 for node in items :94 text = self._getText(node) # type: str95 a = self.menu.addAction(text) # type: Any96 self.actionGroup.addAction(a)97 self.actionGroup.triggered.connect( self.actionTriggered )98 def _removeLastItem(self) -> None:99 actionList = self.actionGroup.actions()100 if actionList :101 a = actionList[-1]102 self.menu.removeAction(a)103 self.actionGroup.removeAction(a)104 105 def _insertItem(self, index:int, item:str) -> None:106 actionList = self.actionGroup.actions()107 actions = [] # type: List[str]108 for a in actionList :109 actions.append(a.text())110 self.actionGroup.removeAction(a)111 self.menu.clear()112 actions = [item] + actions113 for action in actions :114 a = self.menu.addAction(action)115 self.actionGroup.addAction(a) 116 self.actionGroup.triggered.connect( self.actionTriggered )117 def actionTriggered(self, action: QAction) -> None:118 self.callbackMethod(action.text())119

Full Screen

Full Screen

menu.py

Source:menu.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import wx3from classes.ui import UIManager4from classes.ui import UIControllerObject5from classes.ui import UIViewObject6from classes.ui import MenuBarController7from app import log8class MenuController(UIControllerObject):9 tid = 'menu_controller'10 _ATTRIBUTES = {11 'pos': {'default_value': -1,12 'type': int13 },14 'id': {'default_value': wx.ID_ANY,15 'type': int16 },17 'label': {'default_value': wx.EmptyString,18 'type': str19 },20 'help': {'default_value': wx.EmptyString,21 'type': str22 },23 }24 def __init__(self, **state):25 super(MenuController, self).__init__(**state)26 def insert_menu_item(self, menu_item_ctrl):27 self.view._InsertItem(menu_item_ctrl.pos, menu_item_ctrl.view)28 if menu_item_ctrl.callback:29 main_window = wx.App.Get().GetTopWindow()30 # UIM = UIManager()31 # root_ctrl = UIM.get_root_controller()32 main_window.Bind(wx.EVT_MENU, menu_item_ctrl.callback,33 id=menu_item_ctrl.id34 )35 def remove_menu_item(self, menu_item_ctrl):36 if menu_item_ctrl.callback:37 # UIM = UIManager()38 # root_ctrl = UIM.get_root_controller()39 main_window = wx.App.Get().GetTopWindow()40 main_window.Unbind(wx.EVT_MENU, id=menu_item_ctrl.id)41 self.view._RemoveItem(menu_item_ctrl.view)42class MenuView(UIViewObject, wx.Menu):43 tid = 'menu_view'44 def __init__(self, controller_uid):45 UIViewObject.__init__(self, controller_uid)46 UIM = UIManager()47 controller = UIM.get(self._controller_uid)48 if controller.id == wx.ID_ANY:49 controller.id = UIM.new_wx_id()50 wx.Menu.__init__(self)51 def PostInit(self):52 # log.debug('{}.PostInit started'.format(self.name))53 UIM = UIManager()54 controller = UIM.get(self._controller_uid)55 parent_controller_uid = UIM._getparentuid(self._controller_uid)56 parent_controller = UIM.get(parent_controller_uid)57 #58 if isinstance(parent_controller, MenuController):59 if controller.pos == -1:60 # Appending - Not needed to declare pos61 controller.pos = parent_controller.view.GetMenuItemCount()62 if controller.pos > parent_controller.view.GetMenuItemCount():63 # If pos was setted out of range for inserting in parent Menu64 msg = 'Invalid position for Menu with label={}. Position will be setting to {}'.format(controller.label,65 parent_controller.view.GetMenuItemCount())66 log.warning(msg)67 controller.pos = parent_controller.view.GetMenuCount()68 parent_controller.view.Insert(controller.pos,69 controller.id,70 controller.label,71 self,72 controller.help73 )74 elif isinstance(parent_controller, MenuBarController):75 if controller.pos == -1:76 # Appending - Not needed to declare pos77 controller.pos = parent_controller.view.GetMenuCount()78 if controller.pos > parent_controller.view.GetMenuCount():79 # If pos was setted out of range for inserting in parent Menu80 msg = 'Invalid position for Menu with label={}. Position will be setting to {}'.format(controller.label,81 parent_controller.view.GetMenuCount())82 log.warning(msg)83 controller.pos = parent_controller.view.GetMenuCount()84 ret_val = parent_controller.view.Insert(controller.pos, self, controller.label)85 if not ret_val:86 raise Exception()87 else:88 raise Exception()89 # log.debug('{}.PostInit ended'.format(self.name)) 90 def _InsertItem(self, pos, menu_item_view):91 self.Insert(pos, menu_item_view)92 def _RemoveItem(self, menu_item_view):...

Full Screen

Full Screen

qcombobox.py

Source:qcombobox.py Github

copy

Full Screen

...63 and len(args) == 3):64 args, kwargs['userData'] = args[:-1], args[-1]65 if 'userData' in kwargs:66 kwargs['userData'] = userDataWrapper(kwargs['userData'])67 _insertItem(self, *args, **kwargs)68 _setItemData = QComboBox.setItemData69 def setItemData(self, index, value, role=Qt.UserRole):70 value = userDataWrapper(value)71 _setItemData(self, index, value, role=role)72 _itemData = QComboBox.itemData73 def itemData(self, index, role=Qt.UserRole):74 userData = _itemData(self, index, role=role)75 if isinstance(userData, userDataWrapper):76 userData = userData.data77 return userData78 def findData(self, value):79 for i in range(self.count()):80 if self.itemData(i) == value:81 return i...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful