wxPython - Can't make wx.StaticText align inside a wx.StaticBoxSizer - alignment

how it going?
I'm trying to align two wx.StaticText inside a horizontal box, which is inside a vertical wx.StaticBoxSizer. See for yourself. I guess the code says what I'm trying to do.
Thanks!
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
sizer = wx.StaticBoxSizer(wx.VERTICAL, self)
left = wx.StaticText(self, -1, 'left', style=wx.ALIGN_LEFT)
right = wx.StaticText(self, -1, 'right', style=wx.ALIGN_RIGHT)
hBox = wx.BoxSizer(wx.HORIZONTAL)
hBox.Add(left)
hBox.Add(right)
sizer.Add(hBox)
self.SetSizerAndFit(sizer)
app = wx.App()
frame = Frame(None).Show()
app.MainLoop()

Ever since the removal of wx.ALIGN_LEFT and wx.ALIGN_RIGHT in horizontal boxsizers and the introduction of:
wx._core.wxAssertionError: C++ assertion "!(flags & wxALIGN_RIGHT)" failed at /tmp/pip-install-8ko13ycp/wxpython/ext/wxWidgets/src/common/sizer.cpp(2168) in DoInsert(): Horizontal alignment flags are ignored in horizontal sizers,
it's an issue.
Another option is to use the spacing in the sizer instruction to the Left and/or Right. e.g.
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
sizer = wx.StaticBoxSizer(wx.VERTICAL, self, "Test")
left = wx.StaticText(self, -1, 'left')
right = wx.StaticText(self, -1, 'right')
hBox = wx.BoxSizer(wx.HORIZONTAL)
hBox.Add(left, 0, wx.RIGHT, 100)
hBox.Add(right, 0, wx.LEFT, 100)
sizer.Add(hBox)
self.SetSizerAndFit(sizer)
app = wx.App()
frame = Frame(None).Show()
app.MainLoop()

It seems I have to specify a size to make the aligment work!
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
sizer = wx.StaticBoxSizer(wx.VERTICAL, self)
left = wx.StaticText(self, -1, 'left', size=(175, 15), style=wx.ALIGN_LEFT)
right = wx.StaticText(self, -1, 'right', size=(25, 15))
hBox = wx.BoxSizer(wx.HORIZONTAL)
hBox.Add(left)
hBox.Add(right)
sizer.Add(hBox)
self.SetSizerAndFit(sizer)
app = wx.App()
frame = Frame(None).Show()
app.MainLoop()

Related

Kivy Image Buttons Are Shaped Like... Lemons?

