Failing to draw on a Gtk.DrawingArea - gtk

I'm not able to draw, i've already read tutorials, i can't find the problem.
I simply have a correct UI drawed by Glade. Then i want to draw, for example 50 drawing areas. So i create a Grid with 50 cells; for each cell there is a vertical box (with a drawing area and a label inside each one). But i can't seen anything drawed.
class collega_GUI:
def __init__(self):
try:
self.__builder = Gtk.Builder()
self.__builder.add_from_file('UI2.glade')
self.__Grid = Gtk.Grid()
self.__Grid.set_margin_left(20)
self.__Grid.set_margin_right(20)
self.__Grid.set_row_spacing(10)
self.__Grid.set_column_spacing(15)
self.__Grid.set_column_homogeneous(True)
self.__GridBox = self.__builder.get_object('box11')
self.__GridBox.pack_end(self.__Grid, 1, 1, 20)
indirizzi_ip = []
for i in range(50):
indirizzi_ip.append(str(i))
cpu_info = {}
for ip in indirizzi_ip:
cpu_info[ip] = dict()
left = 0
right = 0
for ip in indirizzi_ip:
cpu_info[ip]['drawing_area'] = Gtk.DrawingArea()
cpu_info[ip]['drawing_area'].set_size_request(100, 100)
cpu_info[ip]['drawing_area'].set_name(ip)
box = Gtk.VBox(False, 5)
box.add(cpu_info[ip]['drawing_area'])
label = Gtk.Label(ip)
box.add(label)
self.__Grid.attach(box, left, right, 1, 1) #object,left,right,top,bottom
cpu_info[ip]['drawing_area'].connect("draw", self.__draw)
label.show()
cpu_info[ip]['drawing_area'].show() #the draw should start now!
box.show()
# 5 drawing areas in a row
left += 1
if left == 5:
right += 1
left = 0
self.__builder.get_object('Azioni_Window').show()
Gtk.main()
except Exception as xe:
logging.error('%s' % str(xe))
sys.exit()
def __draw(self, widget, context):
context.set_source_rgb(0.9, 0, 0.1) #rosso
context.set_source_rgb(0.1, 0.9, 0) #verde
context.set_source_rgb(0.8, 0.7, 0) #giallo
context.set_source_rgb(0.8, 0.7, 0.8) #inattivo
context.rectangle(0, 0, widget.get_allocated_width(), widget.get_allocated_height())
context.fill()
if __name__=='__main__':
try:
UINX=collega_GUI()
except Exception:
sys.exit()

You're missing
self.__Grid.show()
And hence nothing in the grid is shown.
In general it's easier to just call show_all() on some top-level container rather than trying to remember to show() every individual widget.

Related

How to use SceneKit vortex field to create a tornato effect

