CCMenu::menuWithItems() deprecated - deprecated

I made a CCMenu object and want to add an item to it but the menuWithItem() method appears deprecated and thus the item doesn't get added to my menu. Here is how am using it:
CCMenuItemFont* pExitButton = CCMenuItemFont::itemWithString(
"Exit",
this,
SEL_MenuHandler(CallbackOnExit));
CCMenu* pMenu = (CCMenu::menuWithItem(pExitButton, NULL);
what is the other possible way to get this done?

Try this:
CCMenuItemFont* pExitButton = CCMenuItemFont::itemFromString(
"Exit",
this,
SEL_MenuHandler(CallbackOnExit));

Related

I imported a pokemon project to gmx

// but the code is throwing unexpected terminal operator new
function MovePokemon(argument0, argument1) {
old = argument0;
new = argument1;
TPartyID = global.PartyID[old]
global.PartyID[old] = global.PartyID[new]
global.PartyID[new] = TPartyID;
new is a keyword in the current versions of GameMaker, so you'll need to rename that variable (say, to _new).
The project in question may leave some to be desired given the complete absence of local variable declarations (var).
Try use this code in your script to avoid use "new"
function MovePokemon(argument0, argument1) {
TPartyID = global.PartyID[argument0]
global.PartyID[argument0] = global.PartyID[argument1]
global.PartyID[argument1] = TPartyID;

django-tables2: linkify, how to make target new window

Using the linkfy argument as so:
def linkify_sale(**kwargs):
record = kwargs.get("record")
if record:
return f"https://...url...#{record.get('order_sale_id')}"
class ASA_Journal_ViewTable(tables.Table):
...
order_sale_nbr = tables.Column(verbose_name="Sales Order Number", linkify=linkify_sale)
works. But how to I specify a target on the link, to open in a new window?
ok, like this
order_sale_nbr = tables.Column(verbose_name="Sales Order Number", linkify=linkify_sale, attrs={"a":{
"target":"_blank"}})

UiAutomator cannot find UiObject that on a screen

I trying to click on a button with UiAutomator, but receive error "androidx.test.uiautomator.UiObjectNotFoundException"
I tried to locate object in two ways.
UiObject cartButton = uiDevice.findObject(new Selector().resourceId("R.id.group_cart_add_button"));
UiObject2 cartButton = uiDevice.findObject(By.res(InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName(), "R.id.group_cart_add_button"));
Then I use cartButton.click() but both times I receive an error.
In hierarchy this object is exist
And when I try to find it in Evaluate tool, I can do it:
But if I try to click, I receive an error:
Why?
You can do the following:
String packageName = "your-app-package-name"
String fullCartButtonResourceId = packageName + ":id/group_cart_add_button";
UiObject2 cartButton = mDevice.findObject(By.res(uk));
or
UiObject cartButton = findObject(new UiObject(new UiSelector().resourceId(fullCartButtonResourceId));

Django CMS - Copy relations in custom plugin not working

I have a problem with copy_relations after publishing a page.
I have a plugin with additional model. This model has ForeignKey to my plugin.
class InfContactForm(CMSPlugin):
name = models.CharField(max_length=50)
def copy_relations(self, oldinstance):
self.inf_contact_form.all().delete()
for inf_contact_form in oldinstance.inf_contact_form.all():
inf_contact_form.pk = None
inf_contact_form.plugin = self
inf_contact_form.save()
class InfContactFormAgreement(models.Model):
inf_contact_form = models.ForeignKey(InfContactForm, related_name="inf_contact_form")
agreement = HTMLField(blank=True, null=True)
The "InfContactFormAgreement" model is then used as stacked inline in "InfContactForm" plugin form.
Like it is written in docs, there is also copy_relations() method but when the page is published, nothing happens. When I get back again to edit mode InfContactFormAgreement is doubled every time I do it.
Here is also my cms_plugins.py file:
class PluginInfContactForm(CMSPluginBase):
render_template = '_contact_form.html'
name = name1
model = InfContactForm
require_parent = False
inlines = [AgreementStackedInline, ]
def render(self, context, instance, placeholder):
context['instance'] = instance
context = super(PluginInfContactForm, self).render(context, instance, placeholder)
agreements = instance.inf_contact_form.all()
context.update({
'agreements': agreements,
})
return context
plugin_pool.register_plugin(PluginInfContactForm)
Thank you for any advice.
instead of:
inf_contact_form.plugin = self
you should use:
inf_contact_form.inf_contact_form = self
and the resulting code should look like this:
def copy_relations(self, oldinstance):
self.inf_contact_form.all().delete()
for inf_contact_form in oldinstance.inf_contact_form.all():
inf_contact_form.pk = None
inf_contact_form.inf_contact_form = self
inf_contact_form.save()
regards
I had a similar situation, the only difference being that my many-to-many relationship was not in a plugin, but an extension (PageExtension).
In my case, #Dariusz solution did not work, and I had to update the implicit "inbetween" model that exists between the Extension model and the Associated model.
My solution (the key being the "through"):
class Extension(PageExtension):
tags_regions = models.ManyToManyField(Region, related_name="articles", blank=True)
def copy_relations(self, oldinstance):
for region_tag in oldinstance.tags_regions.through.objects.filter(extension=oldinstance):
region_tag.extension = self
region_tag.save()

Conditional classname and text (Rails)

I'm pretty new to Rails and trying some basic stuff like conditional classes.
On the 'show' view I have an element that changes styling depending on the stock availability, but also the text changes accordingly.
People keep saying the controller should be as small as possible, but placing this conditional in the view also feels dirty. Is this really the best way?
Current controller:
def show
#tyre = Tyres::Tyre.find_by_id(params[:id])
if #tyre.in_stock
#availability = I18n.t("products.filter.other.in_stock")
#availability_class = 'i-check-circle color--success'
else
#availability = I18n.t("products.filter.other.not_in_stock")
#availability_class = 'i-cross-circle color--important'
end
end
Edit:
Controller:
def show
#tyre = Tyres::Tyre.find_by_id(params[:id])
if #tyre.in_stock
#availability_append = ".in_stock"
else
#availability_append = ".not_in_stock"
end
#availability = I18n.t("products.filter.other#{#availability_append}")
end
View:
.xs-12.description__status
%i{class: (#tyre.in_stock? ? 'i-check-circle color--success' : 'i-cross-circle color--important')}
= #availability
You can clean your controller tyres_controller.rb (i suppose) method,
def show
#tyre = Tyre.find(params[:id]) # I believe you have a model named 'tyre'
end
Then, there will be a file named tyres_helper.rb in your myproject/app/helpers/. Put the following code there,
def tyre_availability(tyre) # it'll return an array with two values, first one is class name, second one is localized value
if tyre.in_stock
return 'i-check-circle color--success', I18n.t("products.filter.other.in_stock")
else
return 'i-cross-circle color--important', I18n.t("products.filter.other.not_in_stock")
end
end
and, in the view you can use,
.xs-12.description__status
%i{:class => tyre_availability(#tyre)[0]}
= tyre_availability(#tyre)[1]

Resources