how to suppress pop-up message in Photoshop script "No pixels are selected." - mask

I have a script to loop through a document and check on every layer if there is a blank layer mask, and then delete that layer mask.
I'm not sure if there is a best approach to check if a layer mask is blank than getting a selection and inverting it.
After inverting, if there is no selection, Photoshop pops up a warning message stating "No pixels are selected."
How to avoid this message without check "Don't show again"?
for ( var a =0; a<activeDocument.artLayers.length; a++ ){
activeDocument.activeLayer = activeDocument.artLayers[a];
checkLayerMask();
};
function checkLayerMask() {
// has layer mask
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
var hasLayerMask = desc.hasKey(charIDToTypeID("UsrM")); // bool
if (hasLayerMask) {
// make layer mask active
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
// get selection from layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "T " ), ref );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
// invert selection
activeDocument.selection.invert();
try { activeDocument.selection.bounds}
catch(e) {
// delete active layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
};
}
app.activeDocument.selection.deselect();
};

AM command with DialogModes set to NO won't produce this message:
executeAction(charIDToTypeID('Invs'), undefined, DialogModes.NO);

Related

DevExpress MVC 17.1 How to open a Popup Window when the ValueChange event is called in a LargeDataComboBox

I need that at the time the ValueChanged event of the LargeDataComboBox is called (when I click on a row in the drop-down list) a Popup Window is displayed.
_searchPanel.cshtml
#Html.DevExpress().ComboBox(
settings =>
{
settings.Name = "comboBoxSearchPanel";
settings.Height = 30;
settings.SelectedIndex = 0;
settings.Properties.DropDownStyle = DropDownStyle.DropDown;
settings.CallbackRouteValues = new { Controller = "SearchPanel", Action = "SearchPanel" };
settings.Properties.CallbackPageSize = 30;
settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.Contains;
settings.Properties.FilterMinLength = 2;
settings.Properties.ClearButton.DisplayMode = ClearButtonDisplayMode.OnHover;
settings.Properties.ValueField = "id_usuario";
settings.Properties.ValueType = typeof(string);
settings.Properties.TextFormatString = "{0} {1}";
settings.Properties.Columns.Add(column =>
{
column.FieldName = "iduser";
column.Caption = "User";
});
settings.Properties.Columns.Add(column =>
{
column.FieldName = "fullname";
column.Caption = "FUllName";
column.Width = 175;
});
settings.Properties.ClientSideEvents.ValueChanged = "function(s, e) { OnValueChangeSearchPanel(s, e)}";
}
).BindList(Model).GetHtml()
function where the ValueChanged event is called
function OnValueChangeSearchPanel(s, e) {
var x = s.GetSelectedItem().text.split(" ");
console.log(x[0]);
//I need to replace the alert with a popup
alert(x[0]);
}
_popupWindow.cshtml
#Html.DevExpress().PopupControl(settings =>
{
settings.Name = "popupUser";
settings.AllowDragging = true;
settings.ShowOnPageLoad = true;
settings.CloseAction = CloseAction.CloseButton;
settings.HeaderText = "User";
settings.SetContent(() =>
{
ViewContext.Writer.Write(
"<h1>" + "Welcome" + "</h1>"
);
});
Diagram of how it should work
The code below does the trick
function OnValueChangeSearchPanel(s, e) {
var x = s.GetSelectedItem().text.split(" ");
popupUser.Show();
}
Your Helper should look like this (complete code here)
#Html.DevExpress().PopupControl(settings =>
{
settings.Name = "popupUser";
settings.AllowDragging = true;
settings.ShowOnPageLoad = true;
settings.EnableClientSideAPI = true;
settings.CloseAction = CloseAction.CloseButton;
settings.PopupAction = PopupAction.None;
settings.HeaderText = "User";
settings.SetContent(() =>
{
ViewContext.Writer.Write(
"<h1>" + "Welcome" + "</h1>"
);
});

reading tile-data from mbtiles generates "RangeError: Error #2006: The supplied index is out of bounds."

I am trying to read imagedata from a sqlite database ( it is a mbtiles map tiles file )
for that i tried to convert this php code
$sql = "SELECT * FROM tiles WHERE zoom_level = $zoom AND tile_column = $column AND tile_row = $row";
$q = $conn->prepare($sql);
$q->execute();
$q->bindColumn(1, $zoom_level);
$q->bindColumn(2, $tile_column);
$q->bindColumn(3, $tile_row);
$q->bindColumn(4, $tile_data, PDO::PARAM_LOB);
while($q->fetch())
{
header("Content-Type: image/png");
echo $tile_data;
}
to as3 using
_conn = new SQLConnection();
_conn.addEventListener(SQLEvent.OPEN, openHandler);
_conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);
var folder:File = File.applicationDirectory;
var dbFile:File = folder.resolvePath("test.mbtiles");
_conn.openAsync(dbFile, SQLMode.READ);
function openHandler(event:SQLEvent):void
{
trace("db opened");
var selectStmt:SQLStatement = new SQLStatement();
selectStmt.sqlConnection = _conn;
selectStmt.text = "SELECT * FROM tiles WHERE zoom_level = 5 AND tile_column = 17 AND tile_row = 20";
selectStmt.execute();
}
but i am getting "RangeError: Error #2006: The supplied index is out of bounds."
Any ideas on how to solve this?
Thanks!
aha, nerver mind.
query should be
"SELECT CAST(tile_data AS ByteArray) as data " +
"FROM tiles WHERE " +
"zoom_level = 5 " +
"and tile_column = 17 " +
"and tile_row = 20";

Google Maps ImageMapTypeOptions.getTileUrl convert point and zoom to LatLng

In google maps v3 api, How do I convert the point and zoom that get passed to ImageMapTypeOptions.getTitleUrl to a LatLng?
Thanks!
This shows how it's done with code you can reimplement in other languages.
https://developers.google.com/maps/documentation/javascript/examples/map-coordinates
const TILE_SIZE = 314;
const tileCoordToWorldCoord = ( tileCoord, zoom ) => {
const scale = Math.pow( 2, zoom );
const shift = Math.floor( TILE_SIZE / 2 );
const calc = tc => ( tc * TILE_SIZE + shift ) / scale;
const x = calc( tileCoord.x );
const y = calc( tileCoord.y );
return new google.maps.Point( x, y );
}
...
getTileUrl: ( coord, zoom ) => {
const pointCoord = tileCoordToWorldCoord( coord, zoom );
const latLng = mapInstance.getProjection().fromPointToLatLng( pointCoord );
}

Drupal Upgrade:: Need to rewrite pagerquery to version 7

I need to rewrite pagerquery, i have tried out several options adding tags, extend(PagerDefault) but nothing worked for me:
Please help.
My version 6 code is:
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
$args = array('uid' => $user->uid);
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
dsm($result);
}
else {
$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;
}
Without knowing the name of your join table this isn't complete, but should get you started:
$query = db_select('node', 'n')
->fields('n', array('nid', 'sticky', 'title', 'created'))
->condition('n.uid', $user->uid)
->condition('n.type', 'case')
->condition('n.status', 1)
->extend('PagerDefault')
->limit(variable_get('default_nodes_main', 10))
->addTag('node_access')
->orderBy('col_name');
$query->join('table_to_join', 'table_alias', 'table_alias.nid = n.nid');
foreach ($query->execute() as $row) {
// Do what you need to
}
if ($vidw == 'my_cases' or $vidw == 'my') { // including private
switch ($sort_by) {
case 'rated':
$order = 'n.sticky DESC, vc.value DESC';
$sort_join = 'LEFT OUTER JOIN {votingapi_cache} vc ON n.nid = vc.content_id AND vc.content_type = "node" AND vc.function = "average"';
break;
case 'discussed':
$order = 'n.sticky DESC, nc.comment_count DESC';
$sort_join = 'LEFT OUTER JOIN {node_comment_statistics} nc ON n.nid = nc.nid';
break;
case 'viewed':
$order = 'n.sticky DESC, nc.totalcount DESC';
$sort_join = 'LEFT OUTER JOIN {node_counter} nc ON n.nid = nc.nid';
break;
case 'recent':
default:
$order = 'n.sticky DESC, n.created DESC';
$sort_join = '';
break;
}
// from taxonomy_select_nodes
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
$args = array('uid' => $user->uid);
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
}
else {
$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}
// $output .= taxonomy_render_nodes($result);
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;dsm($output);
}
if ($num_rows) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
}
else {
$output .= '<p>'. t('There are currently no visible cases in this category.') .'</p>';
}
}
In above drupal 6 code, i have updated the query which gives me result but node_view() and theme() does not work.

