cannot set position of wx.frame on openbox - python-3.x

i am playing with wxPython and try to set position of frame:
import wx
app = wx.App()
p = wx.Point(200, 200)
frame = wx.Frame(None, title = 'test position', pos = p)
frame.Show(True)
print('frame position: ', frame.GetPosition())
app.MainLoop()
even though print('frame position: ', frame.GetPosition()) shows the correct postion, the frame is shown in top left corner of screen.
Alternatively i tried
frame.SetPosition(p)
frame.Move(p)
without success.
my environment: ArchLinux 5.3.13, python 3.8.0, wxpython 4.0.7, openbox 3.6.1
On cinnamom the code works as expected. How to solve this on openbox?
edit 07,12,2019:
i could set postion of a dialog in openbox config ~/.config/openbox/rc.xml:
<application name="fahrplan.py"
class="Fahrplan.py"
groupname="fahrplan.py"
groupclass="Fahrplan.py"
title="Fahrplan *"
type="dialog">
<position force="no">
<x>760</x>
<y>415</y>
</position>
</application>
i got name, class etc. from obxprop. x and y are calculated to center a dialog of 400 x 250 px on screen of 1920 x 1080 px.
This static solution is not suitable for me. I want to place dynamically generated popups.

I had the same problem under Windows and played around with the style flags. With wxICONIZE sytle set active the window finally used the positioning information

The position is provided to the window manager as a "hint". It is totally up to the window manager whether it will actually honor the hint or not. Check the openbox settings or preferences and see if there is anything relevant that can be changed.

Related

Aspect ration of a image for instagram

i want to change the aspect ratio of an image for the instagram with python .here is my code for change the aspact ration :
width,height=imageFile.size
aspectRatio = width/height
if(aspectRatio>=0.80 and aspectRatio<=1.90):
print("yeah")
else:
if(height>width):
futureHeight = width/.85
print(str(width)+" ,"+str(futureHeight))
print(width/futureHeight)
left = 0
int(futureHeight)
teetet = height-futureHeight/2
top = teetet / 4
right = width
bottom = height -150
im1 = imageFile.crop((left, top, right, bottom))
print(im1.size)
im1.show()
im1.save(image)
but still it show
ValueError: Incompatible aspect ratio.
whenever i try to upload this image
i resolved that using basic dimensions. using the inspector i saw that instagram convert images to 598.02x598.02 in the home page, so i typed:
im=PIL.Image.open(path)
im=im.resize((598,598), Image.ANTIALIAS)
im.save(path) # overwrite the image
instead of
im=PIL.Image.open(path)
baseheight = 560
hpercent = (baseheight / float(im.size[1]))
wsize = int((float(im.size[0]) * float(hpercent)))
im=im.resize((wsize, baseheight), PIL.Image.ANTIALIAS)
im.save(path)
in wich aspect ratio is out of range anyway.
now you can post it using something like instabot without troubles 'cause the aspect ratio is 1.0 .

I can not calibrate correct accurate for resistive touch screen on Kivy app

I have a problem with my 5 inch resistive touch screen which I need to calibrate touch on Kivy app. My touch in Raspberry pi is correctly calibrated but when it comes to Kivy app it is not correct.
How can I calibrate the touch to get accurate touch in my Kivy app (GUI). I am using Raspberry pi 3 with Raspbian os (full version not lite) this.
Take a look at the configuration options for Kivy's mtdev input module: https://kivy.org/docs/api-kivy.input.providers.mtdev.html - in particular max_position_x, min_position_y, etc. From the documentation:
You can use a custom range for the X, Y and pressure values. On some drivers, the range reported is invalid. To fix that, you can add these options to the argument line:
invert_x : 1 to invert X axis
invert_y : 1 to invert Y axis
min_position_x : X minimum
max_position_x : X maximum
min_position_y : Y minimum
max_position_y : Y maximum
min_pressure : pressure minimum
max_pressure : pressure maximum
min_touch_major : width shape minimum
max_touch_major : width shape maximum
min_touch_minor : width shape minimum
max_touch_minor : height shape maximum
rotation : 0,90,180 or 270 to rotate
In ~/.kivy/config.ini, you should put something like this:
[input]
mtdev_%(name)s = probesysfs,provider=mtdev,max_position_x=12345,max_position_y=12345
This is if you're using mtdev, but you can also use hidinput from kernel 2.6.34 onwards. See also: https://kivy.readthedocs.io/en/master/api-kivy.input.providers.hidinput.html