In the SceneKit WWDC 2014, they have an example of a vortex field with this effect:
The particle system looks much like a tornato, as it spins inward with a hollow center.
However, the documentation for vortex fields have no information on how to achieve this effect. Right now, I have this:
// create the particle system
let exp = SCNParticleSystem()
exp.loops = true
exp.particleMass = 5
exp.birthRate = 10000
exp.emissionDuration = 10
exp.emitterShape = SCNTorus(ringRadius: 5, pipeRadius: 1)
exp.particleLifeSpan = 15
exp.particleVelocity = 2
exp.particleColor = UIColor.white
exp.isAffectedByPhysicsFields = true
scene.addParticleSystem(exp, transform: SCNMatrix4MakeRotation(0, 0, 0, 0))
// create the field
let field = SCNPhysicsField.vortex()
field.strength = -5
field.direction = SCNVector3(x: 0, y: 1, z: 0)
let fieldNode = SCNNode()
fieldNode.physicsField = field
scene.rootNode.addChildNode(fieldNode)
This creates this effect:
Where I am looking down at the particles rotating clockwise with a really big radius outwards. It looks nothing like a tornato effect. How can I create this effect?
You say tornato, I say tornado, let’s call the whole thing off...
The SceneKit WWDC 2014 demo/slides is a sample code project, so you can see for yourself how they made any of the effects you see therein. In this case, it looks like the “vortex” demo isn’t actually using the vortexField API, but instead the custom field API that lets you supply your own math in an evaluator block. (See the link for the code in that block.)
You might be able to get similar behavior without a custom field by combining a vortex (causes rotation only) with radial gravity (attracts inward) with linear gravity (attracts downward), or some other combination (possibly something involving electric charge). But you’d probably have to experiment with tweaking the parameters quite a bit.
If anyone is still interested in this topic - here is a Swift 5 implementation of that legendary tornado effect.
Here is an example function that will create your tornado.
func addTornadoPhysicsField() {
// Tornado Particles Field Example
guard let tornadoSystem = SCNParticleSystem(named: "tornado.scnp", inDirectory: nil) else { return }
let emitterGeometry = SCNTorus(ringRadius: 1.0, pipeRadius: 0.2)
emitterGeometry.firstMaterial?.transparency = 0.0
let fieldAndParticleNode = SCNNode(geometry: emitterGeometry)
fieldAndParticleNode.position = SCNVector3(0.0, 0.0, -20.0)
tornadoSystem.emitterShape = emitterGeometry
fieldAndParticleNode.addParticleSystem(tornadoSystem)
yourScene.rootNode.addChildNode(fieldAndParticleNode)
// Tornado
let worldOrigin = SCNVector3Make(fieldAndParticleNode.worldTransform.m41,
fieldAndParticleNode.worldTransform.m42,
fieldAndParticleNode.worldTransform.m43)
let worldAxis = simd_float3(0.0, 1.0, 0.0) // i.Ex. the Y axis
// Custom Field (Tornado)
let customVortexField = SCNPhysicsField.customField(evaluationBlock: { position, velocity, mass, charge, time in
let l = simd_float3(worldOrigin.x - position.x, 1.0, worldOrigin.z - position.z)
let t = simd_cross(worldAxis, l)
let d2: Float = l.x * l.x + l.z * l.z
let vs: Float = 27 / sqrt(d2) // diameter, the bigger the value the wider it becomes (Apple Default = 20)
let fy: Float = 1.0 - Float((min(1.0, (position.y / 240.0)))) // rotations, a higher value means more turn arounds (more screwed, Apple Default = 15.0))
return SCNVector3Make(t.x * vs + l.x * 10 * fy, 0, t.z * vs + l.z * 10 * fy)
})
customVortexField.halfExtent = SCNVector3Make(100, 100, 100)
fieldAndParticleNode.physicsField = customVortexField // Attach the Field
}
Additional Configuration Options:
Finally all this can result in something like that:
Note: if you would like to move your static tornado almost like a real tornado, you will have to find a way to re-apply the physics field for each rendererd frame. If you don't, the world origin used in the evaluation block will not move and it will distort your tornado.
Note: You can also split the particle/field node into two different nodes that moves independently from each other. Constrain the field node to the position of the particle node and play around with the influence factor (still need to re-apply the field each frame)
For more information on Custom Fields check out here.

roblox CFrame not working properly

So here is the code:
local prt = Instance.new('Part',game.Workspace)
prt.Color = Color3.new(248, 248, 248)
prt.Size = Vector3.new(0.167, 5, 5)
prt.Rotation = Vector3.new(0, 0, math.rad(90))
prt.Anchored = true
prt.CFrame = CFrame.new(Vector3.new(19.1, 618.59, 116.85))
prt.Shape = "Cylinder"
what i want it to do is create a new part that is shaped like a cylinder, i want it to be a flat cylinder but it does the exact oppisite, it is standing up, i have tried many things.
The CFrame is setting the Rotation to 0,0,0. This is because you're doing CFrame.new() before prt.Rotation. If you did CFrame.new(Vector3.new(19.1,618.59,116.85)) * CFrame.Angles(0, 0, math.rad(90)), this would work and you can remove the "prt.Rotation" part.

How do i stop clipping of limit line text in ios-charts?

I have a requirement for drawing the limit line which is near to the top of the chart and I want to keep limit line label on top right. Is there any way, it can not be truncated. Please see my output.
enter image description here
try limitline.labelPosition = ChartLimitLabelPositionRightBottom;
if you want keep labelPosition on top right,
you may can try set yourYAxis.spaceTop = x;
if x == 0, the maxValue will match the top of the chart,
if x == 1, the maxValue will match the centerY of the chart,
sorry, I can't express myself well, but, just try it.
hope it works.
The default renderer is little bit messed up. Subclass it (YAxisRenderer) and override method: renderLimitLines. Copy the content from original renderer and replace lines:
var clippingRect = viewPortHandler.contentRect
clippingRect.origin.y -= l.lineWidth / 2.0
clippingRect.size.height += l.lineWidth
with:
var clippingRect = viewPortHandler.contentRect
clippingRect.origin.y -= l.lineWidth / 2.0 + l.valueFont.lineHeight
clippingRect.size.height += l.lineWidth + l.valueFont.lineHeight
Now, as you have it prepared, you need to set your new axis renderer for
let yAxisRenderer = CenteredLimitLineYAxisRenderer(
viewPortHandler: chart.viewPortHandler,
yAxis: chart.leftAxis,
transformer: chart.getTransformer(forAxis: .left)
)
chart.leftYAxisRenderer = yAxisRenderer

How do I create a series of layers from an array and for loop?

