Dynamically changing the command window title in Matlab - windows

I want to change the title of the the command window in matlab to state the current branch I am working on.
I know where to find the current branch name.
I need that every time this file is changed to note on a new branch, the title of the command window will be updated with the new branch name.
Any thoughts?

I have this M-file laying around (I think I got it from here). It might suit your needs:
function idetitle(Title)
%IDETITLE Set Window title of the Matlab IDE
%
% Examples:
% idetitle('Matlab - Foo model')
% idetitle(sprintf('Matlab - some big model - #%d', feature('getpid')))
win = appwin();
if ~isempty(win)
win.setTitle(Title);
end
end
function out = appwin()
%APPWIN Get main application window
wins = java.awt.Window.getOwnerlessWindows();
for ii = 1:numel(wins)
if isa(wins(ii), 'com.mathworks.mde.desk.MLMainFrame')
out = wins(ii);
return
end
end
out = [];
end

Related

My toplevel window in tkinter is no longer being destroyed. It was working fine until I tried changing other aspects of my function

I'm trying to get a popup window to display random text and a picture every time a button is pressed in tkinter. My original code was going to use an if/elif statement to do this. It worked as intended but I thought it might be easier to pair the data in a dictionary since there would be 50 elif statements otherwise (is it frowned upon to use so many? I actually found it easier to read).I was able to get this working but now the toplevel window in tkinter is not being destroyed like it was in the original function. A new Label is just being created on top of it and I can't figure out why. The function code is below. Thanks in advance, any help would be appreciated!
def Add_Gemstone2():
global Addstone
#destroy the previous window if there is one.
try:
AddStone.destroy()
except(AttributeError, NameError):
pass
#create the window.
AddStone=Toplevel()
AddStone.configure(bg='White', height=200, width=325)
AddStone.geometry('325x180+10+100')
# add gemstones to list from file.
gem_stones = open('gemstones.txt')
all_gem_stones = gem_stones.readlines()
gemstones = []
for i in all_gem_stones:
gemstones.append(i.rstrip())
# Add pictures to list.
path = r'C:\Users\Slack\Desktop\PYTHON WORKS\PYTHON GUI PROJECT\gems'
gempictures = []
# r=root, d=directories, f = files
for r,d,f in os.walk(path):
for file in f:
if '.gif' in file:
gempictures.append(os.path.join(r, file))
#create dictionary from lists.
gemdiction = dict(zip(gemstones, gempictures))
key, val = random.choice(list(gemdiction.items()))
# create the labels.
glbl1 = Label(AddStone, text=key, bg='gold', wraplength=300)
glbl1.pack()
image = ImageTk.PhotoImage(Image.open(val))
glbl2 = Label(AddStone, image=image)
glbl2.image = image
glbl2.pack()

Roblox - How would I make a script that closes an open GUI when another is opened?

