How to use _menuItem method in pyatom

Best Python code snippet using pyatom_python

utils.py

Source:utils.py Github

copy

Full Screen

1from depot.models import Category, Unit, Goods2from cost.models import CategoryPos, MenuItem, MenuItemDetail3from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned4import cgi5from inventory.common import get_abbreviation6def update_many(objects, fields=[], using="default"):7 """Update list of Django objects in one SQL query, optionally only8 overwrite the given fields (as names, e.g. fields=["foo"]).9 Objects must be of the same Django model. Note that save is not10 called and signals on the model are not raised."""11 if not objects:12 return13 import django.db.models14 from django.db import connections15 con = connections[using]16 names = fields17 meta = objects[0]._meta18 fields = [f for f in meta.fields if19 not isinstance(f, django.db.models.AutoField) and (not names or f.name in names)]20 if not fields:21 raise ValueError("No fields to update, field names are %s." % names)22 fields_with_pk = fields + [meta.pk]23 parameters = []24 for o in objects:25 parameters.append(tuple(f.get_db_prep_save(f.pre_save(o, True), connection=con) for f in fields_with_pk))26 table = meta.db_table27 assignments = ",".join(("%s=%%s" % con.ops.quote_name(f.column)) for f in fields)28 con.cursor().executemany(29 "update %s set %s where %s=%%s" % (table, assignments, con.ops.quote_name(meta.pk.column)),30 parameters)31class SyncMenuStock(object):32 def __init__(self, org, root_parent, is_retail=False):33 self.org = org34 self.is_retail = is_retail35 self.root_parent = Category.objects.get(org=org,parent__isnull=True)36 def update_main_category_pos(self, record):37 try:38 p = CategoryPos.objects.get(parent__isnull=True, org=self.org, slu_id=record['main_group_id'])39 p.processing = 040 p.last_name = p.name = record['main_group_name']41 p.save()42 except ObjectDoesNotExist:43 p = CategoryPos.objects.create(parent=None, org=self.org, slu_id=record['main_group_id'],44 name=record['main_group_name'])45 p.save()46 except MultipleObjectsReturned:47 p = CategoryPos.objects.filter(parent=None, org=self.org, slu_id=record['main_group_id'],48 name=record['main_group_name'])[0]49 p.processing = 050 p.save()51 if self.is_retail is True:52 catepory_pos, created = Category.objects.get_or_create(parent=self.root_parent, org=self.org,53 slu_id=record['main_group_id'],54 defaults={'name': record['main_group_name'],55 'slu_type': 2})56 if not created:57 catepory_pos.name = record['main_group_name']58 catepory_pos.save()59 return (p, catepory_pos)60 return (p, None)61 def update_sub_category_pos(self, record, main_category, catepory_pos=None):62 try:63 c = CategoryPos.objects.get(parent=main_category, org=self.org, slu_id=record['dmi_slu_id'])64 c.processing = 065 c.last_name = c.name = record['dmi_slu_name']66 c.save()67 except ObjectDoesNotExist:68 c=CategoryPos.objects.create(parent=main_category,org=self.org,slu_id=record['dmi_slu_id'],name=record['dmi_slu_name'])69 except MultipleObjectsReturned:70 c = CategoryPos.objects.filter(parent=main_category, org=self.org, slu_id=record['dmi_slu_id'])[0]71 c.processing = 072 c.last_name = c.name = record['dmi_slu_name']73 c.save()74 if self.is_retail is True:75 catepory_pos, created = Category.objects.get_or_create(parent=catepory_pos, org=self.org,76 slu_id=record['dmi_slu_id'],77 defaults={'name': record['dmi_slu_name'],78 'slu_type': 2})79 if not created:80 catepory_pos.name = record['dmi_slu_name']81 catepory_pos.save()82 return c83 def update_menuitem(self, record, sub_category_pos, catepory_pos=None):84 unit = record['unit'].encode("utf-8")85 try:86 # p=MenuItem.objects.filter(org=org,item_id=record['item_id'],unit=unit).order_by('-id')[0]87 p = MenuItem.objects.select_related().filter(org=self.org, item_id=record['item_id'], unit=unit).order_by('-id')[88 0]89 p.categoryPos = sub_category_pos90 p.item_name = cgi.escape(record['item_name'])91 p.unit = unit92 p.price = record['price']93 p.processing = 094 p.nlu = record['nlu']95 p.save()96 except:97 p=MenuItem.objects.create(org=self.org,item_id=record['item_id'],categoryPos=sub_category_pos,item_name=record['item_name'],98 unit=record['unit'],price=record['price'],nlu=record['nlu'])99 if self.is_retail:100 _menuItem = p101 unit = None102 if _menuItem.unit:103 unit, created = Unit.objects.get_or_create(unit=_menuItem.unit, good__isnull=True, org=self.org)104 goods, created = Goods.objects.get_or_create(name=_menuItem.item_name, category=catepory_pos, org=self.org,105 defaults={'unit': unit, 'abbreviation': get_abbreviation(106 _menuItem.item_name), 'sale_price_ori': _menuItem.price,107 'sale_price': _menuItem.price,108 'last_modify_user': None})109 if not created and goods.unit != unit:110 goods.unit = unit111 goods.save()112 MenuItemDetail.objects.filter(org=self.org, menuItem=_menuItem, good=goods).delete()113 MenuItemDetail.objects.get_or_create(org=self.org, menuItem=_menuItem, good=goods, weight=1,114 goods_unit=goods.unit)115 weight = 1116 good_unit = goods.unit117 standard_weight = goods.change_nums(weight, good_unit)118 _menuItem.cost = standard_weight * goods.refer_price119 _menuItem.profit = _menuItem.price - _menuItem.cost120 _menuItem.percent1 = _menuItem.cost and (_menuItem.price - _menuItem.cost) * 100.0 / _menuItem.cost or 0121 _menuItem.percent2 = _menuItem.price and (122 _menuItem.price - _menuItem.cost) * 100.0 / _menuItem.price or 0123 _menuItem.sync_type = 1124 _menuItem.save()125 def rebuild_category(self):126 Category.objects.partial_rebuild(Category.objects.filter(org=self.org)[0].tree_id)127 def rebuild_category_pos(self):128 CategoryPos.objects.rebuild()129 def del_category_proccessing(self):...

