{"id":164,"date":"2010-12-09T10:26:12","date_gmt":"2010-12-09T07:26:12","guid":{"rendered":"http:\/\/python.pingviinitiivul.ee\/?p=164"},"modified":"2010-12-09T16:56:50","modified_gmt":"2010-12-09T13:56:50","slug":"kaksteist","status":"publish","type":"post","link":"https:\/\/python.pingviinitiivul.ee\/?p=164","title":{"rendered":"Kaksteist"},"content":{"rendered":"<p>R\u00e4\u00e4gime t\u00e4na natuke UMList ehk plokkskeemidest. Objekte kasutavaid programme peab t\u00e4pselt planeerima, parem on k\u00f5ik p\u00f5hjalikult l\u00e4bim\u00f5elda, et keset t\u00f6\u00f6d ei tuleks ootamatuid halbu \u00fcllatusi. Selleks on hea koostada plokkskeem &#8211; iga objekt (class) eraldi koos oma andmet\u00fc\u00fcpidega (nimed, arvud, nimekirjad, alamobjektid) ja objektide omavahelised suhted, st kus kasutatakse \u00fchte objekti teise sees.<\/p>\n<p>!\/usr\/bin\/python<br \/>\n -*- coding: utf-8 -*-<\/p>\n<p>galaktika.py:<br \/>\n<code><br \/>\nclass Taht() :<br \/>\n&nbsp;&nbsp;&nbsp;    nimi = u\"\"<br \/>\n&nbsp;&nbsp;&nbsp;    koordX = 0<br \/>\n&nbsp;&nbsp;&nbsp;    koordY = 0<br \/>\n&nbsp;&nbsp;&nbsp;    def __init__(self, koordX,  koordY) :<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        self.koordX=koordX<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        self.koordY=koordY<br \/>\n&nbsp;&nbsp;&nbsp;    def annaX(self):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        return int(self.koordX)<br \/>\n&nbsp;&nbsp;&nbsp;    def annaY(self):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        return int(self.koordY)<\/code><\/p>\n<p>GalTest.py:<br \/>\n<code><br \/>\nimport wx<br \/>\nimport random<br \/>\nimport galaktika<br \/>\nclass GalTest(wx.Frame):<br \/>\n&nbsp;&nbsp;&nbsp;    tahed = []<br \/>\n&nbsp;&nbsp;&nbsp;    def __init__(self, parent, id, title):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        for i in range (1, 100):<br \/>\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;           self.tahed.append(galaktika.Taht(random.randint(50,  900), random.randint(50,  500)))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        wx.Frame.__init__(self, parent, id, title, size=(1000, 600))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        self.Bind(wx.EVT_PAINT, self.joonistaja)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       self.Centre()<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        self.Show(True)<br \/>\n&nbsp;&nbsp;&nbsp;    def joonistaja(self, event):<br \/>\n&nbsp;&nbsp;&nbsp;    #dc - drawing contect - ehk joonistusala, selle v\u00f5ib \u00fcmbernimetada ka<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        dc = wx.PaintDC(self)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        dc.SetPen(wx.Pen('#000000', 1, wx.SOLID))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        dc.SetBrush(wx.Brush('#112233'))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       dc.DrawRectangle(10, 15, 980, 560)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        for taht in self.tahed:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            dc.SetBrush(wx.Brush('#ffdd33'))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            dc.DrawEllipse(taht.annaX(), taht.annaY(),   10 , 8)<br \/>\napp = wx.App()<br \/>\nGalTest(None, -1, 'Galaktika test')<br \/>\napp.MainLoop()<\/code><\/p>\n<p>Kuidas saada k\u00e4tte ekraani suurus?<br \/>\n<code> ekraan=wx.GetDisplaySize()<br \/>\n laius = wx.GetDisplaySize().GetWidth()<br \/>\n korgus=wx.GetDisplaySize().GetHeight()<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>R\u00e4\u00e4gime t\u00e4na natuke UMList ehk plokkskeemidest. Objekte kasutavaid programme peab t\u00e4pselt planeerima, parem on k\u00f5ik p\u00f5hjalikult l\u00e4bim\u00f5elda, et keset t\u00f6\u00f6d ei tuleks ootamatuid halbu \u00fcllatusi. Selleks on hea koostada plokkskeem &#8211; iga objekt (class) eraldi koos oma andmet\u00fc\u00fcpidega (nimed, arvud, &hellip; <a href=\"https:\/\/python.pingviinitiivul.ee\/?p=164\">J\u00e4tka lugemist <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164"}],"version-history":[{"count":9,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=\/wp\/v2\/posts\/164\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python.pingviinitiivul.ee\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}