I am trying to set a colour to highlight a button. However, the modify_fg method only seems to set the focus ring's colour. modify_bg works as expected.
This is my code:
use Gtk2 qw/-init/;
my $window = Gtk2::Window->new;
$window->set_title("Window!");
my $button = Gtk2::Button->new("Coloured _button");
# does not affect text
$button->modify_fg(normal => Gtk2::Gdk::Color->new(0xffff, 0, 0));
$window->add($button);
$window->show_all;
Gtk2->main;
I'm also interested whether there is a standard colour for this sort of highlight, to blend in with the user's theme.
you can get the button's child label and modify its foreground, below is an example (python, let me know if there are troubles converting it to perl)
import gtk
class TestWindow:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
box = gtk.VBox()
button0 = gtk.Button("Test Button")
label0 = button0.get_children()[0]
label0.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('red'))
button1 = gtk.Button(stock=gtk.STOCK_ABOUT)
alignment = button1.get_children()[0]
hbox = alignment.get_children()[0]
image, label1 = hbox.get_children()
label1.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('blue'))
box.add(button0)
box.add(button1)
window.add(box)
window.set_size_request(200, 200)
window.show_all()
def close_application(self, widget, event, data=None):
gtk.main_quit()
return False
if __name__ == "__main__":
TestWindow()
gtk.main()
hope this helps, regards
All previous helped a lot...
All the following works ok!
my $beige = Gtk2::Gdk::Color->new (0xFFFF,0xFFFF,0xCCCC);
my $azul = Gtk2::Gdk::Color->new (0,0,0xCCCC);
my $rojo = Gtk2::Gdk::Color->new (0xCCCC,0,0);
$mw->modify_bg ("normal", $beige);
my $butOk = Gtk2::Button->new_with_label(" 🗹 ¡Ya Terminé!");
($butOk->get_children)[0]->modify_fg("normal", $azul);
($butOk->get_children)[0]->modify_font(Pango::FontDescription->from_string ("Serif Bold 27"));
my $imgBTN = Gtk2::Button->new();
my $img = Gtk2::Image->new_from_file("$imagen");
$imgBTN->set_property("image"=>$img);
Related
import pygame
import time
import random
from __builtin__ import quit
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
red = (200,0,0)
green = (0,200,0)
bright_red = (255,0,0)
bright_green = (0,255,0)
ship_width = 73
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Galaxia Remastered')
clock = pygame.time.Clock()
background = pygame.image.load('space1.png')
background = pygame.transform.scale(background, (800,600))
shipImg = pygame.image.load('ship1.png')
shipImg = pygame.transform.scale(shipImg, (73,73))
mobImg = pygame.image.load('ufo.png')
mobImg = pygame.transform.scale(mobImg, (100,100))
def mobs_dodged(count):
font = pygame.font.SysFont(None, 25)
text = font.render("Dodged: "+str(count), True, white)
gameDisplay.blit(text,(0,0))
def mobs(mobx, moby, mobw, mobh):
gameDisplay.blit(mobImg,(mobx,moby))
def ship(x,y):
gameDisplay.blit(shipImg,(x,y))
def text_objects(text,font):
textSurface = font.render(text, True, white)
return textSurface, textSurface.get_rect()
def message_display(text):
font = pygame.font.Font('freesansbold.ttf',115)
TextSurf, TextRect = text_objects(text,font)
TextRect.center = ((display_width/2),(display_height/2))
gameDisplay.blit(TextSurf,TextRect)
pygame.display.update()
time.sleep(2)
game_loop()
def crash():
message_display('You Crashed!')
def button(msg,x,y,w,h,ic,ac):
mouse = pygame.mouse.get_pos()
if x + w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(gameDisplay, ac, (x,y,w,h))
else:
pygame.draw.rect(gameDisplay,ic, (x,y,w,h))
font = pygame.font.Font('freesansbold.ttf',20)
textSurf, textRect = text_objects(msg, font)
textRect.center = ((x+(w/2)),(y+(h/2))
gameDisplay.blit(textSurf, textRect)
The last line gives me an invalid syntax error, highlighting the "gameDisplay". After looking around myself, there was an "import gameDisplay from..." another file I had within the project. I thought that it would be fixed if I deleted the line, however it stated "unresolved import". I restarted Ecplise and cleaned my project multiple times but it still doesn't work. I sent the program to my other computer and it still gets the same error. When I remove the "gameDisplay" line, it tells me that there is an invalid syntax in "def game_intro():".
All help would be greatly appreciated.
It looks like you got one mismatched paranthese on line 74
Just remove the very first one on that line and your code should work just fine again..
textRect.center = (x+(w/2)),(y+(h/2))
Does anyone know how to set the shape fill to transparent?
I tried the following code, but is not working.
$AppVisio = New-Object -ComObject Visio.Application
$AppVisio.Visible = $false
$docsObj = $AppVisio.Documents
$DocObj = $docsObj.Add("Basic Diagram.vst")
$pagsObj = $AppVisio.ActiveDocument.Pages
$pagObj = $pagsObj.Item(1)
$Shape = $AppVisio.ActiveWindow.Page.DrawRectangle(0.315, 0.397, 3.315, 8.015)
$Shape.FillStyle = "Transparent"
Thanks.
With Visio, most of the properties that effect appearance, size and position are stored in the ShapeSheet. So you need to find the right cell to address which, in this case, is FillForegndTrans. So your line should read:
$Shape.CellsU('FillForegndTrans').FormulaU = '50%'
If you're not familiar with the ShapeSheet, you might find this useful background:
http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html
I have popup being created along the edge of a window and I'd like it to expand the popup as the user types into its text field. This currently works, but the window is expanding to the right. Instead, I'd like the popup to expand to the left (and keep the right edge anchored in place).
My closest example that's kind of working is below. In it, I'm getting the size of the popup with every text input and then moving the popup based on its new size. I feel like this should work, but its not.
On the first text input the popup jumps to the left edge of my screen (x transformation only). On the second text input the popup jumps back to its original position. On a third text input the popup jumps back to the left edge of the screen. On the fourth input... You get the idea. I'd also like to mention that the overall growth of the window looks like it's growing from the center of the popup and not from the right edge.
I've noticed that after the button is clicked it remains highlighted until my mouse passes over it. Could this contributing to the problem?
Any thoughts or a better way to achieve this effect would be great, thanks!
from PySide import QtCore, QtGui
import maya.OpenMayaUI as mui
from shiboken import wrapInstance
def get_parent():
ptr = mui.MQtUtil.mainWindow()
return wrapInstance( long( ptr ), QtGui.QWidget )
############################################
class Tool_Window(QtGui.QDialog):
def __init__(self, parent = get_parent() ):
super(Tool_Window, self).__init__(parent)
# Commands
self.move_UI()
self.create_gui()
self.create_layout()
self.create_connections()
#-------------------------------------------
def create_gui(self):
self.button1 = QtGui.QPushButton()
self.button1.setMaximumWidth(50)
self.button2 = QtGui.QPushButton()
self.button2.setMaximumWidth(50)
self.button3 = QtGui.QPushButton()
self.button3.setMaximumWidth(50)
#-------------------------------------------
def create_layout(self):
layout = QtGui.QVBoxLayout()
layout.addWidget(self.button1)
layout.addWidget(self.button2)
layout.addWidget(self.button3)
blank_layout = QtGui.QVBoxLayout()
main_layout = QtGui.QHBoxLayout( self )
main_layout.addLayout(blank_layout)
main_layout.addLayout(layout)
layout.addStretch()
self.setLayout(layout)
#-------------------------------------------
def move_UI( self ):
''' Moves the UI to the cursor's position '''
pos = QtGui.QCursor.pos()
self.move(pos.x()+20, pos.y()+15)
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
def create_connections(self):
# Left click
self.button1.clicked.connect( self.on_left_click1 )
self.button2.clicked.connect( self.on_left_click2 )
self.button3.clicked.connect( self.on_left_click3 )
# Right click delete
delete = QtGui.QAction(self)
delete.setText("remove")
delete.triggered.connect(self.remove_button)
self.addAction(delete)
#-----#-----#-----#-----#-----#-----#-----#-----#-----#
def remove_button(self):
self.deleteLater()
def on_left_click1(self):
self.popup = Popup_Window( self, self.button1 ) # Passing button in so I can get it's position
self.popup.show()
def on_left_click2(self):
self.popup = Popup_Window( self, self.button2 )
self.popup.show()
def on_left_click3(self):
self.popup = Popup_Window( self, self.button3 )
self.popup.show()
############################################
class Popup_Window( QtGui.QDialog ):
def __init__( self, toolWindow, button ):
super( Popup_Window, self ).__init__()
self.__popup_filter = ClosePopupFilter()
self.installEventFilter(self.__popup_filter)
self.setWindowFlags(QtCore.Qt.Popup)
'''
self.setWindowFlags(QtCore.Qt.FramelessWindowHint |
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.CustomizeWindowHint |
QtCore.Qt.Tool)
'''
self.button_pos = button
self.toolWindow = toolWindow
self.setAttribute( QtCore.Qt.WA_DeleteOnClose )
self.resize(100, 100)
# Commands
self.create_gui()
self.create_layout()
self.create_connections()
self.move_UI()
#-------------------------------------------
def move_UI( self ): # Method that I use to place the popup window initially
self.line_edit.setFocus()
# Get button position
self.btn_global_point = self.button_pos.mapToGlobal(self.button_pos.rect().topLeft())
print self.btn_global_point
# Get window position
self.win_global_point = self.toolWindow.mapToGlobal(self.rect().topLeft())
print self.win_global_point
# Get popup Size
self.popup_size = self.mapToGlobal(self.rect().topRight())
print self.popup_size
# Move the window
self.move((self.win_global_point.x()-self.popup_size.x()), self.btn_global_point.y())
#-------------------------------------------
def create_gui( self ):
''' Visible GUI stuff '''
self.my_label = QtGui.QLabel("default text")
self.line_edit = QtGui.QLineEdit()
self.line_edit.setMaxLength( 30 )
self.push_btn = QtGui.QPushButton( "Hey" )
self.push_btn.setMaximumWidth( 30 )
#-------------------------------------------
def create_layout( self ):
self.button_layout = QtGui.QVBoxLayout()
self.button_layout.addWidget( self.my_label )
self.button_layout.addWidget( self.line_edit )
self.button_layout.addWidget( self.push_btn )
#self.button_layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(self.button_layout)
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
def create_connections( self ):
self.line_edit.textChanged.connect( self.on_text_changed )
#-----#-----#-----#-----#-----#-----#-----#-----#-----#
def on_text_changed( self ):
typed_name = self.line_edit.text()
self.my_label.setText(typed_name)
self.move_UI() # I reuse the move method to move the ui on text edit
############################################
class ClosePopupFilter(QtCore.QObject):
''' Close popup window '''
def eventFilter(self, target, event):
if event.type() == QtCore.QEvent.WindowDeactivate:
target.close()
return False
if __name__ == '__main__':
# Things to fix PySide Maya bug
try:
test_ui.close()
test_ui.deleteLater()
except:
pass
test_ui = Tool_Window()
test_ui.show()
try:
test_ui.show()
except:
test_ui.close()
test_ui.deleteLater()
I've trimmed a little bit the code you provided in the OP and tried to put together an example that address your particular issue.
Some of the modifications I've done to the code:
trigger the move_UI within the resizeEvent of the Popup_Window ;
corrected the method move_UI in Popup_Window so that the popup does not blink on and off to one location to the other ;
moved the eventFilter directly within the Popup_Window ;
merged the functions handling the events for the button.clicked.connect in Tool_Window.
The solution is not perfect, there is still a little 'flicker' of the popup window when it is expanding and moving in Ubuntu. This is not very apparent in Windows7 however. If I think of another solution, I'll do an update.
from PySide import QtCore, QtGui
import sys
class Tool_Window(QtGui.QDialog): #=============================================
def __init__(self, parent=None):
super(Tool_Window, self).__init__(parent)
self.create_gui()
self.create_layout()
self.create_connections()
def create_gui(self): #=====================================================
self.button1 = QtGui.QPushButton('Button 1')
self.button2 = QtGui.QPushButton('Button 2')
self.button3 = QtGui.QPushButton('Button 3')
def create_layout(self): #==================================================
layout = QtGui.QVBoxLayout()
layout.addWidget(self.button1)
layout.addWidget(self.button2)
layout.addWidget(self.button3)
self.setLayout(layout)
def create_connections(self): #=============================================
self.button1.clicked.connect(self.on_lef_click )
self.button2.clicked.connect(self.on_lef_click )
self.button3.clicked.connect(self.on_lef_click )
def on_lef_click(self): #===================================================
button = self.sender()
self.popup = Popup_Window(self, button)
self.popup.show()
class Popup_Window( QtGui.QWidget ): #==========================================
def __init__( self, parent, button):
super(Popup_Window, self ).__init__(parent)
self.setWindowFlags(QtCore.Qt.Popup)
self.button = button
self.parent = parent
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
#---- set layout key dimension ----
self.min_width = 100
self.frame_thick = 10
self.setFixedWidth(self.min_width)
#---- init GUI ----
self.installEventFilter(self)
self.create_gui()
self.create_layout()
self.create_connections()
self.move_UI()
self.line_edit.setFocus()
def create_gui( self ): #===================================================
self.my_label = QtGui.QLabel("default text")
self.my_label.setAlignment(QtCore.Qt.AlignRight)
self.line_edit = QtGui.QLineEdit()
self.line_edit.setAlignment(QtCore.Qt.AlignRight)
self.line_edit.setMaxLength( 50 )
def create_layout( self ): #================================================
button_layout = QtGui.QGridLayout()
button_layout.addWidget(self.my_label, 0, 0)
button_layout.addWidget(self.line_edit, 1, 0)
button_layout.setContentsMargins(self.frame_thick, self.frame_thick,
self.frame_thick, self.frame_thick)
self.setLayout(button_layout)
def create_connections(self): #=============================================
self.line_edit.textChanged.connect(self.line_edit_text_changed)
def line_edit_text_changed(self, text): #==================================
#---- set the text in label ----
self.my_label.setText(text)
#---- determine new width of popup ----
fm = self.line_edit.fontMetrics()
txtWidth = fm.boundingRect(text).width() + 10 # Padding to the left.
# Value is arbitrary.
newWidth = max(txtWidth + self.frame_thick * 2, self.min_width)
self.setFixedWidth(newWidth)
def eventFilter(self, source, event): #=====================================
if event.type() == QtCore.QEvent.WindowDeactivate:
self.close()
return QtGui.QWidget.eventFilter(self, source, event)
def resizeEvent(self, event): #=============================================
self.move_UI()
QtGui.QWidget.resizeEvent(self, event)
def move_UI(self): # =======================================================
y_btn = self.button.mapToGlobal(QtCore.QPoint(0, 0)).y()
x_win = self.parent.mapToGlobal(QtCore.QPoint(0, 0)).x()
w_pop = self.frameGeometry().width()
x = x_win - w_pop - 12 # 12 is an arbitrary value.
y = y_btn
self.move(QtCore.QPoint(x, y))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
instance_1 = Tool_Window()
instance_1.show()
sys.exit(app.exec_())
This results in:
Update (2015-07-30): Popup shrink to the width of the content
I've extended the example so that now the popup starts with a minimum with of 100 that extends when the width of the text goes over this value. Also, the width of the popup will shrink, down to the minimum value of 100, if text is removed.
This is done by calculating the width of the text in QLineEdit when its content change and using the value to assign a fixed width to the popup window in the method line_edit_text_changed.
I found this way:
GdkPixmap *backPixMap = gdk_pixmap_create_from_xpm ( window , NULL , NULL , fileName );
gdk_window_set_back_pixmap( GTK_WIDGET( window )->window , backPixMap , FALSE );
but it seems that GdkPixmap is obsolete now...
So, with GTK3, how can I set the background image of a GtkWindow?
You just need to use an Overlay. Following is an example.
class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.overlay = Gtk.Overlay()
self.add(self.overlay)
self.bg = Gtk.Image()
# Load file. Optionally scale it for window
self.bg.set_from_file(BACKGROUND_IMAGE)
# Wrapping in the Scrollable make it resizable.
scrollable_wrapper = Gtk.ScrolledWindow()
scrollable_wrapper.add(self.bg)
scrollable_wrapper.set_size_request(700, 500)
self.overlay.add(scrollable_wrapper)
text = Gtk.Label("Test")
self.overlay.add_overlay(text)
self.connect('destroy', lambda w: Gtk.main_quit())
self.show_all()
Window()
Gtk.main()
I used a JpGraph in php. Everything ok but slice ($p1->SetSliceColors($color);) color not work. It all time default color.
Here is my used code. Please help me :
$data = array('40','50', '10');
$Legends = array('Loss','Win', 'Draw');
$labels = array("Loss\n(%.1f%%)","Win\n(%.1f%%)","Draw\n(%.1f%%)");
$color = array('red','red','red');
$graph = new PieGraph(550,350);
$graph->SetShadow();
$p1 = new PiePlot3D($data);
$p1->ExplodeSlice(1);
$p1->SetCenter(0.55);
$p1->SetLegends($Legends);
$graph->legend->Pos(0.5,0.1);
$p1->SetTheme("earth");
$p1->SetSliceColors($color);
// Setup the labels to be displayed
$p1->SetLabels($labels);
$p1->SetLabelPos(1);
$p1->SetLabelType(PIE_VALUE_PER);
$p1->value->Show();
$p1->value->SetFont(FF_FONT1,FS_NORMAL,9);
$p1->value->SetColor('navy');
$graph->Add($p1);
$graph->Stroke();
I had the same problem. Call the Add method before setting colors:
$p1 = new PiePlot3D($data);
$graph->Add($p1);
Changing the display settings of line/bar graphs
try
$graph = new PieGraph(550,350);
$graph->ClearTheme();
Leave out
$p1->SetTheme("earth");
SetSliceColors worked for me.