chgksuite 0.24.2__py3-none-any.whl → 0.25.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,7 +79,7 @@ class OpenquizExporter(BaseExporter):
79
79
  re_hs = re.search("\\[" + hs + ".+?: ?(.+)\\]", res, flags=re.DOTALL)
80
80
  if re_hs:
81
81
  res = res.replace(re_hs.group(0), re_hs.group(1))
82
- res = replace_no_break_spaces(res)
82
+ res = self._replace_no_break(res)
83
83
  res = res.replace("\u0301", "")
84
84
  return (res, images)
85
85
 
@@ -5,10 +5,11 @@ import re
5
5
  import toml
6
6
  from pptx import Presentation
7
7
  from pptx.dml.color import RGBColor
8
+ from pptx.enum.text import MSO_AUTO_SIZE, MSO_VERTICAL_ANCHOR
8
9
  from pptx.util import Inches as PptxInches
9
10
  from pptx.util import Pt as PptxPt
10
11
 
11
- from chgksuite.common import log_wrap, replace_escaped
12
+ from chgksuite.common import log_wrap, replace_escaped, tryint
12
13
  from chgksuite.composer.composer_common import BaseExporter, backtick_replace, parseimg
13
14
 
14
15
 
@@ -130,6 +131,14 @@ class PptxExporter(BaseExporter):
130
131
  s = s.strip()
131
132
  return s
132
133
 
134
+ def apply_vertical_alignment_if_needed(self, text_frame):
135
+ align = self.c["textbox"].get("vertical_align")
136
+ if align:
137
+ text_frame.auto_size = MSO_AUTO_SIZE.NONE
138
+ text_frame.margin_top = 0
139
+ text_frame.margin_bottom = 0
140
+ text_frame.vertical_anchor = getattr(MSO_VERTICAL_ANCHOR, align.upper())
141
+
133
142
  def _process_block(self, block):
134
143
  section = [x for x in block if x[0] == "section"]
135
144
  editor = [x for x in block if x[0] == "editor"]
@@ -139,6 +148,7 @@ class PptxExporter(BaseExporter):
139
148
  slide = self.prs.slides.add_slide(self.BLANK_SLIDE)
140
149
  textbox = self.get_textbox(slide)
141
150
  tf = textbox.text_frame
151
+ self.apply_vertical_alignment_if_needed(tf)
142
152
  tf.word_wrap = True