Basically, I need to create layers from five images. Is there a way to do this with a for loop, as opposed to manually creating the layers? The following code was my attempt, but I'm not sure how to debug from here.
tabs_strings = ["nearby", "adopted", "my_cats", "settings", "bruce"]
for tab in [0..tabs_strings]
tab = new Layer
x:0, y:0, width:640, height:1136, image:"images/#{tab}.jpg"
# nearby = new Layer
# x:0, y:0, width:640, height:1136, image:"images/nearby.jpg"
# adopted = new Layer
# x:0, y:0, width:640, height:1136, image:"images/adopted.jpg", opacity: 0
# my_cats = new Layer
# x:0, y:0, width:640, height:1136, image:"images/my_cats.jpg", opacity: 0
# settings = new Layer
# x:0, y:0, width:640, height:1136, image:"images/settings.jpg", opacity: 0
# bruce = new Layer
# x:0, y:0, width:640, height:1136, image:"images/bruce.jpg", opacity: 0
Your for loop is, um, strange. tabs_strings is itself an array so you're saying:
for i in [0 .. some_array]
rather than the usual:
for i in [0 .. some_number]
or
for e in some_array
If you look at the JavaScript version, you'll see this:
for (tab = _i = 0; 0 <= tabs_strings ? _i <= tabs_strings : _i >= tabs_strings; tab = 0 <= tabs_strings ? ++_i : --_i) {
so you end up comparing 0 with an array and that's not terribly productive.
I think you want to use the for e in array form of the for-loop:
for tab in tab_strings
new Layer
x:0, y:0, width:640, height:1136, image:"images/#{tab}.jpg"
There's no need for the tab assignment inside the loop so I took that out.
Is your question that the code you posted does not work and that you are looking for an alternative solution?
EDIT:
The only problem I see here is that you are using "tab" for both the string variable passed from the current position in the array, as well the new Layer object that you are initializing.
Try this:
tabs_strings = ["nearby", "adopted", "my_cats", "settings", "bruce"]
for tab in [0..tabs_strings.length]
tabLayer = new Layer
x:0, y:0, width:640, height:1136, image:"images/#{tab}.jpg"

Python: Decide which scrollbar is moving in ScrolledPanel

This question continue the question on the link : wxPython Event for ScrolledPanel. I edited the code a little bit so that OnScroll function get the x position of the content's scrollbar and use that to set x position of the header's scrollbar.
My problem is I cannot decide when the horizontal scrollbar is rolled. So my program now has the header's horizontal scrollbar rolled whenever any of the content's scrollbars is rolled while I want the header's h-scrollbar rolled when the content's h-scrollbar is rolled. (Or if anyone can suggest an event triggering by only when scrolling the horizontal bar it will be very good). Thanks ahead.
import wx
from wx.lib.scrolledpanel import ScrolledPanel
header = """
col1 col2 col3 col4 col5"""
text = """
1336 733 1336 4732 1217
5968 4477 1217 5748 4477
1217 5635 4372 1217 5634
4369 1217 5633 4371 217"""
class Test(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(300, 200))
self.panel=panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
vboxA = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.headerPanel = headerPanel = ScrolledPanel(panel, -1, size=(150,32))
hboxHeader = wx.BoxSizer(wx.HORIZONTAL)
self.headertc = headertc = wx.TextCtrl(headerPanel, -1, header,
size=(500,32),style= wx.TE_READONLY)
headertc.Unbind(wx.EVT_SCROLLWIN)
hboxHeader.Add(headertc,1)
headerPanel.SetSizer(hboxHeader)
headerPanel.SetAutoLayout(1)
headerPanel.SetupScrolling(scroll_y = False)
hbox.Add(headerPanel,1, wx.EXPAND | wx.ALL,0)
vboxA.Add(hbox, 0, wx.EXPAND)
self.textPanel = textPanel = ScrolledPanel(panel, -1, size = (150,150))
textPanel.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
hboxText = wx.BoxSizer(wx.HORIZONTAL)
self.tc = tc = wx.TextCtrl(textPanel, -1, text, size=(500,500),
style=wx.TE_MULTILINE|wx.TE_DONTWRAP| wx.TE_READONLY)
hboxText.Add(tc, 1)
textPanel.SetSizer(hboxText)
textPanel.SetAutoLayout(1)
textPanel.SetupScrolling(scroll_x=True, scroll_y=True)
vboxA.Add(textPanel,1, wx.EXPAND | wx.ALL,0)
vbox.Add(vboxA, 1, wx.EXPAND | wx.ALL)
panel.SetSizer(vbox)
self.Centre()
self.Show(True)
def OnScroll(self, event):
event.Skip()
x= event.GetPosition()
self.headerPanel.Scroll(x,0)
print event.GetEventType()
if __name__ == "__main__":
app = wx.App()
frame = wx.Frame(None, -1)
win = Test(frame, "Test scroll bar")
app.MainLoop()
Use the following condition to check for horizontal scrolling in your scroll handler.
if event.Orientation == wx.SB_HORIZONTAL: