martastain

cgtool plugin example

Mar 15th, 2021
1,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.38 KB | None | 0 0
  1. import os
  2. import random
  3. from nxcg.plugin import NXCGPlugin
  4.  
  5.  
  6. crawl_default = "USD  1.12  |  EUR/IDR  15927.71  |  EUR/BGN  1.96  |  EUR/ISK  133.60  |  EUR/ILS  4.03  |  EUR/GBP  0.86  |  EUR/DKK  7.47  |  EUR/CAD  1.50  |  EUR/MX"
  7.  
  8. class Plugin(NXCGPlugin):
  9.     def on_init(self):
  10.         self.cg.colors.update({
  11.                 "ticker-bkg" : "#ecececcc",
  12.                 "ticker-fg" :  "#0f0f0fff",
  13.                 "crawl-bkg" :  "#1a1a1acc",
  14.                 "crawl-fg"  :  "#c0c0c0ff",
  15.             })
  16.  
  17.     def ticker_mask(self):
  18.         self.cg.set_color("#000000")
  19.         self.cg.rect(0, 0, 1920, 1080)
  20.         self.cg.set_color("#ffffff")
  21.         self.cg.rect(192, 990, 1390, 36)
  22.  
  23.     def ticker_bkg(self):
  24.         self.cg.set_color("ticker-bkg")
  25.         self.cg.rect(192, 990, 1390, 36)
  26.  
  27.     def ticker(self, **kwargs):
  28.         text = kwargs.get("text", "Lorem ipsum you should providum textum attributum")
  29.         text = text.upper()
  30.         self.cg.text(
  31.                 text,
  32.                 font="TeX Gyre Heros Cn Bold 18",
  33.                 pos=(210, 990),
  34.                 color="ticker-fg"
  35.             )
  36.  
  37.     def crawl_mask(self):
  38.         self.cg.set_color("#000000")
  39.         self.cg.rect(0, 0, 1920, 1080)
  40.         self.cg.set_color("#ffffff")
  41.         self.cg.rect(192, 954, 1390, 36)
  42.  
  43.     def crawl_bkg(self):
  44.         self.cg.set_color("crawl-bkg")
  45.         self.cg.rect(192, 954, 1390, 36)
  46.  
  47.     def crawl(self, **kwargs):
  48.         text = kwargs.get("text", crawl_default)
  49.         text = text.upper()
  50.  
  51.         w, h = self.cg.text(
  52.                 text,
  53.                 font="TeX Gyre Heros Cn Bold 18",
  54.                 render=False
  55.             )
  56.  
  57.         self.cg.new(w, 1080)
  58.         self.cg.text(
  59.                 text,
  60.                 font="TeX Gyre Heros Cn Bold 18",
  61.                 color="crawl-fg",
  62.                 pos=(0, 954)
  63.             )
  64.  
  65.     def music_label(self, **kwargs):
  66.         font_title = "Roboto Light 38"
  67.         font_artist = "Roboto Light 30"
  68.         title=kwargs.get("title", "")
  69.         artist=kwargs.get("artist", "")
  70.         title_w, h = self.cg.text(
  71.             title,
  72.             font=font_title,
  73.             render=False
  74.             )
  75.         artist_w, h = self.cg.text(
  76.             artist,
  77.             font=font_artist,
  78.             render=False
  79.             )
  80.         mwidth = max(title_w, artist_w) + self.cg.safe.l + 40
  81.  
  82.         points = [
  83.                 [192 , self.cg.safe.b - 95],
  84.                 [mwidth - 10, self.cg.safe.b - 100],
  85.                 [mwidth + 15, self.cg.safe.b - 245],
  86.                 [170, self.cg.safe.b - 260]
  87.             ]
  88.         self.cg.set_color("black glass 75")
  89.         self.cg.polygon(*points)
  90.  
  91.         title_w, h = self.cg.text(
  92.                 title,
  93.                 font=font_title,
  94.                 color="gold",
  95.                 pos=(210, self.cg.safe.b - 230)
  96.             )
  97.         artist_w, h = self.cg.text(
  98.                 artist,
  99.                 font=font_artist,
  100.                 color="#b0c7e8",
  101.                 pos=(210, self.cg.safe.b - 165)
  102.             )
  103.  
  104.     def rotator(self, source_path, **kwargs):
  105.         source = open(os.path.join(self.cg.app_dir, source_path)).read()
  106.         source = source.split("\n")
  107.         source = [f.strip() for f in source if f.strip()]
  108.         text = random.choice(source)
  109.  
  110.         w, h = self.cg.text(
  111.                 kwargs.get("header").upper(),
  112.                 font="Roboto Light 72",
  113.                 color="gold",
  114.                 pos=(190, 190),
  115.                 width=1000,
  116.                 render=False
  117.             )
  118.  
  119.         self.cg.set_color("black glass 65")
  120.         self.cg.rect(192, 170, w+40, h+40)
  121.         self.cg.text_render(212, 190)
  122.  
  123.  
  124.         w, h = self.cg.text(
  125.                 text,
  126.                 font="Roboto Light 58",
  127.                 color="#b0c7e8",
  128.                 width=1400,
  129.                 render=False
  130.             )
  131.  
  132.         self.cg.set_color("black glass 65")
  133.         self.cg.rect(192, 360, w+40, h+40)
  134.         self.cg.text_render(212, 380)
  135. ~                                                                                                                                                                                                                                                                                          
  136. ~                                                                          
Advertisement
Add Comment
Please, Sign In to add comment