Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
Fixed window repositioning
Browse files Browse the repository at this point in the history
Fixed that when the app updated the coordinates it would go back to the top of the screen, now it should stay where you put it.
  • Loading branch information
Uriei committed Apr 1, 2018
1 parent 9233227 commit bc562b9
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions EDPlanetBearing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@ def callback():
root.destroy()
exit()

def resize(root, h):
def resize(root, h, StartingUp=False):
#Creating window parameters
w = 159 # width for the Tk root
#h = 40 # height for the Tk root
# get screen width and height
ws = root.winfo_screenwidth() # width of the screen
hs = root.winfo_screenheight() # height of the screen

# calculate x and y coordinates for the Tk root window
x = (ws/2) - (w/2)
y = (hs/100)# - (h/2)
try:
if StartingUp:
# calculate x and y coordinates for the Tk root window
x = (ws/2) - (w/2)
y = (hs/100)# - (h/2)
else:
x = root.winfo_rootx()
y = root.winfo_rooty()

# set the dimensions of the screen
# and where it is placed
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
except Exception as e:
print("E05: " + str(e))
print("Error on resizing")

# set the dimensions of the screen
# and where it is placed
root.geometry('%dx%d+%d+%d' % (w, h, x, y))

class MyHandler(FileSystemEventHandler):
class JournalUpdate(FileSystemEventHandler):
def on_modified(self, event):
if "Status.json" in event.src_path:
calculate()
Expand Down Expand Up @@ -175,7 +184,7 @@ def calculate(event="None"):
JournalFile = eliteJournalPath + "Status.json"

#watchdog
event_handler = MyHandler()
event_handler = JournalUpdate()
observer = Observer()
observer.schedule(event_handler, path=eliteJournalPath, recursive=False)
observer.start()
Expand Down Expand Up @@ -246,13 +255,18 @@ def calculate(event="None"):

#Testing Window movement
def dragwin(event):
x = mainframe.winfo_pointerx() - offsetx
y = mainframe.winfo_pointery() - offsety
root.geometry('+{x}+{y}'.format(x=x,y=y))
global offx
global offy
offx = mainframe.winfo_pointerx() - offsetx
offy = mainframe.winfo_pointery() - offsety
root.geometry('+{x}+{y}'.format(x=offx,y=offy))

def clickwin(event):
offsetx = event.x
offsety = event.y

offx = 0
offy = 0
offsetx = 0
offsety = 0
mainframe.bind('<ButtonPress-1>',clickwin)
Expand All @@ -270,7 +284,7 @@ def clickwin(event):
CloseB = ttk.Button(mainframe, text=" X ", command=callback)
CloseB.grid(column=9, row=1, sticky=(E))

resize(root, 37)
resize(root, 37, True)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
root.protocol("WM_DELETE_WINDOW", callback)
Expand Down

0 comments on commit bc562b9

Please sign in to comment.