Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

#!/usr/bin/env python 

# -*- coding: utf-8 -*- 

 

import ROOT 

from ..functools import static_struct 

 

__all__ = ('Anchors',) 

 

## Define the possible anchors 

ProtoAnchors = static_struct('ProtoAnchors', 

canvas = 'DOC', 

stack = 'DOC', 

mainpad = 'DOC', 

legend = 'DOC', 

legendpad = 'DOC', 

debug = 'DOC', 

debugpad = 'DOC', 

) 

 

class Anchors(ProtoAnchors): 

""" 

This helper class with take ownership the attached TObject. 

 

Usage:: 

 

## Init & attach 

>>> a = Anchors() 

>>> a.canvas = ROOT.TCanvas('name', 'title') 

 

""" 

 

def __setattr__(self, key, obj): 

""" 

Two possibilities: 

 

If obj is False/None, this will explicitly disable this anchor and thus the 

respective object will not be shown. 

 

If it's ROOT.TObject, then bind it normally. 

 

""" 

assert isinstance(obj, ROOT.TObject) 

if not key.startswith('_staticprop_'): 

## Keep alive 

ROOT.SetOwnership(obj, False) 

## Pad needs to be drawn not, and everything else doesn't. 

if isinstance(obj, ROOT.TPad): 

obj.Draw() 

return super(Anchors, self).__setattr__(key,obj) 

 

def update(self): 

""" 

Recursively call `Update` of all its contents. 

 

>>> a = Anchors() 

>>> a.canvas = ROOT.TCanvas('c2', 'title') 

>>> a.legend = ROOT.TLegend() 

>>> a.mainpad = ROOT.TPad('pad', 'pad', 0, 0, 1, 1) 

>>> a.update() 

 

""" 

## Drill down on existing pads. 

for key in self.keys(): 

if key != 'canvas': 

val = getattr(self, key) 

if val and isinstance(val, ROOT.TPad): 

val.Modified() 

val.Update() 

## Usually needed 

self.mainpad.RedrawAxis() 

## last object 

if self.canvas: 

self.canvas.Modified() 

self.canvas.Update() 

 

def save(self, *args): 

""" 

Delegation from canvas.SaveAs 

""" 

self.update() 

return self.canvas.SaveAs(*args) 

 

# def __str__(self): 

# ## Print list of objects in self 

# msg = "" 

# tmp = '{:10} {}\n'.format 

# msg += tmp('NAME', 'INSTANCE') 

# for name in dir(self): 

# if not name.startswith('_'): 

# obj = getattr(self, name) 

# if not hasattr(obj, 'im_self'): 

# msg += tmp(name, obj) 

# return msg