{"action":"created","issue":{"url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI/issues/2391","repository_url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI","labels_url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI/issues/2391/labels{/name}","comments_url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI/issues/2391/comments","events_url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI/issues/2391/events","html_url":"https://github.com/PySimpleGUI/PySimpleGUI/issues/2391","id":539384141,"node_id":"MDU6SXNzdWU1MzkzODQxNDE=","number":2391,"title":"[Bug] My problem is no graph showing with coordinate system origin ","user":{"login":"martinmeteor","id":58822518,"node_id":"MDQ6VXNlcjU4ODIyNTE4","avatar_url":"https://avatars1.githubusercontent.com/u/58822518?v=4","gravatar_id":"","url":"https://api.github.com/users/martinmeteor","html_url":"https://github.com/martinmeteor","followers_url":"https://api.github.com/users/martinmeteor/followers","following_url":"https://api.github.com/users/martinmeteor/following{/other_user}","gists_url":"https://api.github.com/users/martinmeteor/gists{/gist_id}","starred_url":"https://api.github.com/users/martinmeteor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinmeteor/subscriptions","organizations_url":"https://api.github.com/users/martinmeteor/orgs","repos_url":"https://api.github.com/users/martinmeteor/repos","events_url":"https://api.github.com/users/martinmeteor/events{/privacy}","received_events_url":"https://api.github.com/users/martinmeteor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-12-18T00:30:44Z","updated_at":"2019-12-18T01:54:43Z","closed_at":null,"author_association":"NONE","body":"### Type of Issues (Enhancement, Error, Bug, Question)\r\nBug: In the Demo_Graph_Drag_Rectangle.py I tried to change the coordinate system to a scientific style, origin at bottom left. Result no graph showing.\r\nI fixed it by using the coordinate origin at top left and mirroring the coordinate values at the end. Seems a bit clumsy\r\n### Operating System\r\nWindows10\r\n### Python version\r\n3.6.5\r\n### PySimpleGUI Port and Version\r\n4.6.0 Released 11-Nov-2019 <module 'PySimpleGUI' from 'c:\\\\anaconda3\\\\lib\\\\site-packages\\\\PySimpleGUI\\\\__init__.py'>\r\n\r\n### Your Experience Levels In Months or Years\r\n\r\n___1y______ Python programming experience\r\n___20y______ Programming experience overall\r\ntried tkinter gave up__ Have used another Python GUI Framework (tkiner, Qt, etc) previously (yes/no is fine)?\r\nNew to Github\r\n\r\n### You have completed these steps:\r\n\r\n- [x] Read instructions on how to file an Issue\r\n- [x] Searched through main docs http://www.PySimpleGUI.org for your problem\r\n- [ ] Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)\r\n- [x] Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com\r\n- [ ] Note that there are also Demo Programs under each port on GitHub\r\n- [ ] Run your program outside of your debugger (from a command line)\r\n- [ ] Searched through Issues (open and closed) to see if already reported\r\n\r\n\r\n### Code or partial code causing the problem\r\n\r\n            graph_bottom_left=(0, 0), # y starts at bottom\r\n            graph_top_right=(w, h),   # does not work\r\n\r\nsee the corrected version below\r\n\r\n```python\r\nimport PySimpleGUI as sg\r\n\r\n\"\"\"\r\n    Demo - Drag a rectangle to draw it\r\n    modified for scientific coordinate system with origin at BOTTOM left\r\n\"\"\"\r\n\r\ndef mirror_y(xy,imy):\r\n    x = xy[0]\r\n    y = imy - xy[1]\r\n    return (x,y)\r\n\r\n# image_file = r'Color-names.png'\r\nimage_file = 'tmp.png'       # image is optional\r\n\r\nw,h = (400,200)\r\n\r\nlayout = [[sg.Graph(\r\n            canvas_size=(w,h),\r\n            graph_bottom_left=(0, h), # y starts at top, set y-scale here\r\n            graph_top_right=(w, 0),  \r\n            # graph_bottom_left=(0, 0), # y starts at bottom\r\n            # graph_top_right=(w, h),   # does not work\r\n            key=\"-GRAPH-\",\r\n            change_submits=True,  # mouse click events\r\n            drag_submits=True),],\r\n            [sg.Text(key='info', size=(60, 1))]]\r\n\r\nwindow = sg.Window(\"draw rect on image\", layout, finalize=True)\r\n# get the graph element for ease of use later\r\ngraph = window[\"-GRAPH-\"]     # type: sg.Graph\r\n\r\ngraph.draw_image(image_file, location=(0,0)) if image_file else None\r\ndragging = False\r\nstart_point = end_point = prior_rect = None\r\n\r\nwhile True:\r\n    event, values = window.read()\r\n\r\n    if event is None:\r\n        break  # exit\r\n    \r\n    if event == \"-GRAPH-\":                      # if there's a \"Graph\" event, then it's a mouse\r\n        x, y = values[\"-GRAPH-\"]\r\n        if not dragging:\r\n            start_point = (x, y)\r\n            dragging = True\r\n        else:\r\n            end_point = (x, y)\r\n        if prior_rect:\r\n            graph.delete_figure(prior_rect)\r\n        if None not in (start_point, end_point):\r\n            prior_rect = graph.draw_rectangle(start_point, end_point, line_color='red')\r\n    \r\n    elif event.endswith('+UP'):                 # The drawing has ended because mouse up\r\n    \r\n        start_point = mirror_y(start_point, h)  # workaround, mirror values \r\n        end_point = mirror_y(end_point, h)      # for further use\r\n\r\n        info = window[\"info\"]\r\n        info.update(value=f\"grabbed rectangle from {start_point} to {end_point}\")\r\n        start_point, end_point = None, None     # enable grabbing a new rect\r\n        dragging = False\r\n    \r\n    else:\r\n        print(\"unhandled event\", event, values)\r\n```"},"comment":{"url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI/issues/comments/566831044","html_url":"https://github.com/PySimpleGUI/PySimpleGUI/issues/2391#issuecomment-566831044","issue_url":"https://api.github.com/repos/PySimpleGUI/PySimpleGUI/issues/2391","id":566831044,"node_id":"MDEyOklzc3VlQ29tbWVudDU2NjgzMTA0NA==","user":{"login":"PySimpleGUI","id":46163555,"node_id":"MDQ6VXNlcjQ2MTYzNTU1","avatar_url":"https://avatars3.githubusercontent.com/u/46163555?v=4","gravatar_id":"","url":"https://api.github.com/users/PySimpleGUI","html_url":"https://github.com/PySimpleGUI","followers_url":"https://api.github.com/users/PySimpleGUI/followers","following_url":"https://api.github.com/users/PySimpleGUI/following{/other_user}","gists_url":"https://api.github.com/users/PySimpleGUI/gists{/gist_id}","starred_url":"https://api.github.com/users/PySimpleGUI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PySimpleGUI/subscriptions","organizations_url":"https://api.github.com/users/PySimpleGUI/orgs","repos_url":"https://api.github.com/users/PySimpleGUI/repos","events_url":"https://api.github.com/users/PySimpleGUI/events{/privacy}","received_events_url":"https://api.github.com/users/PySimpleGUI/received_events","type":"User","site_admin":false},"created_at":"2019-12-18T01:54:43Z","updated_at":"2019-12-18T01:54:43Z","author_association":"OWNER","body":"Let me verify what you're after.  You would like 0,0 to be at the bottom left corner and (400,200) to be at the top right?\r\n\r\nIf so this code worked which is a copy of what's posted at the drag rectangle demo except I modified the coordinates to be 0,0 at the bottom left.\r\n\r\n```python\r\nimport PySimpleGUI as sg\r\n\r\n\"\"\"\r\n    Demo - Drag a rectangle to draw it\r\n\r\n    This demo shows how to use a Graph Element to (optionally) display an image and then use the\r\n    mouse to \"drag a rectangle\".  This is sometimes called a rubber band and is an operation you\r\n    see in things like editors\r\n\"\"\"\r\n\r\n# image_file = r'Color-names.png'\r\nimage_file = None  # image is optional\r\n\r\nlayout = [[sg.Graph(\r\n    canvas_size=(400, 400),\r\n    graph_bottom_left=(0, 0),\r\n    graph_top_right=(400, 400),\r\n    key=\"-GRAPH-\",\r\n    change_submits=True,  # mouse click events\r\n    drag_submits=True), ],\r\n    [sg.Text(key='info', size=(60, 1))]]\r\n\r\nwindow = sg.Window(\"draw rect on image\", layout, finalize=True)\r\n# get the graph element for ease of use later\r\ngraph = window[\"-GRAPH-\"]  # type: sg.Graph\r\n\r\ngraph.draw_image(image_file, location=(0, 0)) if image_file else None\r\ndragging = False\r\nstart_point = end_point = prior_rect = None\r\n\r\nwhile True:\r\n    event, values = window.read()\r\n\r\n    if event is None:\r\n        break  # exit\r\n\r\n    if event == \"-GRAPH-\":  # if there's a \"Graph\" event, then it's a mouse\r\n        x, y = values[\"-GRAPH-\"]\r\n        if not dragging:\r\n            start_point = (x, y)\r\n            dragging = True\r\n        else:\r\n            end_point = (x, y)\r\n        if prior_rect:\r\n            graph.delete_figure(prior_rect)\r\n        if None not in (start_point, end_point):\r\n            prior_rect = graph.draw_rectangle(start_point, end_point, line_color='red')\r\n\r\n    elif event.endswith('+UP'):  # The drawing has ended because mouse up\r\n        info = window[\"info\"]\r\n        info.update(value=f\"grabbed rectangle from {start_point} to {end_point}\")\r\n        start_point, end_point = None, None  # enable grabbing a new rect\r\n        dragging = False\r\n\r\n    else:\r\n        print(\"unhandled event\", event, values)\r\n```\r\n"}}
{"actor":{"display_login":"PySimpleGUI"}}