DPI aware screen capture

I used AutoIt's _ScreenCapture_Capture() before without any trouble. But on Windows 10 with a 4k resolution screen I'm using DPI scaling at 200%. _ScreenCapture_capture() now gets something 2x zoomed in and half the location I asked for.
For instance :
_ScreenCapture_Capture("c:\a.bmp", 100, 100, 200, 200)
; Path, X1, Y1, X2, Y2
Does not return a 100x100 pixel square of the screen (at 100,100 to 200,200). It returns a 100x100 pixel square (at 50,50 to 100,100) instead.
I did find a solution :
DllCall("User32.dll", "bool", "SetProcessDPIAware")
However this screws up the GUI looks. So I then found this code:
GUISetFont(8.5 * _GDIPlus_GraphicsGetDPIRatio()[0])
Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
Local $aResults[2] = [1, 1]
_GDIPlus_Startup()
Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
If #error Then Return SetError(1, #extended, $aResults)
#forcedef $__g_hGDIPDll, $ghGDIPDll
$aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
If #error Then Return SetError(2, #extended, $aResults)
Local $iDPI = $aResult[2]
Local $aresults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_Shutdown()
Return $aresults
EndFunc ;==>_GDIPlus_GraphicsGetDPIRatio
Which works great for the GUI but doesn't help for _ScreenCapture_Capture() calls. Seems I can either have a good looking- or a functioning program, not both.
How could I combine these two solutions to get both a good GUI and a functioning program? If I knew how to do the opposite of :
DllCall("User32.dll", "bool", "SetProcessDPIAware")
Then when I need to capture a screen portion I could turn on compatibility, then immediately turn it off when done capturing. But I don't know how to 'UNsetprocessdpiaware'.
If you are using Windows 10 A update (10.0.14393) you can spin up a separate thread and make the thread alone Per Monitor DPI aware, and leave your main GUI as dpi unaware.
See
SetThreadDpiAwarenessContext function
If you are building using a version of visual studio before 2015 you can declare a pointer to the function prototype
DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext(
_In_ DPI_AWARENESS_CONTEXT dpiContext
);
and use GetProcAddress to test for the presence of the function before you call it. Anything in that thread will give you raw physical information if you used
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
Note that this function is not available on Windows 10 10.0.10586. You must test for its availability.

How do I properly reset the clip in cairocffi?

I am trying to write a module for myself for doing some simple drawing with cairocffi to make using the package a bit less cumbersome. However, I seem to have run into some trouble with properly implementing clipping. Specifically, I am having trouble properly resetting the clipping region.
I wrote an example Python script, whose result should be a PostScript file with:
1 red circle (circle_1)
1 black line from the bottom left to the top right of the circle (line1)
1 black line from the top left of the image to the bottom right of the image (line2)
Instead of line2 extending from corner to corner, though, it is still being clipped by the previous call to clip().
Here's the example script:
import cairocffi as cairo
from math import pi
fig_w, fig_h = 237.6, 237.6
test_surf = cairo.PSSurface('test.ps', fig_w, fig_h)
temp_surf = cairo.PSSurface('temp.ps', fig_w, fig_h)
line1 = cairo.Context(temp_surf)
line1.move_to(0, fig_h)
line1.line_to(fig_w, 0)
line1.set_source_rgb(0,0,0)
line1.stroke()
circle_1 = cairo.Context(test_surf)
circle_1.arc(fig_w/2, fig_h/2, fig_w/4, 0, 2*pi)
circle_1.close_path()
circle_1.set_source_rgb(1,0,0)
circle_1.stroke_preserve()
circle_1.set_source_surface(temp_surf)
with circle_1:
circle_1.clip()
circle_1.paint()
line2 = cairo.Context(test_surf)
line2.reset_clip()
line2.move_to(0, 0)
line2.line_to(fig_w, fig_h)
line2.set_source_rgb(0,0,0)
line2.stroke()
I'm not really sure what I'm doing wrong. This seems to be how the cairocffi documentation would suggest that it should be done (i.e., see reset_clip() and save()).
If anyone can point out what I'm doing incorrectly, I'd really appreciate it.

