File: cgfileselect__define.pro

package info (click to toggle)
coyote 2019.01.29-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 6,316 kB
  • sloc: python: 184; makefile: 14; sh: 13
file content (174 lines) | stat: -rw-r--r-- 4,518 bytes parent folder | download | duplicates (2)
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
;+
; This method returns the object properties.
;-
PRO cgFileSelect::GetProperty, $
   FILENAME=filename, $
   LASTDIR=lastdir, $
   PARENT=parent, $
   TLB=tlb, $
   UNAME=uname, $
   UVALUE=uvalue
   
   IF Arg_Present(filename) THEN filename = self.filename
   IF Arg_Present(lastdir) THEN lastdir = self.lastdir
   IF Arg_Present(parent) THEN parent = self.parent
   IF Arg_Present(tlb) THEN tlb = self.tlb
   IF Arg_Present(uname) THEN uname = self.uname
   IF Arg_Present(uvalue) THEN IF Ptr_Valid(self.uvalue) THEN uvalue = *self.uvalue

END

;+
; This method sets the object properties.
;-
PRO cgFileSelect::SetProperty, $
   FILENAME=filename, $
   LASTDIR=lastdir, $
   UVALUE=uvalue
   
   IF N_Elements(filename) NE 0 THEN BEGIN
        self.filename = filename
        Widget_Control, self.textID, Set_Value=filename
   ENDIF
   IF N_Elements(lastdir) NE 0 THEN self.lastdir = lastdir
   IF N_Elements(uvalue) NE 0 THEN IF Ptr_Valid(self.uvalue) $
       THEN *self.uvalue = uvalue $
       ELSE self.uvalue = Ptr_New(uvalue)
       
END

;+
; The class clean-up method.
;-
PRO cgFileSelect::CLEANUP

    Ptr_Free, self.uvalue

END


;+
; The class initialization method.
; 
; :Params:
;     parent: in, optional
;          The identifier of the parent widget. If not used, a top-level base widget
;          will be created to hold the contents of the program.
;          
; :Keywords:
;     
;-
FUNCTION cgFileSelect::INIT, parent, $
   FILENAME=filename, $
   FRAME=frame, $
   LABELSIZE=labelsize, $
   NAMESIZE=namesize, $
   TITLE=title, $
   UNAME=uname, $
   UVALUE=uvalue
    
   Compile_Opt idl2
    
   ; Error handling for the program module.
   Catch, theError
   IF theError NE 0 THEN BEGIN
       Catch, /Cancel
       void = cgErrorMsg()
       RETURN, 0
   ENDIF
    
   ; Need a parent?
   IF N_Elements(parent) EQ 0 THEN BEGIN
        parent = Widget_Base()
        createdParent = 1
   ENDIF ELSE createdParent = 0
   
   ; Default keyword values.
   SetDefaultValue, title, 'Filename: '
   SetDefaultValue, filename, ""
   SetDefaultValue, labelsize, !D.X_CH_SIZE * StrLen(title)
   SetDefaultValue, namesize, 0
   SetDefaultValue, uname, 'cgFileSelect'
   
   IF filename EQ "" THEN BEGIN
      CD, CURRENT=lastDir 
   ENDIF ELSE BEGIN
      root = cgRootName(filename, DIRECTORY=lastDir)
   ENDELSE
   
   ; Create the widgets for the program.
   tlb = Widget_Base(parent, ROW=1, UVALUE=self, EVENT_PRO='cgFileSelect_Events', FRAME=frame)
   labelID = Widget_Label(tlb, Value=title, SCR_XSIZE=labelsize)
   IF namesize NE 0 THEN BEGIN
      textID = Widget_Label(tlb, Value=filename, /SUNKEN_FRAME, SCR_XSIZE=namesize)
   ENDIF ELSE BEGIN
      textID = Widget_Label(tlb, Value=filename, /SUNKEN_FRAME, DYNAMIC_RESIZE=1)
   ENDELSE
   button = Widget_Button(tlb, Value='Browse', UVALUE=self)
   
   ; Need to realize the widgets?
   IF createdParent THEN BEGIN
       cgCenterTLB, parent
       Widget_Control, parent, /REALIZE
   ENDIF
   
   ; Populate the object.
   self.filename = filename
   self.lastDir = lastDir
   self.parent = parent
   self.tlb = tlb
   self.textID = textID
   self.labelID = labelID
   self.uname = uname
   IF N_Elements(uvalue) NE 0 THEN self.uvalue = Ptr_New(uvalue)   
    
    
   ; Need to run the program?
   IF createdParent THEN XManager, 'cgfileselect', parent, /No_Block
   
   RETURN, 1
END


;+
; The class event handler. All program widget events come here to be processed.
;
; :Params:
;     event: in, required
;         The event structure from the widget causing the event.
;+
PRO cgFileSelect_Events, event

    Widget_Control, event.id, GET_UVALUE=self
    self -> GetProperty, LASTDIR=lastDir, FILENAME=filename, PARENT=parent, TLB=tlb
    filename = Dialog_Pickfile(PATH=lastDir, /WRITE, Title='Select File...', $
       FILE=cgRootName(filename))
    IF filename NE "" THEN BEGIN
       rootname = cgRootName(filename, DIRECTORY=lastDir)
       self -> SetProperty, FILENAME=filename, LASTDIR=lastDir
    ENDIF
        
END


;+
; The class definition module for the cgFileSelect object.
; 
; :Params:
;     class: out, optional, type=structure
;         The structure definition for the cgFileSelect object class.
;-
PRO cgFileSelect__Define, class

    class = { cgFileSelect, $
              filename: "", $
              labelID: 0L, $
              lastDir: "", $
              parent: 0L, $
              tlb: 0L, $
              textID: 0L, $
              uname: "", $
              uvalue: Ptr_New() $
            }

END