How to change current Plot Window Size (in R) - graphics

For example. Assume I do:
dev.new(width=5, height=4)
plot(1:20)
And now I wish to do
plot(1:40)
But I want a bigger window for it.
I would guess that the way to do it would be (assuming I don't want to open a new window) to do
plot(1:40, width=10, height=4)
Which of course doesn't work.
The only solution I see to it would be to turn off the window and start a new one. (Which will end my plotting history)
Is there a better way ?
Thanks.

Some workaround could be rather than using dev.new() R function use this function which should work across platform :
dev.new <- function(width = 7, height = 7)
{ platform <- sessionInfo()$platform if (grepl("linux",platform))
{ x11(width=width, height=height) }
else if (grepl("pc",platform))
{ windows(width=width, height=height) }
else if (grepl("apple", platform))
{ quartz(width=width, height=height) } }

Here is a my solution to this:
resize.win <- function(Width=6, Height=6)
{
# works for windows
dev.off(); # dev.new(width=6, height=6)
windows(record=TRUE, width=Width, height=Height)
}
resize.win(5,5)
plot(rnorm(100))
resize.win(10,10)
plot(rnorm(100))

Related

how to switch widgets in a QSplitter

How to modify a QSplitter panels from right to left, or center, without deleting the splitter and recreate it.
I uses replaceWidget, but it is giving: QSplitter::replaceWidget: Trying to replace a widget with one of its siblings, and QSplitter::replaceWidget: Trying to replace a widget with itself
widget_1, widget_2, widget_3, widget_4 = QWidget(), QWidget(), QWidget(), QWidget()
splitter1 = QSplitter(Qt.Vertical)
splitter1.addWidget(widget_1)
splitter1.addWidget(widget_2)
splitter1.setSizes([450, 350])
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(widget_3)
splitter2.addWidget(widget_4)
splitter2.setSizes([550, 250])
splitter3 = QSplitter(Qt.Horizontal)
splitter3.setObjectName('align_left')
splitter3.addWidget(splitter1)
splitter3.addWidget(splitter2)
splitter3.setSizes([100, 1000])
right_panel, left_panel = splitter3.widget(0), splitter3.widget(1)
splitter3.replaceWidget(0, left_panel)
splitter3.replaceWidget(1, right_panel)
I further tried to create two QSplitter using the same instances, but seems i need to create different instances for each QSplitter
I tried also, but not working
for i in reversed(range(splitter3.count())):
panel = splitter3.widget(i)
panel.setParent(None)
if align_panel == 'left':
splitter3.addWidget(splitter1)
splitter3.addWidget(splitter2)
splitter3.setSizes([100, 1000])
elif align_panel == 'right':
splitter3.addWidget(splitter2)
splitter3.addWidget(splitter1)
splitter3.setSizes([1000, 100])

Error using checkmouse

I'm trying to use checkmouse in order to undraw something from my window. When someone clicks the button it should undraw the text and write something else. I'm using checkMouse and getX() and getY() to do this but i keep receiving this error that states:
File "C:\Users\User\Documents\python\project2.py", line 71, in panel
if (clicknew.getX()>90 and clicknew.getX()<210) and (clicknew.getY()>35 and clicknew.getY() < 0):
AttributeError: 'NoneType' object has no attribute 'getX'
this code that i have done so far is as follows:
from graphics import *
#creating the game panel window
def panel():
#grey window, with coordinates flipped, with banners etc
win = GraphWin("Start Panel", 300,200)
win.setCoords(0,0,300,200)
win.setBackground("light grey")
#drawing the BoilerMazer banner with text
boilermazer = Rectangle(Point(0,200),Point(300,160))
boilermazer.setFill("white")
boilermazer.draw(win)
#text inside
banner1 = Text(Point(150,180),"BoilerMazer")
banner1.setStyle("bold")
banner1.setSize(20)
banner1.draw(win)
#initial game panel is going to have two buttons and a top scores object
#top score "screen"
toprec = Rectangle(Point(60,140),Point(240,50))
toprec.setFill("white")
toprec.draw(win)
#text inside toprec
topscores = Text(Point(150,130),"TOP SCORES")
topscores.setSize(8)
topscores.draw(win)
border = Text(Point(150,120),"======")
border.draw(win)
bigmac = Text(Point(150,110),"Big Mac 21")
bigmac.setSize(8)
bigmac.draw(win)
tt = Text(Point(150,90),"T.T 23")
tt.setSize(8)
tt.draw(win)
cshell = Text(Point(150,75),"C-Shell 25")
cshell.setSize(8)
cshell.draw(win)
macmac = Text(Point(150,55),"MacMac 27")
macmac.setSize(8)
macmac.draw(win)
#new player button that will eventually be clicked
new1 = Point(90,35)
new2 = Point(210,0)
newrec = Rectangle(new1,new2)
newrec.setFill("chartreuse2")
newrec.draw(win)
#new player button text
newplayer = Text(Point(150,18),"NEW PLAYER")
newplayer.draw(win)
#reset button
resetrec = Rectangle(Point(240,35),Point(300,0))
resetrec.setFill("red")
resetrec.draw(win)
#resettext
reset = Text(Point(270,18),"RESET")
reset.draw(win)
#secondary panel window is the game panel after they click new player
#set up points that we check between for the new player button first
#setting up the checkmouse
clicknew = win.checkMouse()
if (clicknew.getX()>90 and clicknew.getX()<210) and (clicknew.getY()>35 and clicknew.getY() < 0):
newplayer.undraw()
you can find the graphics window here:http://mcsp.wartburg.edu/zelle/python/graphics.py
I don't understand what I'm doing wrong, is there some other method that I'm supposed to be using? Thanks for your help
According to the docs, checkMouse() returns None if no mouse click has been detected priorly. So that seems to be the case.
You could put a loop around the call to checkMouse and keep checking if clicknew is not None and only in that case go on in your program. But maybe there's a better way...
UPDATE:
Example:
while True:
clicknew = win.getMouse()
if clicknew:
break
else:
time.sleep(0.1) # avoid busy waiting
# clicknew is set now => use it

Pyqt4 MDI no clean mdiarea

I am new to PyQt, I am developing an application like MDI, I use the QDesigner to build the forms (I come from Visual Basic), so far so good, but it is costing me horrors to run the application well, when I close a window, erase everything, but the frame remains on the mdi-area, click on the x and close. I attach the code.
With this I knock at the window:
def ordentrabajo(self):
self.cot = FichaOrdenTrabajo()
subwindow = QtGui.QMdiSubWindow()
self.cot.mdiarea = self.ventana.mdiArea
subwindow.setWidget(self.cot)
subwindow.setGeometry(0, 0, 595, 490)
self.ventana.mdiArea.addSubWindow(subwindow)
subwindow.showventana = self.cot.show()
And within the FichaOrdenTrabajo I close with:
def closeEvent(self, QCloseEvent):
self.emit(QtCore.SIGNAL('cerrar'))
general.saveposic('ctrlordentrabajo', self.x(), self.y())
self.subwindow.close = self.cdeta.close()
self.cdeta.hide()
# del self.subwindow
self.subwindow = None
leaving the main window in this state:
The question is how to do so that when closing the mdi-area is clean?
Thank you

python : bind function to button

this is my python code GUI generated from PAGE 4.6.
I want to create a function which will change the textbox value in real time example
tbCapturedImage.set("test 1").
take a look at
self.btnCapture.bind('<Button-1>', self.Capture_a)
but it cant seems to change the value of the textbox.
self.tbCapturedImage = Text(self.TLabelframe1)
self.tbCapturedImage.place(relx=0.04, rely=0.65, relheight=0.33
, relwidth=0.93)
self.tbCapturedImage.configure(background="white")
self.tbCapturedImage.configure(font="TkTextFont")
self.tbCapturedImage.configure(selectbackground="#c4c4c4")
self.tbCapturedImage.configure(width=206)
self.tbCapturedImage.configure(wrap=WORD)
self.btnCapture = Button(master)
self.btnCapture.place(relx=0.01, rely=0.92, height=45, width=982)
self.btnCapture.configure(activebackground="#d9d9d9")
self.btnCapture.configure(disabledforeground="#a7a4a7")
self.btnCapture.configure(font=font11)
self.btnCapture.configure(text='''Capture Image''')
self.btnCapture.bind('<Button-1>', self.Capture_a)
self.Labelframe1 = LabelFrame(master)
self.Labelframe1.place(relx=0.25, rely=0.48, relheight=0.43
, relwidth=0.74)
self.Labelframe1.configure(relief=GROOVE)
self.Labelframe1.configure(text='''Color Detection''')
self.Labelframe1.configure(width=740)
self.Labelframe2 = LabelFrame(master)
self.Labelframe2.place(relx=0.25, rely=0.05, relheight=0.43
, relwidth=0.35)
self.Labelframe2.configure(relief=GROOVE)
self.Labelframe2.configure(text='''Perspective Transformation''')
self.Labelframe2.configure(width=350)
self.Labelframe3 = LabelFrame(master)
self.Labelframe3.place(relx=0.61, rely=0.05, relheight=0.43
, relwidth=0.38)
self.Labelframe3.configure(relief=GROOVE)
self.Labelframe3.configure(text='''Haar-Like Detection''')
self.Labelframe3.configure(width=380)
def Capture():
tbCapture.Set("test")
def Capture_a(self,event):
self.Capture()
if __name__ == '__main__':
vp_start_gui()
You have to use self and set instead of Set
And probably you should use tbCapturedImage instead of tbCapture
def Capture(self): # self
self.tbCapturedImage.set("test") # self, set and tbCapturedImage
BTW: you can use command= in Button instead of bind
self.btnCapture = Button(master, command=self.Capture)
or
self.btnCapture.configure(command=self.Capture)
command= doesn't send event so method doesn't need argument event

How to manually set the toggle state of wxpython platebutton

I am building an application using platebutton iin wxpython. The problem is that I am not able to manually SetState of the toogle buton. I used SetState(0) but it does not change the state of toggle button. Any help would be great. Thanks. Sample code:
self.infinity= platebutton.PlateButton(self._ribbon,wx.ID_NEW, bmp = wx.Bitmap('infinity.bmp'), pos = (0,0), size = (38,18), style= platebutton.PB_STYLE_NOBG |platebutton.PB_STYLE_TOGGLE)
def OnInfinityToggled(self,event):
if event.GetEventObject().IsPressed():
self.popupmenu = wx.Menu()
Session = self.popupmenu.Append(-1, "Session")
self.Bind(wx.EVT_MENU, self.SessionMenu, Session)
self.PopupMenu(self.popupmenu,(2,23))
else:
pass
def SessionMenu(self, event):
print 5
self.infinity.SetState(0)
self.infinity.Raise()
PLATE_NORMAL = 0
PLATE_PRESSED = 1
PLATE_HIGHLIGHT = 2
SetState(0) means set to normal.
Here's how I managed to toggle state:
btn._ToggleState()
btn._pressed = True
I had the same problem. Playing around I managed to resolve my problem with
button._SetState(ix)
button.Refresh()
where ix = your choice of state.

Resources