Is there a way to reassign a grid layout to a label? - python-2.7

I have created a GUI with the aid of Tkinter that has created a 3 [C]olomn by 8 [R]ow, (I have placed the borders of the 'cells' in red) and output is like so:
Just to calrify:
Where the "logo [E]" is (C1,R1) & (C1,R2) are rowspanned and where the "main window" is from (C2,R3) to (C3,R8) are colomnspanned and rowspanned.
All are Label widget except for (C1,R3 to C1,R8), which are button widgets with a command to display a string in "Main Window" (gray area).
My aim is to make the "Main Window"(gray area) display only in different grid layouts based on the selected button on the left. So for example I would like to make the grey have a grid layout of 2col by 4 row when C1,R6 is pressed, or when C1,R3 is pressed the grid layout to be 2Cx6R all in the gray area.
Q: Is there a way of re-gridding a label? If so how? Or an alternative approach?
ADDENDUM:
Ideally I would like to update the GREEN area with different number of row and column configurations. For example: When Micro Audit is touched, the Green area will configure itself to have 4 rows by 2 columns, and when Find Item is selected, it will only 3 rows with 1 column, etc. :

Related

wxPython Toolbook/Toolbar, blank space between toolbar and frame

The screenshot is a snip of the left side of my main frame. This frame has a toolbook at the top. I've set the background color of both the toolbar in the toolbook and the frame to 0,0,0 but, as you can see, there is a small blank line between the two. How do I get that line gone or how do I make it black, as well?
As a quick side question -- is there a way to change the color of the "selected" halo on the toolbar to something a bit more contrasted for black? You can see the very faint blue halo around that first icon, I'd like that to be a much lighter blue, if possible.
EDIT: Code added --
il = wx.ImageList(128, 128)
for tab in self.package.vars["tabs"]:
il.Add(wx.Image(self.package.vars["iconPath"].format(tab), wx.BITMAP_TYPE_PNG).ConvertToBitmap())
self.AssignImageList(il)
imageIdGenerator = self.getNextImageID(il.GetImageCount())
pages = [(wx.Panel(parent = self.parent, id = wx.ID_ANY), name.capitalize()) for name in self.package.vars["tabs"]]
imID = 0
toolbar = self.GetToolBar()
toolbar.SetBackgroundColour(self.package.vars["bgColor"])
toolbar.AddStretchableSpace()
for page, label in pages:
self.AddPage(page, label, imageId=imageIdGenerator.next())
page.SetBackgroundColour(c.COLORS["green"])
imID += 1
toolbar.AddStretchableSpace()
pages = [(wx.Panel(parent = self.parent, id = wx.ID_ANY), name.capitalize()) for name in self.package.vars["tabs"]]
maybe this wx.Panel in the list comprehension still has the default color. what happens if you apply SetBackgroundColour to these panels as well?
(edit)
How about removing that boarder space by
self.SetInternalBorder(0)
self here is Toolbook class. It seems to work on wxPython Demo Toolbook example.

QT gui items won't shrink to ft to their parent widget

I have three widgets under my main window . I design my program that each widget will be controlled by a class .
Last 2 hours I waste my time to fit 3 GUI elements to one of this widgets.
I want to have a label and a line item and a button. I put them in to a grid layout(in real case I have 3 row for simplicity I put 1 row in the example below). And set the grid layout's parent to my class.
What I expect is this GUI items to resize themselves and fit to one row in this widget, no matter what I tried I couldn't succeed .
In short I expect this items to shrink to fit to the widget by themselves. But couldn't figure out how to do it. Any advice ?
void
enviromentSetup::createDialogs()
{
numberOfPoints = new QLabel (QApplication::translate("leftPanel","numberOfPoints"));
inputNumberOfPoints = new
QLineEdit(QString::number(st_environmentParamaters.number_of_points_in_line));
maxElementsButton = new QPushButton("Max Elems");
gridLayout = new QGridLayout(this);
gridLayout->addWidget(numberOfPoints, 0, 0);
gridLayout->addWidget(inputNumberOfPoints, 0, 1);
gridLayout->addWidget(maxElementsButton, 0, 2);
this->show();
}
It is insufficient to merely make the parent of the layout the main widget. You also have to explicitly set the layout of the widget.
Add the following line just before you show the widget:
this->setLayout(gridLayout);

Huge "Grid" of PushButtons lags awfully, buttons can't be enabled

