POWERSHELL tooltip on mousehover listbox item - winforms

I do a Powershell GUI, i want to use a tooltip on a listbox,
but i'm not familiar with events and event handlers, i don't find help for powershell/winform event on Microsoft.com
Below my listbox is $listbox_groupe_import
#Infobulle au survol pour voir les tables d'un groupe de table
$obj_infobulle = New-Object System.Windows.Forms.ToolTip
$obj_infobulle.InitialDelay = 100
$obj_infobulle.ReshowDelay = 100
#Sélectionne tous les groupes de tables dans la base de données et les met dans une liste déroulante
$listbox_groupe_import = Get-ListboxGroup
#Création d'une info bulle pour la Listbox.
$obj_infobulle.SetToolTip($listBox_groupe_import, "tooltip sur listbox")
I want to set the tooltip on mousehover
I found this but i don't know how to execute it :
$listboxGroupe_MouseMove = [System.Windows.Forms.MouseEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
#TODO: Place custom script here
#index vaut ce qu'on pointe avec la souris au dessus de listbox1
$index = $listBox_groupe.IndexFromPoint($_.Location) #$_ => this (listbox.location) je crois
##"index ="+$index
##$tooltip1.SetToolTip($listBox_groupe, "index ="+$index)
if ($index -ne -1){
#Tooltype sur listbox1 = valeur de l'item pointé
$tooltip1.SetToolTip($listBox_groupe, $listBox_groupe.Items[$index].ToString())
}
else{
#on n'est pas au dessus de listBox_groupe
$tooltip1.SetToolTip($listBox_groupe, "")
}
}
Can you tell me how to execute this code by mousehover on my listbox?
Or another way to display tooltip with different text for each item of my listbox ?
Thank you

Can you tell me how to execute this code by mousehover on my listbox?
To find the mouse location in hover event, first you can use Control.MousePosition to find the mouse screen location and then using ListBox.PointToClient, convert it to mouse position on the control. Then the rest of logic is similar to what you already have:
$point = $listBox.PointToClient([System.Windows.Forms.Control]::MousePosition)
$index = $listBox.IndexFromPoint($point)
if($index -ge 0) {
$toolTip.SetToolTip($listBox, $listBox.GetItemText($listBox.Items[$index]))
}
else {
$toolTip.SetToolTip($listBox, "")
}
Just to make it a bit better, I used ListBox.GetItemText method which is better than ToString method of items. In case that you set a complex object as data source of the list box and set display member property, it extracts the item text based on the display name, otherwise it returns ToString of the item.
Also don't forget, to handle MouseHover event, you need to use Add_MouseHover.

Solution :
#Au survol
$listBox_groupe.add_MouseEnter({
#récupérer la position de la souris
$point = $listBox_groupe.PointToClient([System.Windows.Forms.Control]::MousePosition)
#récupérer l'indice de l'item sur lequel on pointe
$index = $listBox_groupe.IndexFromPoint($point)
if($index -ge 0) {
#l'infobulle est au dessus de listBox_groupe et elle a pour texte le texte de l'item
$tooltip1.SetToolTip($listBox_groupe, $listBox_groupe.GetItemText($listBox_groupe.Items[$index]))
}
})

Here's the documentation. Particularly, look at the events at the bottom. There is a MouseHover event that you'll want to add:
$MyListBox.add_MouseHover({
# display your tooltip here
})
$MyListBox.add_MouseLeave({
# remove the tooltip now that user moved away
})
PowerShell GUIs and event handlers aren't very well documented since you usually want to handle this sort of thing in C#.

Related

Send with ruby request with array

I have to make a request to an API, and one of the properties of the body is an Array (Directorios), my question is, how to send it as an array type, and not as a string as I show it in the following code
require 'uri'
require 'net/http'
require 'json'
UbicacionesCambios = Array.new
UbicacionesCambios.push("/Codigo/WebApi/Bccr.WebApi.Auten.csproj")
UbicacionesCambios.push("/Codigo/WebApi/Bccr.WebApi.Auten.csproj1")
#Actualizacion de codigo de nuget BCCR
temp = ""
puts " Preparacion de actualizacion"
uri = URI('http://localhost/api/Devops.API/migrador?api-version=1')
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
req.body = {
"id":"9dedf35e-7df-4992-b03d-edfe24c302a9",
"NombreProyecto":"WebApi",
"NombreColeccion":"Insti",
"AzureHostName":"http://mydomain:8080/tfs",
"Rama":"test",
"UltimoCommit":"f4afdfasdfasdfasdfadsfdsfdda2faf00c25a0a",
"Componente":"WebApi.Nuget",
"Version":"1.0.0.1",
"Directorios": ["#{UbicacionesCambios}"]
#"Directorios":["1","2"]
}.to_json
puts " Ejecucion de actualizacion codigo nugets BCCR"
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
puts res.body if res.is_a?(Net::HTTPSuccess)
puts " Resultado actualizacion de codigo #{res.body}"
Why when it reaches the Api, it is shown like this
["/Codigo/WebApi/Bccr.WebApi.Auten.csproj", "/Codigo/WebApi/Bccr.WebApi.Auten.csproj1"]
an array of a single field
You are forcing array to evaluate as string there. UbicacionesCambios is already an array You can just do it like this:
req.body = {
# ...
"Directorios": UbicacionesCambios
}

