Start git gui and gitk maximized - tk-toolkit

I'm using git version 2.37.1 under Cygwin and I'd like to get git gui (and gitk) to start maximized, and can't figure out how. Below is a somewhat long discourse on what I've tried.
When I resize my git gui window, its dimensions and state are stored in .git/config:
[gui]
wmstate = normal
geometry = 1574x870+134+79 445 220
When I maximize the window, the geometry is updated, but to a value like this:
[gui]
wmstate = normal
geometry = 1920x963+0+23 445 220
And when I start it with the above geometry, without any further modifications to the window position or size, it resets itself to this:
[gui]
wmstate = normal
geometry = 1920x963+8+31 445 220
The window is started normally (non-maximized), and it is offset +8 on the X-axis and +31 on the Y-axis.
I can explain the +31 on the Y axis, as it corresponds precisely to the height of the title bar, so the actual position is apparently of the internal window content, so the +31 accounts for the title bar to be visible.
I can't explain the +8 on the X axis though, as there is really an 8-pixel gap between the git gui window and the left border of the screen. It can't possibly be an 8-pixel window border adjustment (who has an 8-pixel window border?!).
Either way, the window is always started normally (non-maximized) and I can't figure out if it's possible to force it to start maximized. I guess it'd have to do with the gui.wmstate option, but I didn't find any value that would influence anything about the window.
I've also looked at the git gui source and found this to be run as part of exiting the git gui:
if {$cfg_wmstate eq {zoomed}} {
# on Windows wm geometry will lie about window
# position (but not size) when window is zoomed
# restore the window before querying wm geometry
wm state . normal
}
Disabling the last line or changing normal to zoomed didn't change a thing. Other than that, the geometry is read from the .git/config file on startup in an unremarkable way:
proc on_application_mapped {} {
global repo_config use_ttk
bind . <Map> {}
set gm $repo_config(gui.geometry)
if {$use_ttk} {
bind .vpane <Map> \
[list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
bind .vpane.files <Map> \
[list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
} else {
bind .vpane <Map> \
[list on_tk_pane_mapped %W 0 \
[lindex $gm 1] \
[lindex [.vpane sash coord 0] 1]]
bind .vpane.files <Map> \
[list on_tk_pane_mapped %W 0 \
[lindex [.vpane.files sash coord 0] 0] \
[lindex $gm 2]]
}
wm geometry . [lindex $gm 0]
}
if {[info exists repo_config(gui.geometry)]} {
bind . <Map> [list on_application_mapped]
wm geometry . [lindex $repo_config(gui.geometry) 0]
}
# -- Load window state
#
if {[info exists repo_config(gui.wmstate)]} {
catch {wm state . $repo_config(gui.wmstate)}
}
I don't see anything peculiar here, but then again I'm not really a Tcl/Tk guy.
Is there anything that can be done to start the git gui (and gitk) maximized?

Related

How to get the bounding box from a Revit Element with Revit API, then call to center of that bounding box

I am trying to rotate Revit elements about their center points. In order to do that, I need to select a Revit element and find its center point, then create a line with the coordinates at that elements center point.
My best idea to accomplish this is to wrap a Revit element in a bounding box and then find the center of that box. My problem is that I am unsure how to accomplish this.
I am using pyRevit (amazing tool) and I am stuck on how to either wrap the selected element with a bounding box or retrieve its existing bounding box.
Any help would be greatly appreciated! I am really trying to learn the Revit API and understand how everything works. I am making progress but there is a lot to unpack.
def pickobject():
from Autodesk.Revit.UI.Selection import ObjectType
#define the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
# Begin new transaction
t.Start()
# Select an element in Revit
picked = uidoc.Selection.PickObject(ObjectType.Element, "Select something.")
### ?????????? ###
# Get bounding box of selected element.
picked_bb = BoundingBoxXYZ(picked)
# Get max and min points of bounding box.
picked_bb_max = picked_bb.Max
picked_bb_min = picked_bb.Min
# Get center point between max and min points of bounding box.
picked_bb_center = (picked_bb_max + picked_bb_min) / 2
### ?????????? ###
# Close the transaction
t.Commit()
return picked, picked_bb_center
Thanks in advance for taking a look at what I have so far. Please let me know if anything needs further clarification!
edit:
#CyrilWaechter
I think you are right. Using LocationPoint would probably make more sense. I looked through the script you linked (thank you btw!) and I tried implementing this section in my code.
transform = doc.GetElement(picked.ElementId).GetTransform()
I am passing the ElementId through this statement but I get the error, "Wall" object has no attribute 'GetTransform'. Could you please help me understand this?
edit 2:
Thanks #JeremyTammik and #CyrilWaechter, your insights helped me understand where I was going wrong. While I still feel that certain properties are ambiguous in the Revit API, I was able to get my code to execute properly. I will post the code that I was able to get working below.
The centre of the bounding box is very easy to obtain. picked is a Reference. Get the ElementId from that, open it using doc.GetElement, and retrieve the bounding box using get_BoundingBox, cf. Conduits Intersecting a Junction Box
:
Element e = Util.SelectSingleElement(
uidoc, "a junction box" );
BoundingBoxXYZ bb = e.get_BoundingBox( null );
For certain elements and certain irregular shapes, you might want to use the centroid instead of the bounding box:
Solid Centroid and Volume Calculation
GetCentroid on GitHub
Edited and preserved for posterity by The Building Coder:
Python Rotate Picked Around Bounding Box Centre
Many thanks to Christian for the interesting discussion and Cyril for the wealth of additional information he provides!
Here is how I was able to solve my problem using pyRevit. This code allows you to rotate an element about its Z axis from the center of its bounding box.
To use this code, select a single Revit element and then open the Revit Python Shell. Copy and paste the code below into the Revit Python Shell notepad and click the run button. This will rotate the element by 45 degrees because the current rotateSelectedElement() argument is 45. You may change this number to any value before running.
# Import the math module to convert user input degrees to radians.
import math
# Get a list of all user selected objects in the Revit Document.
selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()]
# Definitions
def rotateSelectedElement(degrees_to_rotate):
from Autodesk.Revit.UI.Selection import ObjectType
#define the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
# Convert the user input from degrees to radians.
converted_value = float(degrees_to_rotate) * (math.pi / 180.0)
# Begin new transaction
t.Start()
# Get the first selected element from the current Revit doc.
el = selection[0].Id
# Get the element from the selected element reference
el_ID = doc.GetElement(el)
# Get the Bounding Box of the selected element.
el_bb = el_ID.get_BoundingBox(doc.ActiveView)
# Get the min and max values of the elements bounding box.
el_bb_max = el_bb.Max
el_bb_min = el_bb.Min
# Get the center of the selected elements bounding box.
el_bb_center = (el_bb_max + el_bb_min) / 2
#Create a line to use as a vector using the center location of the bounding box.
p1 = XYZ(el_bb_center[0], el_bb_center[1], 0)
p2 = XYZ(el_bb_center[0], el_bb_center[1], 1)
myLine = Line.CreateBound(p1, p2)
# Rotate the selected element.
ElementTransformUtils.RotateElement(doc, el, myLine, converted_value)
# Close the transaction
t.Commit()
# Execute
# Add the desired degrees to rotate by as an argument for rotateSelectedElement()
rotateSelectedElement(45)
edit: Made code clearer. Code now executes in Revit Python Shell without any further modifications. Refer to directions above if you have trouble!

AWK, Applescript, String/Int Parsing

This is a bit in depth, and I'm in a bit over my head. I've never used AWK, and the more I try to learn about it (perhaps it's the lateness of the hour) the more frustrating it's getting to be.
I'm trying to write an applescript... script to resize windows across my monitors. Now, I COULD take the easy route and hardcode my monitor dimensions into the script, but instead I decided to try and gather them dynamically. I've managed to find a code snippet that parses a plist and spits out ALMOST-useable info, here's the applescript:
set screenInfo to do shell script "defaults read /Library/Preferences/com.apple.windowserver | awk '
BEGIN { FS=\"= \" }
/Active/ { screens++ }
{ gsub(\";\",\"\",$2) }
/^ *OriginX/ { ox[screens] = $2 }
/^ *OriginY/ { oy[screens] = $2 }
/^ *Width/ { w[screens] = $2 }
/^ *Height/ { h[screens] = $2 }
END {
for (si=1;si<=screens;si++) {
print ox[si],oy[si],w[si],h[si]
}
}'"
return screenInfo
end getScreenInfo
That's working pretty well - in my "result" window, I get the following:
"0 0 1920 1080
\"-1600\" 0 1600 1200
1920 0 1680 1050
0 0 1920 1080
\"-1600\" 0 1600 1200
1920 0 1680 1050
3600 1050 1024 768 "
The first number pair is the coordinates for the top left corner of the monitor, the second number pair is the resolution of that monitor. Such is the case for each monitor - though there are duplicates of monitors 1-3, plus a ghost monitor. I don't really care about that, it should be parse-able.
My problem comes when I try to parse those numbers as ints so I can use them - using something like set theVar to word 1 of paragraph 2 of theString as integer, it parses as 1600, not the -1600 it needs to be. I tried stepping through the entire string, 1 character at a time, to remove the escaping backslashes, but I think those only actually show up in the results window - when I display dialog, they don't show. Even when I don't try to parse it as an integer, just word 1 of paragraph 2 it ignores the - and returns "1600". How else can I parse this? Goodness, I'm not a fan of applescript right now.
You can get the screen resolutions with AppleScriptObjC
use framework "Foundation"
set screenFrames to {}
set screens to current application's NSScreen's screens()
repeat with aScreen in screens
set end of screenFrames to aScreen's frame() as record
end repeat
screenFrames will contain a record for each screen containing records origin with x and y members and size with width and height members.
For example you can get the width of screen 1 with
set screen1Width to width of |size| of item 1 of screenFrames as integer

imagemagik make order wrong at 10th frame . like 1st frame 10th frame 2nd frame

convert -delay 100 -loop 0 010-*.png Yannimation.gif
010-0.png
010-2.png
010-3.png
010-4.png
010-5.png
010-6.png
010-7.png
010-8.png
010-9.png
010-10.png
010-11.png
010-12.png
It's not ImageMagick, it's the normal collating sequence. To see, run
ls 010-*
and you'll get the same result. Replace ls with DIR on Windows.
The solution is either to zero-pad your frame numbers:
010-01
010-02
010-03
or to explicitly enumerate them in the correct order on the commandline
convert 010-1.png 010-2.png ...

Love2d - how do i unload a file.lua

I have a menu screen that has an options button. when I click on this button it load the options.lua file perfectly fine.
love.filesystem.load( "options.lua" )( ) love.load( )
On the option screen I want to add a back button to go back to the main menu. In my head to do this I need to unload the options.lua file.
function love.mousepressed( x, y)
if x > 275 and x < 320 and y > 305 and y < 325 then
end
end
Although Paul's answer is one option, you could approach this differently:
You are thinking about this in a way that will cause you a lot of grief, because in Lua, and many other languages loading files is not meant as a way to run code at variable times. Although this might make you change more code than you want, consider creating a variable for GUI States and only draw what you want if that variable has a certain value. Eg:
Add to your love.load function:
function love.load()
-- Set the gui state to the defualt ( the main menu )
guistate = "menu" -- You probably should use an integer, am using a string for the purpose of clarity.
end
This Goes In the Same Place:
function love.mousepressed( x, y)
if x > 275 and x < 320 and y > 305 and y < 325 then
-- The back button is pressed, change the state to the menu.
guistate = "menu"
end
end
Add to your love.draw function:
function love.draw()
if guistate = "menu" then
-- Draw the stuff for your main menu
elseif guistate = "options" then
-- Draw the stuff for your options menu.
end
end
Extras
Also take a peek at these GUI libraries if you are interested:
Love Frames, and Quickie
There is no way to "unload" that file; you can only negate the effect of its loading. You execute the content of options.lua in that fragment and if it has something like a = 5, to undo this change, you need to save the value of a before executing the code in options.lua and then restore the value later.
Something like this may work for a:
local default = {}
default.a = a -- save the current value of a (if any)
love.filesystem.load( "options.lua" )( ) love.load( )
function love.mousepressed( x, y)
if x > 275 and x < 320 and y > 305 and y < 325 then
a = default.a
end
end
You can go through any other value (for example, have a list of names you want to restore). If you want, you can save all values in the global table and restore them later by iterating over pairs(_G). If you deal with tables, rather than simple values, you'll need to use deep copy to save and restore values.

Placing number tiles in Settlers of Catan for iOS

I'm coding Settlers of Catan for iOS and currently have my data tiles in a matix. Now, I'm trying to attach the numbers to each tile. But I'm stuck as to the correct way to do this algorithmically. There are specific rules for putting down the number tiles on the board. These are:
1) They must go in the pre-defined sequence shown in the image.
2) You must start in a corner of the board.
3) You must work your way around the board counter-clockwise, spiraling toward the center.
4) You must skip the desert tile.
Since there are only 6 places on the board where you can actually start putting tiles down, I realize that it wouldn't be difficult to hand-code the 6 solutions into my data grid. But there is a variation of the game in which the board gets larger, so I figured it would be worth exploring an algorithm.
Any thoughts how this can be achieved?
What you want to do will involve the geometric relationships between tiles (entries in your matrix)
You need a way of storing and querying that information.
There are several methods people have developed for assigning coordinates to hexagons:
http://playtechs.blogspot.com/2007/04/hex-grids.html
http://jemgine.omnisu.com/?page_id=412
http://www-cs-students.stanford.edu/~amitp/Articles/GridToHex.html
One way to do what you want, off the top of my head, would be for each hex to have 6 'pointers' to its neighbors. These pointers could really be indices in your array, of course.
You could detect a 'corner' hex by noting that it will have 3 'null' neighbors. Then you can traverse counter-clockwise from there, remembering which you've already visited.
Update (in response to comment)
Let's suppose that for a given hex, we store the 6 neighbors as I described.
For this discussion, we'll name those neighbors A-F.
We assign these counter-clockwise, because that's convenient for us.
Graphically:
A
_____
B / \ F
/ \
( )
\ /
C \_____/ E
D
For a 'corner' hex, we might have:
A
_____
B / \ NULL
/ \
( )
\ /
C \_____/ NULL
NULL
So if we are looking at this hex, and we list our adjacency information (wrapping around), we have:
A, B, C, NULL, NULL, NULL, A, B, C, ...
A soon as we find 3 NULLs in a row, we know that the next spot should "point" in our starting direction. In this case we should start off in the direction of 'A'.
Another example:
NULL
_____
NULL / \ NULL
/ \
( )
\ /
C \_____/ E
D
Just as before, we make a list, starting from the top.
NULL, NULL, C, D, E, NULL, NULL, NULL, C
As soon as we find 3 NULLs, the next one is our starting direction - 'C' in this case.
Spiraling onward in the same direction from there should be fairly straightforward (well not literally - har har).
PS: thanks to http://ascii.co.uk/art/hexagon for quick ascii art (:

Resources