143
153
  text_for_size = (
144
154
  (self.recursive_join([x[1] for x in section]) or "")
@@ -150,10 +160,16 @@ class PptxExporter(BaseExporter):
150
160
  p = self.init_paragraph(tf, text=text_for_size)
151
161
  add_line_break = False
152
162
  if section:
153
- r = p.add_run()
154
- r.text = self._replace_no_break(self.pptx_process_text(section[0][1]))
155
- r.font.size = PptxPt(self.c["text_size_grid"]["section"])
156
- add_line_break = True
163
+ if self.c.get("tour_as_question_number"):
164
+ txt = self.pptx_process_text(section[0][1])
165
+ if self.c.get("tour_as_question_number") == "caps":
166
+ txt = txt.upper()
167
+ self.set_question_number(slide, number=txt)
168
+ else:
169
+ r = p.add_run()
170
+ r.text = self._replace_no_break(self.pptx_process_text(section[0][1]))
171
+ r.font.size = PptxPt(self.c["text_size_grid"]["section"])
172
+ add_line_break = True
157
173
  if editor:
158
174
  r = p.add_run()
159
175
  r.text = self._replace_no_break(
@@ -207,6 +223,8 @@ class PptxExporter(BaseExporter):
207
223
  qtf = qntextbox.text_frame
208
224
  qtf_p = self.init_paragraph(qtf)
209
225
  qtf_r = qtf_p.add_run()
226
+ if self.c.get("question_number_format") == "caps" and tryint(number):
227
+ number = f"ВОПРОС {number}"
210
228
  qtf_r.text = number
211
229
  if self.c["number_textbox"].get("color"):
212
230
  qtf_r.font.color.rgb = RGBColor(*self.c["number_textbox"]["color"])
@@ -336,10 +354,14 @@ class PptxExporter(BaseExporter):
336
354
  image, slide, allowbigimage=allowbigimage
337
355
  )
338
356
  tf = textbox.text_frame
357
+ self.apply_vertical_alignment_if_needed(tf)
339
358
  tf.word_wrap = True
340
359
  self.set_question_number(slide, self.number)
341
360
  question_text = self.pptx_process_text(q["question"], image=image)
342
- p = self.init_paragraph(tf, text=question_text, coeff=coeff)
361
+ if self.c.get("force_text_size_question"):
362
+ p = self.init_paragraph(tf, size=self.c["force_text_size_question"])
363
+ else:
364
+ p = self.init_paragraph(tf, text=question_text, coeff=coeff)
343
365
  self.pptx_format(question_text, p, tf, slide)
344
366
 
345
367
  def recursive_join(self, s):
@@ -352,13 +374,12 @@ class PptxExporter(BaseExporter):
352
374
  slide = self.prs.slides.add_slide(self.BLANK_SLIDE)
353
375
  textbox = self.get_textbox(slide)
354
376
  tf = textbox.text_frame
377
+ self.apply_vertical_alignment_if_needed(tf)
355
378
  tf.word_wrap = True
356
379
  if number is not None:
357
380
  self.set_question_number(slide, number)
358
381
  p = self.init_paragraph(tf, text=handout)
359
- self.pptx_format(
360
- self.pptx_process_text(handout), p, tf, slide
361
- )
382
+ self.pptx_format(self.pptx_process_text(handout), p, tf, slide)
362
383
 
363
384
  def process_question_text(self, q):
364
385
  image = self._get_image_from_4s(q["question"])
@@ -375,31 +396,19 @@ class PptxExporter(BaseExporter):
375
396
  if image and image["big"] and text_is_duplicated:
376
397
  self.add_slide_with_image(image, number=self.number)
377
398
 
378
- def process_question(self, q):
379
- if "number" not in q:
380
- self.qcount += 1
381
- if "setcounter" in q:
382
- self.qcount = int(q["setcounter"])
383
- self.number = str(self.qcount if "number" not in q else q["number"])
384
-
385
- if isinstance(q["question"], list):
386
- for i in range(len(q["question"][1])):
387
- qn = copy.deepcopy(q)
388
- qn["question"][1] = q["question"][1][: i + 1]
389
- self.process_question_text(qn)
399
+ def add_answer_slide(self, q):
400
+ slide = self.prs.slides.add_slide(self.BLANK_SLIDE)
401
+ if self.c.get("override_answer_caption"):
402
+ self.set_question_number(slide, self.c["override_answer_caption"])
390
403
  else:
391
- self.process_question_text(q)
392
-
393
- if self.c["add_plug"]:
394
- slide = self.prs.slides.add_slide(self.BLANK_SLIDE)
395
404
  self.set_question_number(slide, self.number)
396
- slide = self.prs.slides.add_slide(self.BLANK_SLIDE)
397
- self.set_question_number(slide, self.number)
398
405
  fields = ["answer"]
399
406
  if q.get("zachet") and self.c.get("add_zachet"):
400
407
  fields.append("zachet")
401
408
  if self.c["add_comment"] and "comment" in q:
402
409
  fields.append("comment")
410
+ if self.c["add_source"] and "source" in q:
411
+ fields.append("source")
403
412
  textbox = None
404
413
  coeff = 1
405
414
  for field in fields:
@@ -410,6 +419,7 @@ class PptxExporter(BaseExporter):
410
419
  if not textbox:
411
420
  textbox = self.get_textbox(slide)
412
421
  tf = textbox.text_frame
422
+ self.apply_vertical_alignment_if_needed(tf)
413
423
  tf.word_wrap = True
414
424
 
415
425
  text_for_size = self.recursive_join(
@@ -423,7 +433,18 @@ class PptxExporter(BaseExporter):
423
433
  text_for_size += "\n" + self.recursive_join(
424
434
  self.pptx_process_text(q["comment"])
425
435
  )
426
- p = self.init_paragraph(tf, text=text_for_size, coeff=coeff)
436
+ if q.get("source") and self.c.get("add_source"):
437
+ text_for_size += "\n" + self.recursive_join(
438
+ self.pptx_process_text(q["source"])
439
+ )
440
+ if q.get("author") and self.c.get("add_author"):
441
+ text_for_size += "\n" + self.recursive_join(
442
+ self.pptx_process_text(q["author"])
443
+ )
444
+ if self.c.get("force_text_size_answer"):
445
+ p = self.init_paragraph(tf, size=self.c["force_text_size_answer"])
446
+ else:
447
+ p = self.init_paragraph(tf, text=text_for_size, coeff=coeff)
427
448
  r = p.add_run()
428
449
  r.text = f"{self.get_label(q, 'answer')}: "
429
450
  r.font.bold = True
@@ -442,6 +463,38 @@ class PptxExporter(BaseExporter):
442
463
  r.text = f"\n{self.get_label(q, 'comment')}: "
443
464
  r.font.bold = True
444
465
  self.pptx_format(comment_text, p, tf, slide)
466
+ if self.c["add_source"] and "source" in q:
467
+ source_text = self.pptx_process_text(q["source"])
468
+ r = p.add_run()
469
+ r.text = f"\n{self.get_label(q, 'source')}: "
470
+ r.font.bold = True
471
+ self.pptx_format(source_text, p, tf, slide)
472
+ if self.c["add_author"] and "author" in q:
473
+ author_text = self.pptx_process_text(q["author"])
474
+ r = p.add_run()
475
+ r.text = f"\n{self.get_label(q, 'author')}: "
476
+ r.font.bold = True
477
+ self.pptx_format(author_text, p, tf, slide)
478
+
479
+ def process_question(self, q):
480
+ if "number" not in q:
481
+ self.qcount += 1
482
+ if "setcounter" in q:
483
+ self.qcount = int(q["setcounter"])
484
+ self.number = str(self.qcount if "number" not in q else q["number"])
485
+
486
+ if isinstance(q["question"], list):
487
+ for i in range(len(q["question"][1])):
488
+ qn = copy.deepcopy(q)
489
+ qn["question"][1] = q["question"][1][: i + 1]
490
+ self.process_question_text(qn)
491
+ else:
492
+ self.process_question_text(q)
493
+
494
+ if self.c["add_plug"]:
495
+ slide = self.prs.slides.add_slide(self.BLANK_SLIDE)
496
+ self.set_question_number(slide, self.number)
497
+ self.add_answer_slide(q)
445
498
 
446
499
  def determine_size(self, text, coeff=1):
447
500
  text = self.recursive_join(text)
@@ -451,13 +504,16 @@ class PptxExporter(BaseExporter):
451
504
  return element["size"]
452
505
  return self.c["text_size_grid"]["smallest"]
453
506
 
454
- def init_paragraph(self, text_frame, text=None, coeff=1):
507
+ def init_paragraph(self, text_frame, text=None, coeff=1, size=None):
455
508
  p = text_frame.paragraphs[0]
456
509
  p.font.name = self.c["font"]["name"]
457
- size = self.c["text_size_grid"]["default"]
458
- if text:
459
- size = self.determine_size(text, coeff=coeff)
460
- p.font.size = PptxPt(size)
510
+ if size:
511
+ _size = size
512
+ else:
513
+ _size = self.c["text_size_grid"]["default"]
514
+ if text:
515
+ _size = self.determine_size(text, coeff=coeff)
516
+ p.font.size = PptxPt(_size)
461
517
  return p
462
518
 
463
519
  def export(self, outfilename):
chgksuite/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.24.2"
1
+ __version__ = "0.25.0b1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chgksuite
3
- Version: 0.24.2
3
+ Version: 0.25.0b1
4
4
  Summary: A package for chgk automation
5
5
  Home-page: https://gitlab.com/peczony/chgksuite
6
6
  Author: Alexander Pecheny
@@ -6,7 +6,7 @@ chgksuite/parser.py,sha256=AVNeTUgv0aGHsxWunV_7bM4Ul2hbDslkzqg0dU49lic,37285
6
6
  chgksuite/parser_db.py,sha256=W1--OcDnx18mehH1T2ISHu3Saeq-9mqHo-xJopNySXI,11135
7
7
  chgksuite/trello.py,sha256=BG1Qb_W7Uu4o3Mfc_tK71ElU8ysdSplGlj_sAKfvUn4,14730
8
8
  chgksuite/typotools.py,sha256=Jdk65Wn_bXqpQtOT7PkBZyD2ZG1MBeeZFPMzcHEPkf4,12771
9
- chgksuite/version.py,sha256=UBF3OYTcBAovta3ux5ybxb0MZYAGpGO79WH_ax2NGeI,23
9
+ chgksuite/version.py,sha256=crnYq7xsXkDETbXgokTH1ogPed4GXjnXBZXwqXTvHpM,25
10
10
  chgksuite/vulture_whitelist.py,sha256=P__p_X0zt10ivddIf81uyxsobV14vFg8uS2lt4foYpc,3582
11
11
  chgksuite/composer/__init__.py,sha256=MAOVZIYXmZmD6nNQSo9DueV6b5RgxF7_HGeLvsAhMJs,6490
12
12
  chgksuite/composer/chgksuite_parser.py,sha256=MFcLUWbccMqo3OYEuaAIA0loEvWM_PNS9vR7c1z_c60,8843
@@ -15,8 +15,8 @@ chgksuite/composer/db.py,sha256=71cINE_V8s6YidvqpmBmmlWbcXraUEGZA1xpVFAUENw,8173
15
15
  chgksuite/composer/docx.py,sha256=5MASXACM-ztWrr3VdO8HZ-W-hWWQ5TY1jXMsCQIufGc,18346
16
16
  chgksuite/composer/latex.py,sha256=WtLdUICxeX4_5vHEJRF0YhFLpTsOUwBkQFunQS488FA,9248
17
17
  chgksuite/composer/lj.py,sha256=nty3Zs3N1H0gNK378U04aAHo71_5cABhCM1Mm9jiUEA,15213
18
- chgksuite/composer/openquiz.py,sha256=CWGxb_cPG2Qh3dQ3hu0pS5fOfhKc8klZuO38Lo9hUF8,7020
19
- chgksuite/composer/pptx.py,sha256=lmLld5CCNfndmLwWz2rRqZFyPIUxl0Dvk6wO1jW_c5s,19116
18
+ chgksuite/composer/openquiz.py,sha256=4adZewvRXpZhKrh9H4epKoMMDhmki9US55-Q0LcpZW0,7019
19
+ chgksuite/composer/pptx.py,sha256=v3F8ahHOIsiBJ6-ggoT003MVcodAN05KKArNQv6zi48,21778
20
20
  chgksuite/composer/reddit.py,sha256=-Eg4CqMHhyGGfCteVwdQdtE1pfUXQ42XcP5OYUrBXmo,3878
21
21
  chgksuite/composer/stats.py,sha256=GbraSrjaZ8Mc2URs5aGAsI4ekboAKzlJJOqsbe96ELA,3995
22
22
  chgksuite/composer/telegram.py,sha256=H65LS79JZ3aCcqeq_SrnUU4E4yro1f-EZxCM3IrIyyQ,46526
@@ -45,9 +45,9 @@ chgksuite/resources/template.docx,sha256=Do29TAsg3YbH0rRSaXhVzKEoh4pwXkklW_idWA3
45
45
  chgksuite/resources/template.pptx,sha256=hEFWqE-yYpwZ8ejrMCJIPEyoMT3eDqaqtiEeQ7I4fyk,29777
46
46
  chgksuite/resources/template_shorin.pptx,sha256=hEFWqE-yYpwZ8ejrMCJIPEyoMT3eDqaqtiEeQ7I4fyk,29777
47
47
  chgksuite/resources/trello.json,sha256=M5Q9JR-AAJF1u16YtNAxDX-7c7VoVTXuq4POTqYvq8o,555
48
- chgksuite-0.24.2.dist-info/licenses/LICENSE,sha256=_a1yfntuPmctLsuiE_08xMSORuCfGS8X5hQph2U_PUw,1081
49
- chgksuite-0.24.2.dist-info/METADATA,sha256=EfR9tuFPhFwdMjYtaExqh1P-CuoXBPSuU-_7avOAvYs,1294
50
- chgksuite-0.24.2.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
51
- chgksuite-0.24.2.dist-info/entry_points.txt,sha256=lqjX6ULQZGDt0rgouTXBuwEPiwKkDQkSiNsT877A_Jg,54
52
- chgksuite-0.24.2.dist-info/top_level.txt,sha256=cSWiRBOGZW9nIO6Rv1IrEfwPgV2ZWs87QV9wPXeBGqM,10
53
- chgksuite-0.24.2.dist-info/RECORD,,
48
+ chgksuite-0.25.0b1.dist-info/licenses/LICENSE,sha256=_a1yfntuPmctLsuiE_08xMSORuCfGS8X5hQph2U_PUw,1081
49
+ chgksuite-0.25.0b1.dist-info/METADATA,sha256=tkwtbotcMrvt0ZchMgV8CH5xtMnhpJ0puy299SDq2zA,1296
50
+ chgksuite-0.25.0b1.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
51
+ chgksuite-0.25.0b1.dist-info/entry_points.txt,sha256=lqjX6ULQZGDt0rgouTXBuwEPiwKkDQkSiNsT877A_Jg,54
52
+ chgksuite-0.25.0b1.dist-info/top_level.txt,sha256=cSWiRBOGZW9nIO6Rv1IrEfwPgV2ZWs87QV9wPXeBGqM,10
53
+ chgksuite-0.25.0b1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.0)
2
+ Generator: setuptools (79.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5