I'm trying build a GUI in python with an array of buttons and some circular menu items on the right. I made a some png files for the menu items, but when I add them as buttons into the code, it shows them kind of like two lemons on top of each other rotated 90˚. A bit like this: Lemon Buttons
These are the icons that I made:
Circular Buttons
Here is the code I have right now.
from kivy.app import App
from kivy.uix.button import Button
from kivy.config import Config
from kivy.uix.floatlayout import FloatLayout
buttonSize = (0.3, 0.2)
Config.set('graphics', 'resizable', True)
class MyApp(App):
def build(self):
layout = FloatLayout()
button1 = Button(
text='1st Function',
size_hint=buttonSize,
pos_hint={'x':.05, 'y':.75}
)
button2 = Button(
text='2nd Function',
size_hint=buttonSize,
pos_hint={'x':.4, 'y':.75}
)
button3 = Button(
text='3rd Function',
size_hint=buttonSize,
pos_hint={'x':.05, 'y':.475}
)
button4 = Button(
text='4th Function',
size_hint=buttonSize,
pos_hint={'x':0.4, 'y':0.475}
)
button5 = Button(
text='5th Function',
size_hint=buttonSize,
pos_hint={'x':.05, 'y':.2}
)
button6 = Button(
text='6th Function',
size_hint=buttonSize,
pos_hint={'x':0.4, 'y':0.2}
)
menuButton = Button(
background_normal='Circular Button.png',
background_down='Circular Button Down.png',
size_hint=(0.125, 0.15),
pos_hint={'x':0.8, 'y':0.8}
)
patientButton = Button(
background_normal='Patient Button.png',
background_down='Patient Button Down.png',
size_hint=(0.125, 0.15),
pos_hint={'x':0.8, 'y':0.5}
)
layout.add_widget(button1)
layout.add_widget(button2)
layout.add_widget(button3)
layout.add_widget(button4)
layout.add_widget(button5)
layout.add_widget(button6)
layout.add_widget(menuButton)
layout.add_widget(patientButton)
return layout
if __name__ == '__main__':
app = MyApp()
app.run()
How do I get the icons to show normal circles instead of these monstrosities?
This seems to be caused by the (lack of) border attribute.
Fix it by setting borders to 0 as follows:
menuButton = Button(
background_normal='Circular Button.png',
background_down='Circular Button Down.png',
size_hint=(0.1, 0.1),
pos_hint={'x':0.8, 'y':0.8},
border=(0, 0, 0, 0)
)
patientButton = Button(
background_normal='Patient Button.png',
background_down='Patient Button Down.png',
size_hint=(0.2, 0.2),
pos_hint={'x':0.8, 'y':0.5},
border=(0, 0, 0, 0)
)
Result (images are not perfectly square and I set second one to twice the size hint, this is just for testing):

Collection View Scale Flow Layout

I want to create layout for following layout inside collection view.
Align one cell in centre and two cell outside with scale down using transform.
I have used third party library DXScaleFlowLayout and implemented following code to make like same.
let scaleLayout = DXScaleFlowLayout()
scaleLayout.transformScale = 0
scaleLayout.isPagingEnabled = true
scaleLayout.minimumAlpha = 0.8
scaleLayout.minimumLineSpacing = 0
scaleLayout.minimumInteritemSpacing = 0
let width = self.cvBusinessPlans.bounds.width
let height = self.cvBusinessPlans.bounds.height
scaleLayout.itemSize = CGSize(width: width, height: height)
scaleLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
self.cvBusinessPlans.collectionViewLayout = scaleLayout
But it didn't work for me. If anyone know how to make this then please help. I have search of SOF, but I can't find exact or similar solution.

Vertical UIStackView alignment

