mwxlib 0.99.0__py3-none-any.whl → 1.7.13__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.
mwx/mgplt.py CHANGED
@@ -16,16 +16,16 @@ class Gnuplot:
16
16
  """Gnuplot backend - gnuplot pipe wrapper.
17
17
  """
18
18
  debug = 0
19
-
20
- PGNUPLOT = "gnuplot" # Note: gnuplot/pgnuplot is integrated
21
-
19
+
20
+ PGNUPLOT = "gnuplot" # Note: gnuplot/pgnuplot is integrated
21
+
22
22
  @staticmethod
23
23
  def init_path(path):
24
24
  if not os.path.isdir(path):
25
25
  print("- {!r} is not a directory.".format(path))
26
26
  return False
27
27
  os.environ['PATH'] = "{};{}".format(path, os.environ['PATH'])
28
-
28
+
29
29
  def __init__(self, startup="__init__.plt", debug=0):
30
30
  print("Launching new gnuplot...")
31
31
  self.__gnuplot = Popen([self.PGNUPLOT],
@@ -36,13 +36,13 @@ class Gnuplot:
36
36
  self.tempfile = tempfile.mktemp()
37
37
  self.debug = debug
38
38
  self.reset()
39
-
39
+
40
40
  def __del__(self):
41
41
  print("bye gnuplot...")
42
42
  self.terminate()
43
43
  if os.path.isfile(self.tempfile):
44
44
  os.remove(self.tempfile)
45
-
45
+
46
46
  def __call__(self, text):
47
47
  for cmd in filter(None, (t.strip() for t in text.splitlines())):
48
48
  self.__gnuplot.stdin.write((cmd + '\n').encode())
@@ -50,9 +50,9 @@ class Gnuplot:
50
50
  print("pgnupot>", cmd)
51
51
  self.__gnuplot.stdin.flush()
52
52
  return self
53
-
53
+
54
54
  def plot(self, *args):
55
- if isinstance(args[0], str): # text command
55
+ if isinstance(args[0], str): # text command
56
56
  pcmd = [v.strip() for v in args]
57
57
  if pcmd[-1].endswith(','):
58
58
  pcmd[-1] = pcmd[-1][:-1]
@@ -76,22 +76,22 @@ class Gnuplot:
76
76
  for v in args:
77
77
  if not isinstance(v, str):
78
78
  data.append(v)
79
- if len(data) - len(opts) > 1: # opts 指定が省略されたのでデフォルト指定
79
+ if len(data) - len(opts) > 1: # opts 指定が省略されたのでデフォルト指定
80
80
  opts.append("w l")
81
81
  else:
82
82
  opts.append(v)
83
83
 
84
- while len(data) > len(opts): # opts 指定の数が足りない場合 (maybe+1)
84
+ while len(data) > len(opts): # opts 指定の数が足りない場合 (maybe+1)
85
85
  opts.append("w l")
86
86
 
87
- pcmd = ["tempfile using 1:{} {}".format(j+2,opt) for j,opt in enumerate(opts)]
87
+ pcmd = ["tempfile using 1:{} {}".format(j+2, opt) for j, opt in enumerate(opts)]
88
88
  data = np.vstack((axis, data))
89
89
  with open(self.tempfile, 'w') as o:
90
90
  for v in data.T:
91
91
  o.write('\t'.join(self.data_format(x) for x in v) + '\n')
92
92
 
93
93
  self("plot " + ', '.join(pcmd))
94
-
94
+
95
95
  def terminate(self):
96
96
  if self.__gnuplot is not None:
97
97
  try:
@@ -101,21 +101,21 @@ class Gnuplot:
101
101
  except Exception:
102
102
  pass
103
103
  self.__gnuplot = None
104
-
104
+
105
105
  def restart(self):
106
106
  self.terminate()
107
107
  self.__init__(self.startupfile)
108
-
108
+
109
109
  def reset(self, startup=None):
110
110
  if startup:
111
111
  self.startupfile = startup
112
112
  if self.startupfile:
113
113
  self("load '{}'".format(self.startupfile))
114
114
  self("tempfile = '{}'".format(self.tempfile))
115
-
115
+
116
116
  def wait(self, msg=""):
117
117
  input(msg + " (Press ENTER to continue)")
118
-
118
+
119
119
  def edit(self):
120
120
  with warnings.catch_warnings():
121
121
  warnings.simplefilter("ignore", ResourceWarning)
@@ -129,7 +129,7 @@ class GnuplotFrame(mwx.Frame):
129
129
  mwx.Frame.__init__(self, *args, **kwargs)
130
130
 
131
131
  self.gnuplot = Gnuplot()
132
- self.panel = GnuplotPanel(self)
132
+ self.panel = ControlPanel(self)
133
133
 
134
134
  self.menubar["Edit"] = [
135
135
  (wx.ID_COPY, "&Copy params\tCtrl-c", "Copy params to clipboard",
@@ -139,7 +139,7 @@ class GnuplotFrame(mwx.Frame):
139
139
  lambda v: self.panel.paste_from_clipboard()),
140
140
  (),
141
141
  (wx.ID_RESET, "&Reset params\tCtrl-n", "Reset params to ini-value",
142
- lambda v: self.panel.set_params()),
142
+ lambda v: self.panel.reset_params()),
143
143
  ]
144
144
  self.menubar["Gnuplot"] = [
145
145
  (mwx.ID_(80), "&Gnuplot setting\tCtrl-g", "Edit settings",
@@ -152,9 +152,7 @@ class GnuplotFrame(mwx.Frame):
152
152
  lambda v: self.gnuplot.restart()),
153
153
  ]
154
154
  self.menubar.reset()
155
-
155
+
156
156
  def Destroy(self):
157
- try:
158
- del self.gnuplot
159
- finally:
160
- return mwx.Frame.Destroy(self)
157
+ del self.gnuplot
158
+ return mwx.Frame.Destroy(self)