/
new_grid_image.py
executable file
·1710 lines (1403 loc) · 46.7 KB
/
new_grid_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import os, glob, re, socket
import time
import math
from gimpfu import *
import rwkos
import pdb as Pdb
import vibrations_gimp
from gimp_copy_utils import *
Linux = rwkos.amiLinux()
##graph_path = '/home/ryan/siue/classes/graph_paper.png'
## classes_base = '/home/ryan/siue/classes'
## keys = ['452','mechatronics','482','484','356','mobile_robotics']
## nums = ['452','458','482','484','356','492']
## course_num_dict = dict(zip(keys, nums))
## bases = ['452/lectures', 'mechatronics/2009/lectures', '482/2009/lectures', \
## '484/lectures', '356/Fall_2009/lectures', \
## 'mobile_robotics/2009/lectures']
## base_dict = dict(zip(keys, bases))
## curdir = os.getcwd()
## log_msg('curdir = %s' % curdir)
import pygimp_lecture_utils
from pygimp_lecture_utils import set_lecture_path, get_course_number, \
get_path_from_pkl, graph_path, get_date_for_slide, \
save_as, save_as_jpg, \
find_graph_ind, find_notes_layer, get_notes_layer_slide_num, \
get_slide_num_filename, \
log_msg, open_pickle, save_pickle, \
folder_from_pickle, \
save_all_slides, \
close_all, _save_and_close, \
my_save_2010, _really_save, \
slide_num_from_path
import pygimp_lecture_utils as PGLU
## def get_course_key_from_curdir():
## curdir = os.getcwd()
## #log_msg('curdir = %s' % curdir)
## for key in keys:
## if curdir.find('/' + key +'/') > -1:
## return key
## log_msg('could not find any of %s \n' % keys)
## log_msg('in curdir %s' % curdir)
## def get_lecture_base():
## key = get_course_key_from_curdir()
## if key:
## base = base_dict[key]
## lecture_base = os.path.join(classes_base, base)
## return lecture_base
## def get_course_number():
## key = get_course_key_from_curdir()
## if key:
## cn = course_num_dict[key]
## return cn
#lb = get_lecture_base()
#log_msg('lecture_base = %s' % lb)
## def get_cur_date_str():
## date_str = time.strftime('%m_%d_%y')
## return date_str
## def get_date_from_path():
## curdir = os.getcwd()
## p = re.compile('/lectures/(\d+_\d+_\d+)')
## q = p.search(curdir)
## if q:
## #q.group(1).split('_',2)
## return q.group(1)
## else:
## return None
## def get_date_str():
## date_str = get_date_from_path()
## if not date_str:
## date_str = get_cur_date_str()
## return date_str
## def get_date_folder():
## date_str = get_date_str()
## lecture_base = get_lecture_base()
## folder = os.path.join(lecture_base, date_str)
## return folder
def _feather_helper(feather_radius=0):
if feather_radius == None:
return False, 0.0
return True, feather_radius
def _radius_helper(radius):
if isinstance(radius, tuple):
return radius
return radius, radius
def select_by_color(drawable, color, threshold = 0,
operation = 2,
antialias = False, feather_radius = 0,
sample_merged = False, select_transparent = False,
select_criterion = 0, \
feater_radius=0):
print('a1')
if drawable == None:
drawable = _active_drawable()
print('a2')
do_feather, feather_radius = _feather_helper(feater_radius)
print('a3')
feather_radius_x, feather_radius_y = _radius_helper(feather_radius)
print('a4')
pdb.gimp_by_color_select_full(drawable, color, threshold, operation,
antialias, do_feather, feather_radius_x,
feather_radius_y, sample_merged,
select_transparent, select_criterion)
print('a5')
def activate_notes_layer(img, name="Notes Layer"):
ind = find_graph_ind(img, name=name)
img.active_layer = img.layers[ind]
def move_resize_window():#timg, tdrawable):
print('hello')
if Linux:
## import subprocess
## p = subprocess.Popen(['xdotool','getactivewindow'], \
## stdout=subprocess.PIPE,stderr=subprocess.PIPE)
## output, errors = p.communicate()
## win = output.strip()#get id of active window
## #this was important on my old laptop where I didn't want the image
## #maximized
## ## movecmd = 'xdotool windowmove %s 0 0' % win
## ## os.system(movecmd)
## ## #sizecmd = 'xdotool windowsize %s 1024 700' % win
## ## sizecmd = 'xdotool windowsize %s 1280 1000' % win
## ## os.system(sizecmd)
#maxcmd = "xdotool key ctrl+super+Up"
hostname = socket.gethostname()
print('hostname = ' + str(hostname))
if hostname in ['ryan-USB','hpdv4','ryan-Latitude-D820']:
maxcmd = "xdotool key alt+F11"
os.system(maxcmd)
ecmd = "xdotool key ctrl+shift+E"
#time.sleep(0.1)
time.sleep(0.15)
os.system(ecmd)
register(
"move_resize_window",
"Move and resize window for class lectures",
"Move and resize window for class lectures",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Move and Resize",
"",
[],
[],
move_resize_window,
menu="<Toolbox>/Xtns/Languages/Ryan")
def new_grid_image(pat=None, footer='', footer_x=1920):#timg, tdrawable):
width = 2000
height = 1300
header_x = 1780
footer_y = height - 80
img = gimp.Image(width, height, RGB)
white_layer = gimp.Layer(img, "White Layer", width, height, \
RGB_IMAGE, 100, NORMAL_MODE)
pdb.gimp_drawable_fill(white_layer, WHITE_FILL)
img.add_layer(white_layer)
graph_layer = pdb.gimp_file_load_layer(img, graph_path)
img.add_layer(graph_layer)
new_name, slide_num = get_slide_num_filename(pat=pat)
notes_name = "Notes Layer %0.4d" % int(slide_num)
trans_layer = gimp.Layer(img, notes_name, width, height, \
RGBA_IMAGE, 100, NORMAL_MODE)
pdb.gimp_drawable_fill(trans_layer, TRANSPARENT_FILL)
img.add_layer(trans_layer)
img.active_layer = trans_layer
date_str = get_date_for_slide()
date_str = date_str.replace('_','/')
pdb.gimp_context_set_foreground((0,0,0))
cn = get_course_number()
if cn == 106:
fmt = "IME %s\n%s"
else:
print('cn = %s' % cn)
print('type(cn) = %s' % type(cn))
fmt = "ME %s\n%s"
rhead = fmt % (cn, date_str)
font_size_header_footer = 40
text_layer = pdb.gimp_text_fontname(img, trans_layer, header_x, 10, \
rhead , \
0, True, font_size_header_footer, \
1, "Sans")
pdb.gimp_floating_sel_anchor(text_layer)
text_layer2 = pdb.gimp_text_fontname(img, trans_layer, footer_x, footer_y, \
footer+str(slide_num), \
0, True, font_size_header_footer, \
1, "Sans")
pdb.gimp_floating_sel_anchor(text_layer2)
#pdb.gimp_selection_all(img)
#pdb.gimp_edit_clear(trans_layer)
out1 = gimp.Display(img)
gimp.displays_flush()
pdb.gimp_image_clean_all(img)
title_in = img.filename
#log_msg('title_in=%s' % title_in)
#move_resize_window()
return img
## register("new_grid_image",
## "A new image for class lectures",
## "A new image for class lectures",
## "Ryan Krauss",
## "Ryan Krauss",
## "2009",
## "<Toolbox>/Xtns/Languages/Ryan/2009/_New Grid Image",
## "",#RGB*, GRAY*",
## [],
## [(PF_IMAGE, 'img', 'the new image')],
## new_grid_image)
register("set_lecture_path", \
"Set the path for todays lectures", \
"Set the path for todays lectures saving it in a pkl", \
"Ryan Krauss", \
"Ryan Krauss", \
"2009", \
"Set Lecture Path", \
"", \
[], \
[], \
set_lecture_path, \
menu="<Toolbox>/Xtns/Languages/Ryan/2009")
import tkFileDialog
filetypes = [('png files', '*.png'), ('jpg files', '*.jpg'),\
('all files', '.*')]
jpgtypes = [('jpg files', '*.jpg'), ('png files', '*.png'),\
('all files', '.*')]
xcftypes = [('xcf file', '*.xcf')]
import tk_simple_dialog
import tk_msg_dialog
#?bob = tkSimpleDialog.askinteger?
#?tkSimpleDialog.askinteger?
def get_quiz_solution_number():
myfolder = get_path_from_pkl()
mypaths = rwkos.Find_in_top_and_sub_dirs(myfolder, 'quiz_*')
qn = None
if mypaths:
path1 = mypaths[0]
folder, fn1 = os.path.split(path1)
pat = re.compile('quiz_([0-9]+)')
q = pat.search(fn1)
if q:
qn_str = q.group(1)
qn = int(qn_str)
if qn is None:
W = tk_simple_dialog.myWindow()
qn_str = W.var.get()
qn = int(qn_str)
## log_msg('qn_str = %s' % qn_str)
## log_msg('type(qn_str) = %s' % type(qn_str))
## log_msg('qn = %s' % qn)
## log_msg('type(qn) = %s' % type(qn))
return qn
def get_quiz_solution_pattern(qn=None):
if qn is None:
qn = get_quiz_solution_number()
pat = 'quiz_%0.2d_solution' % qn + '_%0.4d.jpg'
return pat
def get_quiz_solution_filename():
pat = get_quiz_solution_pattern()
folder = get_path_from_pkl()
new_ind = rwkos.get_new_file_number(pat, folder)
new_name = pat % new_ind
return new_name#, new_ind
def new_quiz_solution_page():
#how to get the quiz number?
#new_grid_image(pat=pat, footer=footer)
qn = get_quiz_solution_number()
footer = 'Quiz %d Solution ' % qn
pat = get_quiz_solution_pattern(qn)
new_grid_image(pat=pat, footer=footer, footer_x=1500)
register(
"new_quiz_solution_page",
"A new image for quiz solutions",
"A new image for quiz solutions",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"New _Quiz Solution Page",
"",#RGB*, GRAY*",
[],
[],
new_quiz_solution_page,
menu="<Toolbox>/Xtns/Languages/Ryan/2009")
def red_brush():
pdb.gimp_context_set_foreground((255,0,0))
register(
"red_brush",
"Set brush foreground to red",
"Set brush foreground to red",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Red Brush",
"",#RGB*, GRAY*",
[],
[],
red_brush,
menu="<Toolbox>/Lecture/Brushes")
def black_brush():
pdb.gimp_context_set_foreground((0,0,0))
register(
"black_brush",
"Set brush foreground to black",
"Set brush foreground to black",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Black Brush",
"",#RGB*, GRAY*",
[],
[],
black_brush,
menu="<Toolbox>/Lecture/Brushes")
def blue_brush():
pdb.gimp_context_set_foreground((0,0,255))
register(
"blue_brush",
"Set brush foreground to blue",
"Set brush foreground to blue",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Blue Brush",
"",#RGB*, GRAY*",
[],
[],
blue_brush,
menu="<Toolbox>/Lecture/Brushes")
def find_if_open(imgname):
#Pdb.set_trace()
mylist = gimp.image_list()
for img in mylist:
curname = img.name
if curname == imgname:
return img
#this line would be executed only if imgname was never found
return None
def list_images():
#Pdb.set_trace()
mylist = gimp.image_list()
for item in mylist:
print('item = '+str(item))
register(
"list_images",
"Set brush foreground to blue",
"Set brush foreground to blue",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"List Images",
"",#RGB*, GRAY*",
[],
[],
list_images,
menu="<Toolbox>/Xtns/Languages/Ryan/2009")
def green_brush():
pdb.gimp_context_set_foreground((0,160,0))
register(
"green_brush",
"Set brush foreground to green",
"Set brush foreground to green",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Green Brush",
"",#RGB*, GRAY*",
[],
[],
green_brush,
menu="<Toolbox>/Lecture/Brushes")
def get_brush():
mystr = pdb.gimp_context_get_brush()
print('cur brush=' + mystr)
myfloat = pdb.gimp_context_get_brush_size()
print('size=%0.5g' % myfloat)
register(
"get_brush",
"Set brush foreground to green",
"Set brush foreground to green",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Get Brush",
"",
[],
[],
get_brush,
menu="<Toolbox>/Lecture/Brushes")
def set_brush():
pdb.gimp_context_set_brush('2. Hardness 025')
pdb.gimp_context_set_brush_size(10)
register(
"set_brush",
"Set my lecture brush",
"Set my lecture brush",
"Ryan Krauss",
"Ryan Krauss",
"2013",
"Set Brush",
"",#RGB*, GRAY*",
[],
[],
set_brush,
menu="<Toolbox>/Lecture/Brushes")
# examples:
def open_it(initialdir=None):
filename = tkFileDialog.askopenfilename()
return filename
def open_xcf(initialdir=None, initialfile=None):
filename = tkFileDialog.askopenfilename(initialfile=initialfile,
initialdir=initialdir,
filetypes=xcftypes)
return filename
def open_jpg(initialdir=None, initialfile=None):
filename = tkFileDialog.askopenfilename(initialfile=initialfile,
initialdir=initialdir,
filetypes=jpgtypes)
return filename
def open_image(initialdir=None, initialfile=None):
filename = tkFileDialog.askopenfilename(initialfile=initialfile,
initialdir=initialdir,
filetypes=filetypes)
return filename
def save_it():
filename = tkFileDialog.askopenfilename()
return filename
def my_save(img, drawable):
ind = find_graph_ind(img)
if ind:
img.layers[ind].visible = False
folder = get_path_from_pkl()
myint = get_notes_layer_slide_num(img)
new_name, slide_num = get_slide_num_filename(myint=myint)
filename = save_as(initialdir=folder, initialfile=new_name)
#log_msg('filename = ' + filename)
if filename:
pne, ext = os.path.splitext(filename)
xcf_path = pne+'.xcf'
pdb.gimp_xcf_save(1, img, drawable, xcf_path, xcf_path)
flat_layer = pdb.gimp_image_flatten(img)
#pdb.gimp_file_save(img, flat_layer, filename, filename)
pdb.file_png_save(img, flat_layer, filename, filename, \
0, 0, 0, 0, 0, \
1, 1)
pdb.gimp_image_clean_all(img)
register(
"my_save",
"Save grid image with grid not visible",
"Save grid image with grid not visible",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Save Grid Image",
"RGB*, GRAY*",
[],
[],
my_save,
menu="<Image>/Filters/Ryan/2009")
def my_save2(img, drawable):
#log_msg('in my_save2')
ind = find_graph_ind(img)
if ind:
img.layers[ind].visible = False
else:
log_msg('did not find a graph ind')
folder = get_path_from_pkl()
log_msg('folder='+str(folder))
myint = get_notes_layer_slide_num(img)
log_msg('myint='+str(myint))
title_in = img.filename
log_msg('title_in = %s' % title_in)
new_name = None
if title_in:
folder_in, name_in = os.path.split(title_in)
fno, ext = os.path.splitext(name_in)
name_in = fno + '.png'
#log_msg('name_in = %s' % name_in)
#log_msg('folder_in = %s' % folder_in)
cn = get_course_number()
my_ind = name_in.find('ME'+cn)
#log_msg('my_ind = %s' % my_ind)
if my_ind == 0:
#log_msg('in the good case')
folder = folder_in
new_name = name_in
#log_msg('new_name = %s' % new_name)
if new_name is None:
new_name, slide_num = get_slide_num_filename(myint=myint)
filename = save_as(initialdir=folder, initialfile=new_name)
log_msg('filename = ' + filename)
if filename:
pne, ext = os.path.splitext(filename)
xcf_path = pne+'.xcf'
pdb.gimp_selection_all(img)
pdb.gimp_edit_copy_visible(img)
img2 = pdb.gimp_edit_paste_as_new()
pdb.gimp_xcf_save(1, img, drawable, xcf_path, xcf_path)
folder, xcf_name = os.path.split(xcf_path)
xcf_path = xcf_path.encode()
xcf_name = xcf_name.encode()
#log_msg('xcf_name='+xcf_name)
#log_msg('type(img.filename)=%s' % type(img.filename))
#log_msg('type(xcf_name)=%s' % type(xcf_name))
img.filename = xcf_path
#pdb.gimp_file_save(img, drawable, xcf_path, xcf_path)
flat_layer = pdb.gimp_image_flatten(img2)
#gimp.Display(img2)
pdb.gimp_file_save(img2, flat_layer, filename, filename)
pdb.gimp_image_delete(img2)
if ind:
img.layers[ind].visible = True
pdb.gimp_image_clean_all(img)
gimp.displays_flush()
log_msg('after clean all')
register(
"my_save2",
"Save grid image with grid not visible",
"Save grid image with grid not visible",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Save Grid Image 2",
"RGB*, GRAY*",
[],
[],
my_save2,
menu="<Image>/Filters/Ryan/2009")
def raise_img(img):
#gimp.Display(img)#<-- this seems to re-open the image or create a
#new Display for it
gimp.displays_flush()
#time.sleep(0.5)
#move_resize_window()#timg, tdrawable)
def _open_by_int(next_int):
new_name, new_ind = get_slide_num_filename(myint=next_int)
print('new_name = ' + str(new_name))
path_no_ext, ext = os.path.splitext(new_name)
xcf_name = path_no_ext +'.xcf'
img = find_if_open(xcf_name)
if img is None:
my_open(filename=xcf_name)
else:
raise_img(img)
#pdb.gimp_selection_none(img)
def open_next(img, drawable):
#This doesn't work perfectly. It seems like it opens pngs instead
#of xcfs (which makes sense if you look at get_slide_num_filename)
myint = get_notes_layer_slide_num(img)
next_int = myint + 1
_open_by_int(next_int)
register(
"open_next",
"Open next image",
"Open next image",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Open Next Image",
"RGB*, GRAY*",
[],
[],
open_next,
menu="<Image>/Filters/Ryan/2009")
def open_previous(img, drawable):
#This doesn't work perfectly. It seems like it opens pngs instead
#of xcfs (which makes sense if you look at get_slide_num_filename)
myint = get_notes_layer_slide_num(img)
prev_int = myint - 1
_open_by_int(prev_int)
register(
"open_previous",
"Open previous image",
"Open previous image",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Open Previous Image",
"RGB*, GRAY*",
[],
[],
open_previous,
menu="<Image>/Filters/Ryan/2009")
def my_close(img, drawable):
#pdb.gimp_display_delete(gimp._id2display(1))
pdb.gimp_display_delete(img)
register(
"my_close",
"Close image",
"Close image",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Close Image",
"RGB*, GRAY*",
[],
[],
my_close,
menu="<Image>/Filters/Ryan/2009")
def save_quiz(img, drawable):
folder = get_path_from_pkl()
new_name = get_quiz_solution_filename()
ind = find_graph_ind(img)
if ind:
img.layers[ind].visible = False
title_in = img.filename
#log_msg('title_in = %s' % title_in)
if title_in:
cur_folder, cur_name = os.path.split(title_in)
if cur_name.find('quiz_') == 0:
new_name = cur_name
folder = cur_folder
filename = save_as_jpg(initialdir=folder, initialfile=new_name)
filename = filename.encode()
#log_msg('filename = ' + filename)
if filename:
flat_layer = pdb.gimp_image_flatten(img)
pdb.gimp_file_save(img, flat_layer, filename, filename)
img.filename = filename
pdb.gimp_image_clean_all(img)
gimp.displays_flush()
register(
"save_quiz",
"Save quiz image",
"Save quiz image",
"Ryan Krauss",
"Ryan Krauss",
"2009",
"Save _Quiz Image",
"RGB*, GRAY*",
[],
[],
save_quiz,
menu="<Image>/Filters/Ryan/2009")
def batch_xcf_to_png(file_pattern):
#log_msg('pattern='+file_pattern)
file_list=glob.glob(file_pattern)
file_list.sort()
for filename in file_list:
#log_msg('filename='+filename)
img = pdb.gimp_file_load(filename, filename)
ind = find_graph_ind(img)
#log_msg('ind='+str(ind))
if ind:
img.layers[ind].visible = False
pne, ext = os.path.splitext(filename)
png_path = pne+'.png'
flat_layer = pdb.gimp_image_flatten(img)
log_msg('%s --> %s' % (filename, png_path))
pdb.gimp_file_save(img, flat_layer, png_path, png_path)
## pdb.file_png_save(img, flat_layer, png_path, png_path, \
## 0, 9, 0, 0, 0, \
## 0, 0)
#pdb.gimp_file_save(image, drawable, filename, filename)
pdb.gimp_image_delete(img)
register(
"batch_xcf_to_png", "", "", "", "", "",
"Batch XCF to PNG", "",
[
(PF_STRING, "file_pattern", "file_pattern", "*.xcf"),
],
[],
batch_xcf_to_png,
menu="<Toolbox>/Xtns/Languages/Ryan")
def my_open(dialog_func=open_xcf, filename=None):
folder = get_path_from_pkl()
if filename is None:
filename = dialog_func(initialdir=folder)
#img = pdb.gimp_file_load(1, filename, filename)
img = pdb.gimp_file_load(filename, filename)
ind = find_graph_ind(img)
title_in = img.filename
#log_msg('title_in=%s' % title_in)
if ind:
img.layers[ind].visible = True
ind2 = find_notes_layer(img)
if ind2:
pdb.gimp_image_set_active_layer(img, img.layers[ind2])
pdb.gimp_image_clean_all(img)
#Set the current_slide if it is in the current lecture
mydict = open_pickle()
full_pat = os.path.join(mydict['lecture_path'], mydict['search_pat'])
if filename.find(full_pat) == 0:
cur_slide = slide_num_from_path(filename)
mydict['current_slide'] = cur_slide
save_pickle(mydict)
out2 = gimp.Display(img)
gimp.displays_flush()
#time.sleep(0.5)
#move_resize_window()#timg, tdrawable)
####pdb.gimp_selection_none(img)
## register(
## "my_open",
## "Open grid image making grid visible",
## "Open grid image making grid visible and setting Notes layer active",
## "Ryan Krauss",
## "Ryan Krauss",
## "2009",
## "<Image>/Filters/Ryan/_Open Grid Image",
## "RGB*, GRAY*",
## [],
## [],
## my_open)
register(
"my_open", "", "", "", "", "",
"Open Grid Image", "",
[],
[],
my_open,
menu="<Toolbox>/Lecture",
)
def open_quiz():
my_open(dialog_func=open_jpg)
register(
"open_quiz", "", "", "", "", "",
"Open Q_uiz Image", "",
[],
[],
open_quiz,
menu="<Toolbox>/Xtns/Languages/Ryan")
#############################################
#
# Fall 2010 Versions
#
#############################################
## def save_all_slides():
## img_list = gimp.image_list()
## N = len(img_list)
## print('img_list = ' + str(img_list))
## #Pdb.set_trace()
## mydict = open_pickle()
## full_pat = os.path.join(mydict['lecture_path'], mydict['search_pat'])
## success = True
## for img in img_list:
## curname = img.filename
## if curname and curname.find(full_pat) == 0:
## if pdb.gimp_image_is_dirty(img):
## out = my_save_2010(img)
## if not out:
## #if any one save fails, success is False
## success = False
## else:
## print('not saving clean image: ' + curname)
## return success
## def close_all(N=10):
## if gimp.image_list():
## for i in range(N):
## disp = gimp._id2display(i)
## if disp is not None:
## #Pdb.set_trace()
## try:
## pdb.gimp_display_delete(disp)
## except:
## print('problem deleting disp # ' + str(i))
def build_slide_path(mydict):
pat = mydict['pat']
filename = pat % mydict['current_slide']
filepath = os.path.join(mydict['lecture_path'], filename)
return filepath
def build_next_outline_path(mydict):
print('mydict = ' + str(mydict))
if mydict.has_key('outline_pat'):
pat = mydict['outline_pat']
else:
pat = 'outline_%0.4i.png'
ind = mydict['outline_slide'] + 1
filename = pat % ind
if mydict.has_key('outline_dir'):
exclude_dir = mydict['outline_dir']
else:
exclude_dir = os.path.join(mydict['lecture_path'], 'exclude')
filepath = os.path.join(exclude_dir, filename)
return filepath
def open_or_create_slide(mydict, verbosity=1):
filepath = build_slide_path(mydict)
if os.path.exists(filepath):
if verbosity > 0:
print('found:' + filepath)
save_pickle(mydict)
my_open(filename=filepath)
else:
print('filepath not found: ' + filepath)
new_grid_image_2010()#this function saves the pickle
def check_for_next_outline_slide(mydict):
outline_path = build_next_outline_path(mydict)
return os.path.exists(outline_path)
def check_for_slide(mydict):
slidepath = build_slide_path(mydict)
return os.path.exists(slidepath)
def open_outline_png(pngpath):
img = new_grid_image_2010(outline=True)
floating_sel = copy_png_to_img(pngpath, img, x_offset=5, \
y_offset=5, autocrop=False, \
x_margin=0)
if top_layer_is_TEMP(img, 1) or top_layer_is_Latex(img, 1):
pdb.gimp_floating_sel_anchor(floating_sel)
if top_layer_is_Latex(img):
print('top_layer_is_Latex True')
#select_by_color(img.layers[0], (255,255,255))
#print('a')
#pdb.gimp_edit_clear(img.layers[0])
#print('b')
#pdb.gimp_selection_none(img)
print('c')
pdb.gimp_image_merge_down(img, img.layers[0],1)
print('d')
gimp.displays_flush()
#pdb.gimp_image_clean_all(img)
#pdb.gimp_selection_none(img)
def decrement_outline_slide_num():
mydict = open_pickle()
cur_outline_num = mydict['outline_slide']
print('cur_outline_num = ' + str(cur_outline_num))
new_dec_num = cur_outline_num - 1
mydict['outline_slide'] = new_dec_num
save_pickle(mydict)
def open_or_create_next_slide(save=True, close=True, force_no_outline=False):
if save or close:
success = _save_and_close(save=save, close=close)
if not success:
return
mydict = open_pickle()
next_slide = mydict['current_slide'] + 1
mydict['current_slide'] = next_slide
if check_for_slide(mydict):
save_pickle(mydict)