I have a vertical UIStackview with 3 controls in it.
I want all the controls to be centered, and the first two to expand the whole width available. The third one should take 80% of the available width and be centered as well.
Here is the result I got so far:
As you can see the third control is left aligned.
Here is the code I have for all of this:
var container = new UIStackView
{
TranslatesAutoresizingMaskIntoConstraints = false,
Axis = UILayoutConstraintAxis.Vertical,
Distribution = UIStackViewDistribution.EqualCentering,
Alignment = UIStackViewAlignment.Fill,
Spacing = 10f
};
// Create the Title
UILabel title = new UILabel
{
TranslatesAutoresizingMaskIntoConstraints = false,
Text = item.name,
TextAlignment = UITextAlignment.Center,
Lines = 2,
};
container.AddArrangedSubview(title);
// Create the gauge
SFCircularGauge circularGauge = new SFCircularGauge { TranslatesAutoresizingMaskIntoConstraints = false };
circularGauge.Tag = circularGauge.GenerateViewTag();
circularGauge.HeightAnchor.ConstraintEqualTo(100f).Active = true;
#if DEBUG
circularGauge.BackgroundColor = UIColor.Cyan;
#endif
container.AddArrangedSubview(circularGauge);
// Add the evaluate button
var evaluate = UIButton.FromType(UIButtonType.RoundedRect);
evaluate.TranslatesAutoresizingMaskIntoConstraints = false;
evaluate.SetTitle(Utilities.GetLocalizedString("qol_rate_button_text"), UIControlState.Normal);
evaluate.SetTitleColor(UIColor.White, UIControlState.Normal);
evaluate.BackgroundColor = new UIColor(red: 1.00f, green: 0.37f, blue: 0.00f, alpha: 1.0f); // Optimistic Orange
evaluate.Layer.CornerRadius = 5f;
evaluate.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
evaluate.ContentEdgeInsets = new UIEdgeInsets(top: 0, left: 10f, bottom: 0, right: 10f);
evaluate.UserInteractionEnabled = true;
evaluate.TouchUpInside -= Evaluate_TouchUpInside;
evaluate.TouchUpInside += Evaluate_TouchUpInside;
evaluate.Tag = evaluate.GenerateViewTag();
viewIdsAutoEvalsIds.Add((int)evaluate.Tag, item.id);
container.AddArrangedSubview(evaluate);
evaluate.WidthAnchor.ConstraintEqualTo(container.WidthAnchor, 0.8f).Active = true;
evaluate.CenterXAnchor.ConstraintEqualTo(container.CenterXAnchor).Active = true;
I can't figure out where is my problem. In the UIStackView configuration? Somewhere else?
Thanks in advance.
The property Alignment is to sets the alignment of the non-axial subviews . In your case , you need to set it as
UIStackViewAlignment.Center
instead of
UIStackViewAlignment.Fill
This might be a bug of the control. We'll see.
In the meantime, thanks again to the Reveal Tool, the gauge has no width defined.
I solved the problem by setting the width constraint explicitly:
// Fix the width to be 100% of the container
circularGauge.WidthAnchor.ConstraintEqualTo(container.WidthAnchor).Active = true;

Connecting to a signal of a widget, button::press

I want to create a simple widget which is a progress bar that gets its value set to 1 when we click it with left mouse button.
local myFirstWidget = wibox.widget {
{
value = 0.5,
color = "#ff0000",
widget = wibox.widget.progressbar,
width = 100,
forced_height = 20,
shape = gears.shape.rounded_bar,
border_width = 2,
border_color = beautiful.border_color,
ticks = true,
clip = true,
margins = {top = 5, bottom = 5},
paddings = 2
},
layout = wibox.layout.fixed.horizontal
}
myFirstWidget:connect_signal("button::press",
function(w, _, _, btn) w.value = 1 end)
When I press the bar - nothing really happens. And if I use
w.set_value(1)
then clicking the bar shows an error
attempt to call a nil value (field 'set_value')
How do I make it work?
It turnes out that w is the "parent" widget which contains progressbar widget. So I had to do it this way
myFirstWidget:connect_signal("button::press", function(w)
local children = w:get_all_children()
children[1].value = 1;
end)
so basically I retrieve a table of all children widgets and then use [1] to refer to the first widget in the table and after that I assign a value to its property

scrollView doesn't adjust horizontally

Basically, I need a scrollView which is shrinked horizontally. Now, when I insert a bunch of text in it, it doesn't adjust it, text just goes over the edge of the scrollView, like this: http://prntscr.com/ai0100
This is my scrollView code:
local scrollView = widget.newScrollView
{
hideBackground = false,
hideScrollBar = true,
left = 64,
top = 0,
width = contW - 128,
height = contH,
topPadding = 256,
bottomPadding = 20,
horizontalScrollDisabled = true,
verticalScrollDisabled = false,
}
I insert a bunch of text later, and screenshot above is the result. How can I fix this?
Read this: https://docs.coronalabs.com/api/library/display/newText.html
In order to wrap a text you have to set the display.newText() width parameter accordingly.
So something like
scrollView.newText
{
text = "I am a super text"
width = 123 -- replace with your desired width
}
This is another way:
local lotsOfTextObject = display.newText( lotsOfText, display.contentCenterX-40, 0, samewidthasscrollview, 0, native.systemFont, 30)
scrollView:insert( lotsOfTextObject )

Resources