In my project, I have 256 tiny PushButtons in one 16x16 grid layout. (Yeah that took forever.) Editing and running my program now is very laggy. Also, for some strange reason, Qt will not let me enable any of the buttons, but other buttons to the side work just fine?
Is there any easy way to determine which square of the grid was clicked without having a bunch of buttons? (Like following the cursor over an image maybe?)
Also, when each "square" of the grid is clicked, it becomes the "selection" and it needs to be the only "square" selected. (Think about it like a huge chess board)
Here is a pic: http://gyazo.com/988cdbb59b3d1f1873c41bf91b1408fd
Later on, I will need to do this again for a 54x54 size grid (2916 buttons) and I REALLY don't want to do it button by button.
Thanks for your time, I hope you understand my question :)
You can do this easy way, I've explained almost everything in code, but if you have any questions about it feel free to ask, and please, accept this answer if it solved your problem :)
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class DrawImage(QMainWindow):
def __init__(self, parent=None):
super(QMainWindow, self).__init__(parent)
self.setWindowTitle('Select Window')
#you can set grid size here ... 8x8, 16x16 , for bigger numbers (54x54) be sure your image is big enough, because QWidget can't be smaller then ~20 pixels
self.gridSize = 16
mainWidget = QWidget()
self.setCentralWidget(mainWidget)
self.scene = QGraphicsScene()
view = QGraphicsView(self.scene)
layout = QVBoxLayout()
layout.addWidget(view)
mainWidget.setLayout(layout)
self.image = QImage('image.JPG')# put your image name here, image (suppose to be grid) must be at the same folder or put full path
pixmapItem = QGraphicsPixmapItem(QPixmap(self.image), None, self.scene)
pixmapItem.mousePressEvent = self.pixelSelect
def pixelSelect( self, event ):
#add whatever you want to this widget,any functionality or you can add image for example, I've simply colored it
wdg = QWidget()
layout = QVBoxLayout()
palette = QPalette(wdg.palette())
palette.setBrush(QPalette.Background, QColor(200,255,255))
wdg.setPalette(palette)
wdg.setLayout(layout)
self.scene.addWidget(wdg)
#calculate size and position for added widget
imageSize = self.image.size()
width = imageSize.width()
height = imageSize.height()
#size
wgWidth = float(width)/self.gridSize
wgHeight = float(height)/self.gridSize
wdg.setFixedSize(wgWidth,wgHeight)
#position
wgXpos = int(event.pos().x()/wgWidth) * wgWidth
wgYpos = int(event.pos().y()/wgHeight) * wgHeight
wdg.move(wgXpos, wgYpos)
#which square is clicked?
print "square at row ", int(event.pos().y()/wgHeight)+1,", column ",int(event.pos().x()/wgWidth)+1, "is clicked"
def main():
app = QtGui.QApplication(sys.argv)
form = DrawImage()
form.show()
app.exec_()
if __name__ == '__main__':
main()
Also, if you want to display simple square image over your grid image, look at question/solution I had: QGraphicsPixmapItem won't show over the other QGraphicsPixmapItem
If you don't really need the appearance of buttons, I would create a QWidget subclass that implements a custom paintEvent and renders a grid of needed size (taking the widget size into account). Then, in the mouse events (up,down,move etc.) you can calculate which grid item was clicked with a simple formula. You can render cells with different colors to indicate selection or highlighting.
P.S.:I would really like to post some code from my implementations (i have done this two or three times) but the source codes are at my old company :)
You just create your own QGridLayout in order to be able to add the buttons easily.
I posted an answer to another question, showing you how to fill a custom made QGridLayout with a bunch of widgets sequentially. The buttons are added according to the maximum count of columns you specified. (Note: It's just a very rough example but enough to start from)
In your example you would create the custom grid layout with 16 columns and simply add your buttons.
To find out which button has been pressed (and to make connecting easier) you can use QSignalMapper.
For investigating the lag you could check the amount of (GDI-/User-) handles of your application (using ProcessExplorer for example). The handle count shouldn't be above 10.000.
I don't know why you can't enable the push buttons.

Overlapping MenuItems in Cocos2d CCMenu

I am trying to make a Menu that contains 13 MenuItemImages in two columns (the last one is in the middle).
The frame width/ design resolution width is 480 pixels. MenuItemImage width is 180 pixels.
here is my code :
CCMenu* testMenu = CCMenu::createWithArray(testMenuItems);
testMenu->alignItemsInColumns(2,2,2,2,2,2,1);
CCSize size1 = CCDirector::sharedDirector()->getWinSize();
testMenu->setPosition(ccp(size1.width / 2, size1.height/2));
but the two columns are slightly overlapping. (the right one is above the left one)
here is the result of my code:
I would like it to be properly spaced with some padding between the two columns.
Please help me out I am new to Cocos2d-x.
the alignItemsInColumns will align menu itens based on itens center, against menu width.
In your case, you have 2 options:
1) Increase your menu width (by default, their size will be based on screen size. Change the menu.contentSize.width)
2) Change the anchor point of left itens to ccp(.7,.5) and right itens to ccp(.3,.5) for example

How can I create a 3 state custom push button?

I need to create a custom push button which will have 3 different background images corresponding to the following states:
normal
mouse over
mouse down
I would like to have a QHBoxLayout with 3 parts for left side, right side and middle side (stretching side) for the button.
Inside the middle size, I would like to have a label to show the text.
I need this button to have a "clicked" event as well.
I have been doing a lot of search to achieve this but I am really lost. I tried many things including custom widget from QWidget or styling QPushButton with stylesheets but I failed to achieve having 3 images for 3 mouse states and the clicked event.
I am looking for help.
You can use the border-image property, by composing a single image for each state like this:
| |
Left Image | Middle Image | Right Image
| |
then by specifying the left and right image sizes as the border slice sizes and in the border widths of the stylesheet. For example, if the right images were 25 pixel wide and the left ones 20, you would have:
QPushButton {
border-image: url(:/normal.png) 0 25 0 20 stretch stretch;
border-width:0 25 0 20; /* without it, only the middle images would show */
}
QPushButton:hover {
border-image: url(:/hover.png) 0 25 0 20 stretch stretch;
}
QPushButton:pressed {
border-image: url(:/pressed.png) 0 25 0 20 stretch stretch;
}
The values represent the distance between the top, right, bottom and left sides of the image.
well,first,you should have 3 picture for 3 states,and then you can use function setStyleSheet .
QPushButton *btn = new QPushButton;
btn->setStyleSheet("QPushButton{background:url(:/Resources/pause_nor.png);border:0px;}"
"QPushButton:hover{background:url(:/Resources/pause_over.png);border:0px}"
"QPushButton:pressed{background:url(:/Resources/pause_over.png); position: relative;top: 1px; left: 1px;}");