GJs/Seed GtkSourceView - seed

I can get a Gtk.TextView working with the following code—
const Gtk = imports.gi.Gtk;
let mtext1 = new Gtk.TextView();
However, I would rather use a GtkSourceView, as it has line numbers. How can I do this? I can't find much documentation around the subject.
Thanks!

Import the GtkSource library:
const GtkSource = imports.gi.GtkSource;
let mtext1 = new GtkSource.View();

Related

is there any way to switch ImageJ macro code to python3 code?

I'm making an app in python3 and I want to use some function in imagej. I used macro recorder to switch to python code but it got really messy, now I don't know how to do next. Can someone help me, please.
Here is the marco recorder code and my marco code
imp = IJ.openImage("D:/data/data_classify/data_train/1/9700TEST.6.tiff40737183_2.jpg");
//IJ.setTool("line");
//IJ.setTool("polyline");
xpoints = [177,155,114,101,100,159,179];
ypoints = [82,94,109,121,133,163,173];
imp.setRoi(new PolygonRoi(xpoints,ypoints,Roi.POLYLINE));
IJ.run(imp, "Straighten...", "title=9700TEST.6.tiff40737183_2-1.jpg line=30");
my python3 code
mport imagej
from scyjava import jimport
ij = imagej.init('2.5.0', mode='interactive')
print(ij.getVersion())
imp = ij.IJ.openImage("D:/data/data_classify/data_train/1/9700TEST.6.tiff40737183_2.jpg")
xpoints = [177,155,114,101,100,159,179]
xpoints_int = ij.py.to_java(xpoints)
ypoints = [82,94,109,121,133,163,173]
ypoints_int = ij.py.to_java(xpoints)
straightener = jimport('ij.plugin.Straightener')
polyRoi = jimport('ij.gui.PolygonRoi')
and I don't know how to do next...
After a few days, I finally found the answer. It is important to understand the parameters of the function to write, I have referenced in:
https://pyimagej.readthedocs.io/en/latest/
https://imagej.nih.gov/ij/developer/api/ij/module-summary.html
in my example the next thing i need is polygonroi from the given coordinates. I found the required coefficients of PolygonRoi in the above website and determined to take as parameters PolygonRoi​(int[] xPoints, int[] yPoints, int nPoints, int type)
Next, I found a way to convert my list of coordinates to an int[] which was shown in the pyimagej tutorial.
In the type section, I can find it by trying print(int(roi.PolygonRoi)) and the result is 6, you can also find the reason in the website above in the Roi section
The rest, the last thing you need to do is put that PolygonRoi into the Straightener function with the line value you want
Here is my code for using macro Imagej in Python3
import imagej
from scyjava import jimport
from jpype import JArray, JInt
ij = imagej.init('2.5.0', mode='interactive')
print(ij.getVersion())
imp = ij.IJ.openImage("D:/AI lab/joint_detection/data/1/9700TEST.6.tiff133328134_1.jpg")
xpoints = [124,126,131,137,131,128,121,114]
xpoints_int = JArray(JInt)(xpoints)
ypoints = [44,63,105,128,148,172,194,206]
ypoints_int = JArray(JInt)(ypoints)
straightener = jimport('ij.plugin.Straightener')
polyRoi = jimport('ij.gui.PolygonRoi')
roi = jimport('ij.gui.Roi')
new_polyRoi = polyRoi(xpoints_int,ypoints_int,len(xpoints), int(roi.POLYLINE))
imp.setRoi(new_polyRoi)
straightened_img = ij.IJ.run(imp, "Straighten...", "title=9700TEST.6.tiff40737183_2-1.jpg line=30")
ij.IJ.saveAs(straightened_img, 'Jpeg', './test.jpg')

Try to reverse an bytearray(from hex) in python

I have the following script:
hex_string = "c23dba5fcac1048b3c050266ceb6a0e870670021"
hex_bytes = bytearray.fromhex(hex_raw)
print(hex_bytes.reverse())
The problem it prints/returns None. I was wondering, because in this example it works.
Thanks in advance.
I found the issue. The method .reverse() dont return anything, but changes the bytearray, so the code must be:
hex_string = "c23dba5fcac1048b3c050266ceb6a0e870670021"
hex_bytes = bytearray.fromhex(hex_raw)
hex_bytes.reverse()
print(hex_bytes)

where can I find make_labels?

I do not find make_labels
I thought it would be part of the independent package utils. But I guess it was part of featuretools.
it featuretools.utils
you just have make_temporal_cutoffs instead. So how do you use that? Waht would be the translation of the example code:
label_times = pd.concat([utils.make_labels(es=instacart_es,
product_name = "Banana",
cutoff_time = pd.Timestamp('March 15, 2015'),
prediction_window = ft.Timedelta("4 weeks"),
training_window = ft.Timedelta("60 days"))
found out!
make_label is not part of featuretool but of the example repository
https://github.com/Featuretools/predict-next-purchase

Creating and mounting volumes with docker.py

I've been looking through the documentation and some tutorials but I cannot seem to find anything current on how to create a volume using the docker.py library. Nothing I've found appears to be current as the create_host_config() method appears to be non-existent. Any help in solving this issue or a push in the right direction would be greatly appreciated. Thanks to all of you.
I've searched the documentation on:
https://docker-py.readthedocs.io/en/stable/
https://github.com/docker/docker-py
I tried using this old stack overflow example:
How to bind volumes in docker-py?
I've also tried the client.volumes.create() method.
I'm trying to write a class to make docker a bit easier for most people to deal with in python.
import docker
VOLUMES = ['/home/$USER', '/home/$USER/Desktop']
def mount(volumes):
mount_points = []
docker_client = docker.from_env()
volume_bindings = _create_volume_bindings(volumes)
host_config = docker_client.create_host_config(binds=volume_bindings)
def _create_volume_bindings(volumes):
volume_bindings = {}
for path in range(len(volumes)):
volume_bindings[volumes[path]] = {'bind': 'mnt' + str(path + 1),
'mode': 'rw'}
return volume_bindings
Perhaps you want to use the Low-level API client?
If yes, you can try to replace the line
docker_client = docker.from_env()
with
docker_client = docker.APIClient(base_url='unix://var/run/docker.sock')
That one has the create_host_config() method.

How to include multiple file extensions with 'glob.sync' in NodeJS?

Can anyone please suggest how to add multiple file extensions with the glob.sync method.
Something like:
const glob = require('glob');
let files = glob.sync(path + '**/*.(html|xhtml)');
Thank you :)
You can use this (which most shells support as well):
glob.sync(path + '**/*.{html,xhtml}')
Or one of these:
glob.sync(path + '**/*.+(html|xhtml)')
glob.sync(path + '**/*.#(html|xhtml)')

Resources