Moq.MockVerificationException : The following setups were not matched:

I got this error
Test
'EM.CoreTest.Services.UnitTestEventSevice.EventService_Return_10_Events'
failed: Moq.MockVerificationException : The following setups were not
matched: IPricePackRepository pricepack =>
pricepack.Delete(It.Is(a => a.PP_EventID ==
1)) at Moq.Mock.Verify() Services\UnitTestEventSevice.cs(52,0): at
EM.CoreTest.Services.UnitTestEventSevice.EventService_Return_10_Events()
I am wondering why on that part raising an error because they have the same logic with the eventPersistenceMock. Please help me.
namespace EM.CoreTest.Services
{
[TestFixture]
public class UnitTestEventSevice
{
[SetUp]
public void StartUp()
{
AutoMapperConfiguration.Configure();
}
[Test]
public void EventService_Return_10_Events()
{
var eventPersistenceMock = new Mock<IEventRepository>();
var pricepackPersistenceMock = new Mock<IPricePackRepository>();
var regformPersistenceMock = new Mock<IRegFormRepository>();
var attendeePersistenceMock = new Mock<IAttendeeRepository>();
var eventlists = GetEvents();
var pricepacks = GetPricepacks();
var currentevent = eventlists.ToList()[1];
eventPersistenceMock.Setup(r => r.GetAll()).Returns(eventlists);
eventPersistenceMock.Setup(u => u.Single(It.IsAny<Func<tbl_SBAem_Event, bool>>())).Returns(eventlists.Where(a => a.EventMngID == currentevent.EventMngID).Single());
eventPersistenceMock.Setup(r => r.Delete(currentevent)).Verifiable();
eventPersistenceMock.Setup(r => r.SaveChanges()).Verifiable();
pricepackPersistenceMock.Setup(pricepack => pricepack.GetAll()).Returns(pricepacks);
pricepackPersistenceMock.Setup(pricepack => pricepack.Delete(It.Is<tbl_SBAem_PricePackages>(a => a.PP_EventID == currentevent.EventMngID))).Verifiable();
pricepackPersistenceMock.Setup(pricepack => pricepack.SaveChanges()).Verifiable();
regformPersistenceMock.Setup(rgform => rgform.Delete(It.Is<tbl_SBAem_RegForm>(a => a.RF_EventID == currentevent.EventMngID))).Verifiable();
regformPersistenceMock.Setup(rgform => rgform.SaveChanges()).Verifiable();
attendeePersistenceMock.Setup(atnd => atnd.Delete(It.Is<tbl_SBAem_Attendee>(a => a.AT_RegID == currentevent.EventMngID))).Verifiable();
attendeePersistenceMock.Setup(atnd => atnd.SaveChanges()).Verifiable();
var eventservice = new EventService(eventPersistenceMock.Object,pricepackPersistenceMock.Object,regformPersistenceMock.Object,attendeePersistenceMock.Object);
Assert.AreEqual(eventservice.EventLists().Count, 10);
Assert.AreEqual(eventservice.CustomizedQuestions(1).EventMngID, 1);
Assert.IsTrue(eventservice.DeletePage(currentevent.EventMngID));
eventPersistenceMock.Verify();
pricepackPersistenceMock.Verify();
regformPersistenceMock.Verify();
attendeePersistenceMock.Verify();
}
private IEnumerable<tbl_SBAem_PricePackages> GetPricepacks()
{
var listtblsbaemPricePackages = new List<tbl_SBAem_PricePackages>();
for (var i = 0; i < 10; i++)
{
var tblsbaemPricePackages = new tbl_SBAem_PricePackages
{
PP_AID = 1
,
PP_AccessLevel = "Access Level"
,
PP_AttendeeCount = 50
,
PP_Cost = (decimal?)34.45
,
PP_Desc = "Pricepacks Description"
,
PP_EnforceCount = 1
,
PP_EventID = i
,
PP_GID = 1
,
PP_Name = "Name"
,
PP_Tax = (decimal?)23.12
,
PricePackageID = i
};
listtblsbaemPricePackages.Add(tblsbaemPricePackages);
}
return listtblsbaemPricePackages;
}
private IEnumerable<tbl_SBAem_Event> GetEvents()
{
var listtblsbaemConfig = new List<tbl_SBAem_Event>();
for (var i = 0; i < 10; i++)
{
var tblSbAemEvent = new tbl_SBAem_Event
{
EventMngID = i
,
EM_AID = null
,
EM_Agree1Name = "Rene agree"
,
EM_Agree1Value = "Yes"
,
EM_Agree2Name = "Tessa Agree"
,
EM_Agree2Value = "Yes"
,
EM_AllowSignup = null
,
EM_BccNotify = "rene_florendo#yahoo.com.ph"
,
EM_ChargeTiming = "10:00 am"
,
EM_ContactEmail = "rene.florendo#codelean.com"
,
EM_ContactName = "Rene Florendo"
,
EM_ContactPhone = "1234567"
,
EM_CurAttendee = null
,
EM_Date = DateTime.Now
,
EM_Description = "It's me rene"
,
EM_EditStatus = null
,
EM_EmailIntro = "Hey dear I am rene"
,
EM_EmailMessage = "I love you"
,
EM_GID = null
,
EM_GuestPass = "guessPass"
,
EM_GuestUser = "rene"
,
EM_Image = "image1.png"
,
EM_Instructions = "just me"
,
EM_Link = "htpp://yahoo.com"
,
EM_Location = "makati city"
,
EM_MapLink = "http://google.com/image.png"
,
EM_MaxAttendee = null
,
EM_RegEnd = new DateTime(2012, 4, 16)
,
EM_RegStart = new DateTime(2012, 4, 16)
,
EM_ReqAddress = null
,
EM_ReqEmail = 1
,
EM_ReqOrg = 1
,
EM_ReqPhone = 1
,
EM_ReqPhone2 = 1
,
EM_ReqTitle = 1
,
EM_ShowShip = 1
,
EM_SkipAttendee = 1
,
EM_Time = "10:00 am"
,
EM_Type = "Type A"
,
EM_isTemplate = 1
,
EM_name = "Name me"
,
EM_opt1Name = "optName1"
,
EM_opt1Values = "optValues1"
,
EM_opt2Name = "optName2"
,
EM_opt2Values = "optValues2"
,
EM_opt3Name = "optName3"
,
EM_opt3Values = "optValues3"
,
EM_opt4Name = "optName4"
,
EM_opt4Values = "optValues4"
,
EM_opt5Name = "optName5"
,
EM_opt5Values = "optValues5"
,
EM_opt6Name = "optName6"
,
EM_opt6Values = "optValues6"
,
EM_reqAgree1 = null
,
EM_reqAgree2 = null
,
EM_reqOpt1 = 1
,
EM_reqOpt2 = 1
,
EM_reqOpt3 = 1
,
EM_reqOpt4 = 1
,
EM_reqOpt5 = 1
,
EM_reqOpt6 = 1
};
listtblsbaemConfig.Add(tblSbAemEvent);
}
return listtblsbaemConfig;
}
}
}
Sorry it's been a while and you probably have got the issue resolved for thousands of times.
But I met this problem today too and I've got some idea about the error.
"The following setups were not matched" means you have a mock setup, but never called.
It means you suppose
pricepack.Delete(a)
should be called. But in reality it is never called.
If you know why this is not called and you think it's a correct behaviour, just delete the setup. Otherwise you might need to investigate why this is not called.
Change the statement pricepackPersistenceMock.Setup(pricepack => pricepack.Delete(It.Is<tbl_SBAem_PricePackages>(a => a.PP_EventID == currentevent.EventMngID))).Verifiable(); to
pricepackPersistenceMock.Setup(pricepack => pricepack.Delete(It.IsAny<Func<tbl_SBAem_PricePackages, bool>>())).Verifiable();
public void EventService_Return_10_Events()
{
var eventPersistenceMock = new Mock<IEventRepository>();
var pricepackPersistenceMock = new Mock<IPricePackRepository>();
var regformPersistenceMock = new Mock<IRegFormRepository>();
var attendeePersistenceMock = new Mock<IAttendeeRepository>();
var eventlists = GetEvents();
var pricepacks = GetPricepacks();
var currentevent = eventlists.ToList()[1];
eventPersistenceMock.Setup(r => r.GetAll()).Returns(eventlists);
eventPersistenceMock.Setup(u => u.Single(It.IsAny<Func<tbl_SBAem_Event, bool>>())).Returns(eventlists.Where(a => a.EventMngID == currentevent.EventMngID).Single());
eventPersistenceMock.Setup(r => r.Delete(currentevent)).Verifiable();
eventPersistenceMock.Setup(r => r.SaveChanges()).Verifiable();
pricepackPersistenceMock.Setup(pricepack => pricepack.GetAll()).Returns(pricepacks);
pricepackPersistenceMock.Setup(pricepack => pricepack.Delete(It.IsAny<Func<tbl_SBAem_PricePackages, bool>>())).Verifiable();
pricepackPersistenceMock.Setup(pricepack => pricepack.SaveChanges()).Verifiable();
regformPersistenceMock.Setup(rgform => rgform.Delete(It.IsAny<Func<tbl_SBAem_RegForm,bool>>())).Verifiable();
regformPersistenceMock.Setup(rgform => rgform.SaveChanges()).Verifiable();
attendeePersistenceMock.Setup(atnd => atnd.Delete(It.IsAny<Func<tbl_SBAem_Attendee,bool>>())).Verifiable();
attendeePersistenceMock.Setup(atnd => atnd.SaveChanges()).Verifiable();
var eventservice = new EventService(eventPersistenceMock.Object,pricepackPersistenceMock.Object,regformPersistenceMock.Object,attendeePersistenceMock.Object);
Assert.AreEqual(eventservice.EventLists().Count, 10);
Assert.AreEqual(eventservice.CustomizedQuestions(1).EventMngID, 1);
Assert.IsTrue(eventservice.DeletePage(currentevent.EventMngID));
eventPersistenceMock.Verify();
pricepackPersistenceMock.Verify();
regformPersistenceMock.Verify();
attendeePersistenceMock.Verify();
}

Resources