R simplify heatmap to pdf

I want to plot a simplified heatmap that is not so difficult to edit with the scalar vector graphics program I am using (inkscape). The original heatmap as produced below contains lots of rectangles, and I wonder if they could be merged together in the different sectors to simplify the output pdf file:
nentries=100000
ci=rainbow(nentries)
set.seed=1
mean=10
## Generate some data (4 factors)
i = data.frame(
a=round(abs(rnorm(nentries,mean-2))),
b=round(abs(rnorm(nentries,mean-1))),
c=round(abs(rnorm(nentries,mean+1))),
d=round(abs(rnorm(nentries,mean+2)))
)
minvalue = 10
# Discretise values to 1 or 0
m0 = matrix(as.numeric(i>minvalue),nrow=nrow(i))
# Remove rows with all zeros
m = m0[rowSums(m0)>0,]
# Reorder with 1,1,1,1 on top
ms =m[order(as.vector(m %*% matrix(2^((ncol(m)-1):0),ncol=1)), decreasing=TRUE),]
rowci = rainbow(nrow(ms))
colci = rainbow(ncol(ms))
colnames(ms)=LETTERS[1:4]
limits=c(which(!duplicated(ms)),nrow(ms))
l=length(limits)
toname=round((limits[-l]+ limits[-1])/2)
freq=(limits[-1]-limits[-l])/nrow(ms)
rn=rep("", nrow(ms))
for(i in toname) rn[i]=paste(colnames(ms)[which(ms[i,]==1)],collapse="")
rn[toname]=paste(rn[toname], ": ", sprintf( "%.5f", freq ), "%")
heatmap(ms,
Rowv=NA,
labRow=rn,
keep.dendro = FALSE,
col=c("black","red"),
RowSideColors=rowci,
ColSideColors=colci,
)
dev.copy2pdf(file="/tmp/file.pdf")
Why don't you try RSvgDevice? Using it you could save your image as svg file, which is much convenient to Inkscape than pdf
I use the Cairo package for producing svg. It's incredibly easy. Here is a much simpler plot than the one you have in your example:
require(Cairo)
CairoSVG(file = "tmp.svg", width = 6, height = 6)
plot(1:10)
dev.off()
Upon opening in Inkscape, you can ungroup the elements and edit as you like.
Example (point moved, swirl added):
I don't think we (the internet) are being clear enough on this one.
Let me just start off with a successful export example
png("heatmap.png") #Ruby dev's think of this as kind of like opening a `File.open("asdfsd") do |f|` block
heatmap(sample_matrix, Rowv=NA, Colv=NA, col=terrain.colors(256), scale="column", margins=c(5,10))
dev.off()
The dev.off() bit, in my mind, reminds me of an end call to a ruby block or method, in that, the last line of the "nested" or enclosed (between png() and dev.off()) code's output is what gets dumped into the png file.
For example, if you ran this code:
png("heatmap4.png")
heatmap(sample_matrix, Rowv=NA, Colv=NA, col=terrain.colors(32), scale="column", margins=c(5,15))
heatmap(sample_matrix, Rowv=NA, Colv=NA, col=greenred(32), scale="column", margins=c(5,15))
dev.off()
it would output the 2nd (greenred color scheme, I just tested it) heatmap to the heatmap4.png file, just like how a ruby method returns its last line by default

Resources