def __init__(self): self.screenrect = get_screenrect() self.sidebar_width = 200 self.game_area = pygame.Rect( 0, 0, self.screenrect.width - self.sidebar_width, self.screenrect.height) self.ant_count = 4 self.ants = [] self.create_ants(self.ant_count) self.sidebar = Sidebar( pygame.Rect( self.screenrect.width - self.sidebar_width, 0, self.sidebar_width, self.screenrect.height, ), self, ) # right now a job is just a position # we want the ant to pick up the thing # and move it to a spot to drop it off self.jobs = [] self.working_jobs = [] self.done_jobs = [] self.drop_off = pygame.Rect(20, 20, 20, 20) self.create_jobs(self.ant_count)
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, self.AUTHOR, self.EMAIL) f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # Calculate the sidebar links, adding a few of our own. self.__d = {'rootdir': rootdir} dir = os.path.split(file)[0] p.process_sidebar() p.sidebar.append(BLANKCELL) # It is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up. self.__linkfixer.massage(p.sidebar, self.__d) Sidebar.__init__(self, p.sidebar) p.sidebar.append(BLANKCELL) # Fix up our site links, no relthis because the site links are # relative to the root of our web pages. sitelinks=get_sitelinks(file, rootdir, relthis) sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks) # kludge! for i in range(len(p.sidebar)-1, -1, -1): if p.sidebar[i] == 'Email Us': p.sidebar[i] = 'Email me' break p.sidebar.append((None, ''))
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, '*****@*****.**') f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # calculate the sidebar links, adding a few of our own self._d = {'rootdir': rootdir} p.process_sidebar() p.sidebar.append(BLANKCELL) # it is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up p.sidebar.append(('http://www.python.org/', ''' <center> <img border="0" src="%(rootdir)s/images/PythonPoweredSmall.gif"></center> ''' % self._d)) self.__linkfixer.massage(p.sidebar, self._d) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of our web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self._d, aboves=1) Banner.__init__(self, sitelinks, cols=2)
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, self.AUTHOR) f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # calculate the sidebar links, adding a few of our own self.__d = {'rootdir': rootdir} p.process_sidebar() p.sidebar.append(BLANKCELL) # it is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up p.sidebar.append(('%(rootdir)s', ''' <center> <img alt="" border=0 src="%(rootdir)s/pics/PythonPoweredSmall.gif"></center> ''' % self.__d)) self.__linkfixer.massage(p.sidebar, self.__d) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of our web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks) # calculate the random corner # XXX Should really do a list of the pics directory... NBANNERS = 64 i = whrandom.randint(0, NBANNERS-1) s = "PyBanner%03d.gif" % i self.__d['banner'] = s self.__whichbanner = i
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, '*****@*****.**') f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # calculate the sidebar links, adding a few of our own self._d = {'rootdir': rootdir} p.process_sidebar() p.sidebar.append(BLANKCELL) # it is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up p.sidebar.append(('http://www.python.org/', ''' <center> <img border=0 src="%(rootdir)s/images/PythonPoweredSmall.gif"></center> ''' % self._d)) self.__linkfixer.massage(p.sidebar, self._d) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of our web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self._d, aboves=1) Banner.__init__(self, sitelinks, cols=2)
def __init__(self, file, rootdir, relthis): self.__body = None root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, 'Barry A. Warsaw', '*****@*****.**') f = self.__linkfixer = LinkFixer(html, rootdir, relthis) p.process_sidebar() p.sidebar.append(BLANKCELL) # massage our links self.__d = {'rootdir': rootdir} self.__linkfixer.massage(p.sidebar, self.__d) # tweak p.sidebar.append(('http://www.python.org/', ''' <center> <img border="0" src="%(rootdir)s/images/PythonPoweredSmall.gif"></center>''' % self.__d)) p.sidebar.append(BLANKCELL) copyright = self.__parser.get('copyright', '1996-%d' % time.localtime()[0]) p.sidebar.append((None, '© ' + copyright)) p.sidebar.append((None, 'Barry A. Warsaw')) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of my web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks, cols=2) # kludge! for i in range(len(p.sidebar)-1, -1, -1): if p.sidebar[i] == 'Email Us': p.sidebar[i] = 'Email me' break
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, self.AUTHOR) f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # calculate the sidebar links, adding a few of our own self.__d = {'rootdir': rootdir} p.process_sidebar() p.sidebar.append(BLANKCELL) # it is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up p.sidebar.append(('%(rootdir)s', ''' <center> <img alt="" border="0" src="%(rootdir)s/pics/PythonPoweredSmall.gif"></center> ''' % self.__d)) self.__linkfixer.massage(p.sidebar, self.__d) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of our web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks) # calculate the random corner # XXX Should really do a list of the pics directory... NBANNERS = 64 i = whrandom.randint(0, NBANNERS - 1) s = "PyBanner%03d.gif" % i self.__d['banner'] = s self.__whichbanner = i
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self._parser = HTParser(file) self._linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None p.process_sidebar() self._linkfixer.massage(p.sidebar) Sidebar.__init__(self, p.sidebar)
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, 'x@y') f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # calculate the sidebar links, adding a few of our own self._d = {'rootdir': rootdir} p.process_sidebar() # remove "Email us" and use replacement del p.sidebar[-2:] p.sidebar.append('Contact') p.sidebar.append( ('http://lists.sourceforge.net/lists/listinfo/jython-users', 'Questions on Jython?<br>jython-users')) p.sidebar.append(BLANKCELL) # it is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up p.sidebar.append(('http://www.python.org/', ''' <center> <img border="0" src="%(rootdir)s/images/PythonPoweredSmall.gif"></center> ''' % self._d)) p.sidebar.append(BLANKCELL) p.sidebar.append(('http://sourceforge.net/', ''' <center> <img src="http://sourceforge.net/sflogo.php?group_id=12867" width="88" height="31" border="0" alt="SourceForge Logo"></center> ''' % self._d)) if self.webmaster: # webmaster -> jython-dev p.sidebar.append(BLANKCELL) p.sidebar.append(BLANKCELL) p.sidebar.append(('mailto:[email protected]', 'webmaster')) self.__linkfixer.massage(p.sidebar, self._d) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of our web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(self.sitelinks, self._d, aboves=1) Banner.__init__(self, self.sitelinks, cols=2)
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file,'x@y') f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # calculate the sidebar links, adding a few of our own self._d = {'rootdir': rootdir} p.process_sidebar() # remove "Email us" and use replacement del p.sidebar[-2:] p.sidebar.append('Contact') p.sidebar.append(('http://lists.sourceforge.net/lists/listinfo/jython-users','Questions on Jython?<br>jython-users')) p.sidebar.append(BLANKCELL) # it is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up p.sidebar.append(('http://www.python.org/', ''' <center> <img border="0" src="%(rootdir)s/images/PythonPoweredSmall.gif"></center> ''' % self._d)) p.sidebar.append(BLANKCELL) p.sidebar.append(('http://sourceforge.net/', ''' <center> <img src="http://sourceforge.net/sflogo.php?group_id=12867" width="88" height="31" border="0" alt="SourceForge Logo"></center> ''' % self._d)) if self.webmaster: # webmaster -> jython-dev p.sidebar.append(BLANKCELL) p.sidebar.append(BLANKCELL) p.sidebar.append(('mailto:[email protected]','webmaster')) self.__linkfixer.massage(p.sidebar, self._d) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of our web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(self.sitelinks, self._d, aboves=1) Banner.__init__(self, self.sitelinks, cols=2)
def _update_map(self, m): if m.name is None: # Data is not yet loaded return m.layers.get() sp = HorizontalPanel(Size=('100%', '100%')) sidebar = Sidebar() sidebar.setLayersCollection(m.layers) sp.add(sidebar) sp.setCellWidth(sidebar, '25%') map_ = Map(Size=('100%', '100%')) map_.set_map(m) sp.add(map_) self.setWidget(sp)
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) self.html = root + '.html' p = self.__parser = HTParser(file) f = self.__linkfixer = LinkFixer(self.html, rootdir, relthis) self.__body = None self.__cont = None # Calculate the sidebar links, adding a few of our own. self.__d = {'rootdir': rootdir} p.process_sidebar() p.sidebar = p.sidebar[:-2] self.make_assoc(p.sidebar) self.find_buttons(p.sidebar) self.test_buttons() self.collapse_links(p.sidebar, self.html) Sidebar.__init__(self, p.sidebar) Banner.__init__(self, ()) # Rollover script self.rollover = '''<script>
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, self.AUTHOR, self.EMAIL) f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # Calculate the sidebar links, adding a few of our own. self.__d = {'rootdir': rootdir} p.process_sidebar() p.sidebar.append(BLANKCELL) # It is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up. p.sidebar.append(('http://www.python.org/', '''\ <img class="side" alt="[Python Powered]" border="0" src="img/PythonPoweredSmall.png">''' % self.__d)) self.__linkfixer.massage(p.sidebar, self.__d) Sidebar.__init__(self, p.sidebar) copyright = self.__parser.get('copyright', '1999-%d' % time.localtime()[0]) p.sidebar.append((None, '© ' + copyright)) p.sidebar.append(('http://www.python.org/psf/', 'Python Software Foundation')) p.sidebar.append((None, '<hr>')) p.sidebar.append((None, '''<script type="text/javascript" \ src="http://www.altervista.org/js_tags/contatore.js"> </script> ''')) p.sidebar.append((None, '''last update''')) p.sidebar.append((None, time.asctime())) # Fix up our site links, no relthis because the site links are # relative to the root of our web pages. sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks) # kludge! for i in range(len(p.sidebar)-1, -1, -1): if p.sidebar[i] == 'Email Us': p.sidebar[i] = 'Email me' break
def __init__(self, file, rootdir, relthis): self.__body = None root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, '*****@*****.**') f = self.__linkfixer = LinkFixer(html, rootdir, relthis) p.process_sidebar() p.sidebar.append(BLANKCELL) # massage our links self.__d = {'rootdir': rootdir} self.__linkfixer.massage(p.sidebar, self.__d) # tweak p.sidebar.append((None, """\ <center><a href="http://www.python.org/"><img border=0 src="%(rootdir)s/images/PythonPoweredSmall.png"></a> <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=103" width="88" height="31" border="0" alt="SourceForge Logo"></a> """ % self.__d)) p.sidebar.append(BLANKCELL) years = COMMA.join([str(x) for x in range(1998, time.localtime()[0]+1)]) copyright = self.__parser.get('copyright', years) p.sidebar.append((None, '© ' + copyright + """\ <br>Free Software Foundation, Inc.<br> Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.<br> Please send comments on these pages to <a href="mailto:[email protected]"> <[email protected]></a>, other questions to <a href="mailto:[email protected]"><[email protected]></a>. """)) Sidebar.__init__(self, p.sidebar) # # fix up our site links, no relthis because the site links are # relative to the root of my web pages # sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks, cols=3)
def __init__(self, file, rootdir, relthis): root, ext = os.path.splitext(file) html = root + '.html' p = self.__parser = HTParser(file, self.AUTHOR, self.EMAIL) f = self.__linkfixer = LinkFixer(html, rootdir, relthis) self.__body = None self.__cont = None # Calculate the sidebar links, adding a few of our own. self.__d = {'rootdir': rootdir} p.process_sidebar() p.sidebar.append(BLANKCELL) # It is important not to have newlines between the img tag and the end # end center tags, otherwise layout gets messed up. p.sidebar.append(('http://www.python.org/', ''' <center> <img alt="[Python Powered]" border="0" src="PythonPoweredSmall.png"></center> ''' % self.__d)) self.__linkfixer.massage(p.sidebar, self.__d) Sidebar.__init__(self, p.sidebar) p.sidebar.append(BLANKCELL) copyright = self.__parser.get('copyright', '1999-%d' % time.localtime()[0]) p.sidebar.append((None, '© ' + copyright)) p.sidebar.append(('http://www.python.org/psf/', 'Python Software Foundation')) p.sidebar.append((None, '<hr>')) p.sidebar.append((file, '[page source]')) # Fix up our site links, no relthis because the site links are # relative to the root of our web pages. sitelink_fixer = LinkFixer(f.myurl(), rootdir) sitelink_fixer.massage(sitelinks, self.__d, aboves=1) Banner.__init__(self, sitelinks) # kludge! for i in range(len(p.sidebar)-1, -1, -1): if p.sidebar[i] == 'Email Us': p.sidebar[i] = 'Email me' break
class Game: def __init__(self): self.screenrect = get_screenrect() self.sidebar_width = 200 self.game_area = pygame.Rect( 0, 0, self.screenrect.width - self.sidebar_width, self.screenrect.height) self.ant_count = 4 self.ants = [] self.create_ants(self.ant_count) self.sidebar = Sidebar( pygame.Rect( self.screenrect.width - self.sidebar_width, 0, self.sidebar_width, self.screenrect.height, ), self, ) # right now a job is just a position # we want the ant to pick up the thing # and move it to a spot to drop it off self.jobs = [] self.working_jobs = [] self.done_jobs = [] self.drop_off = pygame.Rect(20, 20, 20, 20) self.create_jobs(self.ant_count) # self.create_single_job() def create_ants(self, amount): if amount == 0: return for _ in range(self.ant_count): rx = random.randint(0, self.game_area.width) ry = random.randint(0, self.game_area.height) new_ant = Ant(rx, ry, self) self.ants.append(new_ant) def create_single_job(self): self.create_jobs(1) x = self.jobs[0][0] + 80 y = self.jobs[0][1] + 80 ant = Ant(x, y, self) self.ants.append(ant) def get_jobs_in_range(self, pos, job_range): result = [] for job in self.jobs: d = utils.get_distance(pos, job) if d < job_range: result.append(job) return result def request_job(self, job): if job in self.jobs: self.jobs.remove(job) self.working_jobs.append(job) return True return False def job_completed(self, job): if job in self.working_jobs: self.working_jobs.remove(job) else: print("Job not found in working jobs!") print(job) print(self.working_jobs) self.done_jobs.append(job) def create_jobs(self, amount): padding = 40 job_cache = [] while len(self.jobs) < amount: rx = random.randint(padding, self.game_area.width - padding) ry = random.randint(padding, self.game_area.height - padding) if (rx, ry) not in job_cache: new_job = Job(utils.Point(rx, ry)) self.jobs.append(new_job) job_cache.append((rx, ry)) def update(self, dt): self.sidebar.update(dt) for ant in self.ants: ant.update(dt) def draw(self, canvas): self.sidebar.draw(canvas) pygame.draw.rect(canvas, (40, 0, 0), self.game_area) for ant in self.ants: ant.draw(canvas) for job in self.jobs: job.draw(canvas) for job in self.working_jobs: job.draw(canvas) pygame.draw.rect(canvas, (255, 255, 255), self.drop_off) def handle_event(self, event): pass
def get_sidebar(self): if self.__parser.get('wide-page', 'no').lower() == 'yes': return None return Sidebar.get_sidebar(self)
def get_sidebar(self): return Sidebar.get_sidebar(self)
import pygame.freetype pygame.init() screen_width = 1280 screen_height = 720 main_surface = pygame.display.set_mode((screen_width, screen_height)) text_container_height = 80 padding = 20 max_cont = (screen_height // (text_container_height + padding)) - 2 event_manager = EventManager() graph = Graph(event_manager, (0, 0), (screen_width, screen_height)) sidebar = Sidebar((300, screen_height), pygame.Color('#3a577b'), pygame.Color('#4d4d4d')) toggle_button = ToggleButton(event_manager, (95, 25), [screen_width - 220, 30], 'degrees', 'radians') def create_new_text_container(): if len(FunctionBox.all_function_boxes) - 1 != max_cont: place = len( FunctionBox.all_function_boxes) * (text_container_height + padding) FunctionBox(event_manager, (0, place), (300, text_container_height), 30) new_expr = Button(event_manager, (25, screen_height - 60), pygame.Color(0, 200, 0), 'ADD NEW',
def get_sidebar(self): if string.lower(self.__parser.get("wide-page", "no")) == "yes": return None return Sidebar.get_sidebar(self)