Full Screen

Full Screen

treeitem.py

Source:treeitem.py Github

copy

Full Screen

1from elisa.boxwidget import surface, events2from elisa.framework import common3class TreeItem(surface.Surface): 4 def __init__(self, menuitem, font = None, enable_arrow = False):5 surface.Surface.__init__(self, menuitem.get_short_name())6 self._appli = common.get_application()7 self._focus = False8 self._menuitem = menuitem9 self._enable_arrow = enable_arrow10 self._appli.get_menu_renderer().add_menuitem_surface(menuitem, self)11 12 if enable_arrow == True:13 self._arrow_surface = surface.Surface(self._menuitem.get_short_name() + str(' arrow'))14 self._arrow_surface.set_back_color(255,255,255)15 self._arrow_surface.set_location(14,128,2.3)16 self._arrow_surface.set_size(100,20)17 self._arrow_surface.set_background_from_file("elisa/skins/default_skin/pictures/downarrow.png")18 #self._arrow_surface.get_texture().set_aspect_ratio(False)19 self.add_surface(self._arrow_surface)20 else:21 self._arrow_surface = None22 23 self._font = font24 self.set_focus(False)25 26 if self._appli.get_player_manager().uri_is_attached(menuitem.get_target_path()) == True:27 #Movie is playing28 p = self._appli.get_player_manager().get_player(menuitem.get_target_path())29 self.set_texture(p.get_texture())30 else:31 self.set_background_from_file(menuitem.get_icon_path())32 33 def on_removed(self):34 self.set_focus(False)35 surface.Surface.on_removed(self)36 self._appli.get_menu_renderer().remove_menuitem(self._menuitem)37 38 def show_label(self):39 if self._font != None and self.visible()==True:40 self._font.show()41 (_x,_y,_z) = self.get_location()42 self._font.set_text(self._menuitem.get_short_name())43 (_xf,_yf,_zf) = self._font.get_size()44 (_xs,_ys) = self.get_size()45 self._font.set_location((_xs - _xf)/2, _ys - _yf , 2.4)46 self.add_surface(self._font)47 48 def hide_label(self):49 if self._font != None:50 self._font.hide()51 self.remove_surface(self._font)52 def show_down_arrow(self):53 if self._enable_arrow == True:54 self._arrow_surface.set_alpha_level(100)55 56 def hide_down_arrow(self):57 if self._enable_arrow == True:58 self._arrow_surface.set_alpha_level(0)59 60 def get_menuitem(self):61 return self._menuitem62 63 def has_focus(self):64 return self._focus65 66 def set_focus(self, focus):67 self._focus = focus68 menu_item = self.get_menuitem()69 menu_item.fire_focus(menu_item, focus)70 71 if focus == False:72 self.set_alpha_level(100)73 self.hide_down_arrow()74 self.hide_label()75 else:76 self.set_alpha_level(100)77 if self._menuitem.get_items() != []: 78 self.show_down_arrow()79 self.show_label()80 def set_alpha_level(self, level, apply_to_child=False):81 if self._focus==False:82 level = level * 0.4083 surface.Surface.set_alpha_level(self, level, apply_to_child)84 85 def on_message(self, receiver, message, sender):86 if self.visible(True) and self.has_focus():87 if isinstance(message, events.InputEvent):88 if message.get_simple_event() == events.SE_OK and self.has_focus():89 self._menuitem.fire_action(self._menuitem)90 ...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1"""polySymmetry2The _initializePlugin and _uninitializePlugin functions are automatically 3called when the plugin is un/loaded to create the polySymmetry tools menu.4"""5import polySymmetry.commands as _cmds6import polySymmetry.options as _opts7import polySymmetry.tools as _tools8import maya.api.OpenMaya as OpenMaya9import maya.cmds as cmds10_POLY_SYMMETRY_MENU_NAME = 'polySymmetryMenu' 11class _MenuItem(object):12 """Simple wrapper to keep the script editor is pretty.13 14 Attributes15 ----------16 name : str17 Label for this menu item.18 action : callable19 Command executed when this menu item is clicked.20 isOptionBox : bool21 If True, this menu item is an option box.22 """23 def __init__(self, name, action=None, isOptionBox=False):24 self.name = name 25 self.action = action 26 self.isOptionBox = isOptionBox27 def __str__(self):28 return self.name.replace(' ', '')29 def __call__(self, *args, **kwargs):30 try:31 self.action()32 except Exception as e:33 OpenMaya.MGlobal.displayError(str(e).strip())34_POLY_SYMMETRY_MENU_ITEMS = (35 _MenuItem('Poly Symmetry Tool', _tools.polySymmetryTool),36 None,37 _MenuItem('Flip Mesh', _cmds.flipMesh),38 _MenuItem('Mirror Mesh', _cmds.mirrorMesh),39 None,40 _MenuItem("Copy Poly Deformer Weights", _cmds.copyPolyDeformerWeights), 41 _MenuItem("Copy Poly Deformer Weights Options", _opts.copyPolyDeformerWeightsOptions, True), 42 _MenuItem("Flip Poly Deformer Weights", _cmds.flipDeformerWeights),43 _MenuItem("Flip Poly Deformer Weights Options", _opts.flipPolyDeformerWeightsOptions, True), 44 _MenuItem("Mirror Poly Deformer Weights", _cmds.mirrorDeformerWeights),45 _MenuItem("Mirror Poly Deformer Weights Options", _opts.mirrorPolyDeformerWeightsOptions, True), 46 None, 47 _MenuItem("Copy Poly Skin Weights", _cmds.copyPolySkinWeights),48 _MenuItem("Copy Poly Skin Weights Options", _opts.copyPolySkinWeightsOptions, True),49 _MenuItem("Mirror Poly Skin Weights", _cmds.mirrorPolySkinWeights),50 _MenuItem("Mirror Poly Skin Weights Options", _opts.mirrorPolySkinWeightsOptions, True),51 None,52 _MenuItem("Set Influence Symmetry", _cmds.setInfluenceSymmetry),53 _MenuItem("Set Influence Symmetry Options", _opts.InfluenceSymmetryOptionsBox, True),54 _MenuItem("Print Influence Symmetry", _cmds.printInfluenceSymmetry),55 None56)57def _try_delete_menu():58 if cmds.menu(_POLY_SYMMETRY_MENU_NAME, query=True, exists=True):59 cmds.deleteUI(_POLY_SYMMETRY_MENU_NAME) 60 61def _initializePlugin(*args):62 """Construct the poly symmetry plugin menu."""63 64 if cmds.about(batch=True):65 return66 67 _try_delete_menu()68 69 cmds.menu(70 _POLY_SYMMETRY_MENU_NAME,71 label="Poly Symmetry", 72 parent='MayaWindow'73 )74 for item in _POLY_SYMMETRY_MENU_ITEMS:75 _addMenuItem(item)76 _addMenuItem(77 _MenuItem('Reload Menu', _initializePlugin)78 )79 80 cmds.menuSet("riggingMenuSet", addMenu=_POLY_SYMMETRY_MENU_NAME)81 82def _addMenuItem(item):83 if item is None:84 cmds.menuItem(divider=True)85 else:86 cmds.menuItem(87 label=item.name,88 command=item, 89 sourceType='python',90 optionBox=item.isOptionBox91 )92def _uninitializePlugin():93 """Construct the poly symmetry plugin menu."""94 if cmds.about(batch=True):95 return96 ...

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 pyatom 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