SuiteCRM invoice and ticket number

how can I make an unique number for invoice and ticketing system, something like
for tickets: ST-{yymm}-0000001
for Invoice: IN-{yymm}-0000001
Thank you
I recomend you create first a field that will be use to generate the code.
Once you have the field you have different options.
1- Assign that column in the database directly as autonumeric
2- Use a Logic Hook before_save that will be calculating the code in each save. For example:
<?php
//prevents directly accessing this file from a web browser
if(!defined('sugarEntry') ||!sugarEntry) die('Not A Valid Entry Point');
class CrearCodigoAutonumerico
{
public function CrearCodigoAutonumerico(&$bean, $event, $arguments)
{
// Si el campo está vacío...
if(empty($bean->codigo_c)) {
// Obtener el último código asignado
$db = DBManagerFactory::getInstance();
$query = "SELECT codigo_c
FROM <table_module>
ORDER BY codigo_c DESC LIMIT 1";
$result = $db->getOne($query, true);
$ultimo_codigo = $result;
// Calcular y asignar el nuevo código
$bean->codigo_c = $ultimo_codigo + 1;
}
}
}
Once you have this, you can create one more Logic Hook before save that constructs the name as you need it.

How to disable inference in hermiT

I am using OWL-Api and hermiT reasoner, while trying to retrieve the partOf subClasses using hermiT, it give back the right result, so the partOf subclasses, but it also give back the inferenced subclasses (which i don't need).
This is the function used to retrieve the partOf subClasses:
//ricerca delle classi che hanno come parti quella attuale
System.out.println("Questa classe è parte di: ");
OWLClassExpression domain = df.getOWLObjectIntersectionOf((Stream<? extends OWLClassExpression>) ontologia.objectPropertyDomainAxioms(partOf));
NodeSet<OWLClass> subClassesInDomain = hermit.getSubClasses(domain, false);
if(subClassesInDomain.isEmpty()) {
System.out.println("\tQuesta classe non è parte di nessun'altra");
}
else {
for(Node<OWLClass> parteDi : subClassesInDomain) {
OWLClass classe2 = parteDi.getRepresentativeElement();
System.out.println("\t"+ classe2.getIRI().getFragment());;
}
}
In this image, it is provided the actual result of the operation.
given result
In this, it is shown the result i need.
wanted result
Is there a way to disable hermiT inference engine only for this operation?
hermit.getSubClasses(domain, false);
Change this to
hermit.getSubClasses(domain, true);
To retrieve only direct subclasses.

How to get width of a dynamically created element with $comiple in Angularjs

So I want to create an element in angular and append it to DOM :
//in my directive I've created an element as bellow :
el = $compile('<span>Hello dynamically</span>')($scope);
// and then I appended it to my DOM like this :
myDomElement.append(el);
So far so good , no errors no nothing .
All I'm looking for is to how to get the width of this el that I've created in my directive ?
Normally when I want to get width of an element I'll get the offsetWidth of that element ,
I'm looking for something like this :
el = $compile('<span>Hello dynamically</span>')($scope);
var width = el.offsetWidth ; // I want the width here !!
console.log(width); // will log 0 !!!!!!
console.log(el); // will show an Object that has a **offsetWidth:134** property !!!!!!!
myDomElement.append(el);
But when I log this , I always get 0 , it's weird because when I look at my developer tools in chrome I can see that offsetWidth is not 0 !
Do this :
el = $compile('<span>Hello dynamically</span>')($scope);
myDomElement.append(el);
var width = el.offsetWidth ; // I want the width here !!
console.log(width);
Means first append the element to DOM , then get it's width

how to insert data into the db in cakephp

Hi I have a for that has one field (url) and I want to insert the URL typed in the form to the DB
My function add in my controller looks like this:
public function add(){
if($this->request->is('post')){
// debug($this->Link->find('all'));//this works
$link = $this->Link->findByUrl($this->request->data['link']['url']);
if(empty($link)){
//I will create the link
$this->Link->create($this->request->data, true);//true = ignoring the ID
$this->Link->save(null, true, array('url'));
//null = because I ready wrote "$this->request->data" in create
//true = I want to use VALIDATION
//array = I choose to SAVE this field only
echo "I've created the link";
die($this->Link->id);
}else {
debug($link);
die("The link is already in the database");
//je dois récupérer le lien
}
}
How can I insert into the DB the links entered?
Not sure which version of Cake you're using, but the way this would normally work is:
create() new reference
set() new data
save() reference
Example:
$this->Link->create();
$this->Link->set($this->request->data['link']);
$save = $this->Link->save();
echo $save ? "I've created the link" : "Error creating link!";
die($this->Link->id);

Resources