I have two GUI's that are opened by a button each at the top of the screen, but I want to make it so that if someone tries to open the second GUI with the first open, it will close the first one before opening the second one.
You can do something like:
local frames = {
[buttonA] = frameA;
[buttonB] = frameB;
}
for button,frame in pairs(frames) do
button.MouseButton1Click:connect(function()
if frame.Visible then
-- If we try to reopen the current frame, close it
frame.Visible = false
return
end
-- Close all frames and make ours visible
for k,v in pairs(frames) do
-- 'v == frame' is true if it's our frame
v.Visible = v == frame
end
end)
end
You should also check out the ROBLOX Wiki. It has some nice tutorials for Lua and stuff like opening/closing GUIs.
100% WORKS
To make an opening and closing gui...Put this script:
FIRSTGUINAME is your first gui, rename it and SECONDGUINAME is your second gui name so...
FIRSTGUINAME = script.Parent -- very important classifying info
SECONDGUINAME = script.Parent.Parent.Parent:WaitForChild(YOUR SECOND GUI)
FIRSTGUINAME.MouseButton1Click:connect(function()
SECONDGUINAME.Visible = not Visible
Thats all, now just copy paste this and your set
If you want to close a GUI if another one is open you can try this code:
GUI1 = (insert)
GUI2 = (insert)
GUI.MouseButton1Click:connect(function()
if GUI1.Visible == false then
if GUI2.Visible == true then
GUI2.Visible = false
GUI1.Visible = true
else
GUI.Visible = true
end
else
GUI1.Visible = false
end
If you are into the fancy stuff with the tweens, you might have to do that research yourself.

Menu bar icon in OS X for script running as daemon?

I have a ruby script(https://github.com/daemonza/MacBak) that runs on my macbook as a daemon and monitors a bunch of directories for file changes and rsync any changes that happens. I was wondering would i be able to let it create a icon in the menu bar at the top? Just so that I know it's actually running, without having to check for it with ps.
Maybe later if needed I might want to be able to control the script from there, simple drop down with stop and status entries, etc.
It seems from ObjectC I can call NSStatusItem to get the icon, but I really just want to do it easily from my Ruby script. Perhaps maybe some applescript call that I can do?
This MacRuby script creates a status bar icon:
https://github.com/ashchan/gmail-notifr
So does this one:
https://github.com/isaac/Stopwatch
Here's a Gist including code that does it:
https://gist.github.com/1480884
# We build the status bar item menu
def setupMenu
menu = NSMenu.new
menu.initWithTitle 'FooApp'
mi = NSMenuItem.new
mi.title = 'Hellow from MacRuby!'
mi.action = 'sayHello:'
mi.target = self
menu.addItem mi
mi = NSMenuItem.new
mi.title = 'Quit'
mi.action = 'quit:'
mi.target = self
menu.addItem mi
menu
end
# Init the status bar
def initStatusBar(menu)
status_bar = NSStatusBar.systemStatusBar
status_item = status_bar.statusItemWithLength(NSVariableStatusItemLength)
status_item.setMenu menu
img = NSImage.new.initWithContentsOfFile 'macruby_logo.png'
status_item.setImage(img)
end
# Menu Item Actions
def sayHello(sender)
alert = NSAlert.new
alert.messageText = 'This is MacRuby Status Bar Application'
alert.informativeText = 'Cool, huh?'
alert.alertStyle = NSInformationalAlertStyle
alert.addButtonWithTitle("Yeah!")
response = alert.runModal
end
def quit(sender)
app = NSApplication.sharedApplication
app.terminate(self)
end
app = NSApplication.sharedApplication
initStatusBar(setupMenu)
app.run
You could look at MacRuby. It's a way of developing OS X apps using Ruby instead of Objective-C. It includes a number of improvements, such as getting rid of header files, so yu just have "implementation" files in Ruby. You can use IB for building windows too

How to create a walking animation in LOVE 2D

So I was wondering how to change an image of character I've created depending on the key I've pressed/am pressing?
My ultimate going to to have a walking animation occuring when "d" (or any of the wasd keys) is pressed but then he stands still when the "d" key has just been pressed etc. All images have been created already.
I've tried this but it didn't work out:
function love.load()
if love.keyboard.isDown("a") then
hero = love.graphics.newImage("/hero/11.png")
elseif love.keyboard.isDown("d") then
hero = love.graphics.newImage("/hero/5.png")
elseif love.keyboard.isDown("s") then
hero = love.graphics.newImage("/hero/fstand.png")
elseif love.keyboard.isDown("w") then
hero = love.graphics.newImage("/hero/1.png")
end
function love.draw()
love.graphics.draw(background)
love.graphics.draw(hero, x, y)
end
You must understand how LÖVE works. It (very basically) does this:
love.load() -- invoke love.load just once, at the beginning
while true do -- loop that repeats the following "forever" (until game ends)
love.update(dt) -- call love.update()
love.draw() -- call love.draw()
end
This schema is so frequent that the loop itself has a name - it's called The Game Loop.
Your code does't work because you are using love.load() as if it was part of the game loop, but it isn't. It's called at the beginning, during the first millisecond or so of your program, and never again.
You want to use love.load do load the images, and love.update to change them:
function love.load()
heroLeft = love.graphics.newImage("/hero/11.png")
heroRight = love.graphics.newImage("/hero/5.png")
heroDown = love.graphics.newImage("/hero/fstand.png")
heroUp = love.graphics.newImage("/hero/1.png")
hero = heroLeft -- the player starts looking to the left
end
function love.update(dt)
if love.keyboard.isDown("a") then
hero = heroLeft
elseif love.keyboard.isDown("d") then
hero = heroRight
elseif love.keyboard.isDown("s") then
hero = heroDown
elseif love.keyboard.isDown("w") then
hero = heroUp
end
end
function love.draw()
love.graphics.draw(background)
love.graphics.draw(hero, x, y)
end
The code above has certain repetitiveness that can be factored out using tables, but I've left it simple on purpose.
You will also notice that I have included the dt parameter in the love.update function. This is important, since you will need it to make sure that animations work the same in all computers (the speed at which love.update is called depends on each computer, and dt allows you to cope with that)
Nevertheless, if you want to do animations, you will probably want to use this Animation Lib or my own.

Dynamic refresh in a view - xcode 4 / interface builder

I'm new to xcode so please bear with me.
I have a label that I have set to blank, and after a user clicks 'go' I generate a random word or number and use:
self.label.stringValue = "some_word"
to update the view. (I am using MacRuby btw)
However, I would like to show 20 or so random words in quick succession before the last one is shown - just because it's too boring at the moment. (Alternatively, I'd be happy with showing an animated graphic in its place - which is replaced by the final random word.)
I've tried things like:
100.times do
num = rand(40)
self.label.stringValue = num
end
But it doesn't work. I've also tried .reloadData but to no avail as well.
Any ideas on how to achieve this?
So as not to leave the question haning, from the Macruby mailing list:
def drawWord(sender)
if !next_word
self.timer.invalidate
return
end
self.label.stringValue = next_word
self.setNeedsDisplay true
end
def next_word
...
end
self.timer = NSTimer.scheduledTimerWithTimeInterval( 1/20.0,
target:self, selector:"drawWord:", userInfo:nil, repeats:true)

Resources