PageRenderTime 616ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/view.py

https://github.com/aidanf/SimpleICM
Python | 338 lines | 282 code | 19 blank | 37 comment | 9 complexity | 970e4c3ea6258f73d428533fb26a7137 MD5 | raw file
Possible License(s): GPL-3.0
  1. import clr
  2. clr.AddReference('System.Windows.Forms')
  3. clr.AddReference('System.Drawing')
  4. #clr.AddReference('System.ComponentModel')
  5. import System
  6. from System.Windows.Forms import *
  7. from System.ComponentModel import *
  8. from System.Drawing import *
  9. from System.IO import File, Path
  10. from clr import *
  11. from controller import SimpleICMController
  12. class SimpleICMForm(System.Windows.Forms.Form):
  13. #__slots__ = ['_tab_control', '_tabs[0]', '_tabs[1]', 'equities[8]', 'equities[7]', 'equities[6]', 'equities[5]', 'equities[4]', 'equities[3]', 'equities[2]', 'equities[1]', '_label_stack_header', '_label_eq_header', '_label_player_header', 'equities[0]', 'go_button', 'stacks[8]', '_player_labels[8]', 'stacks[7]', '_player_labels[7]', 'stacks[6]', '_player_labels[6]', 'stacks[5]', '_player_labels[5]', 'stacks[4]', '_player_labels[4]', 'stacks[3]', '_player_labels[3]', 'stacks[2]', '_player_labels[2]', 'stacks[1]', '_player_labels[1]', 'stacks[0]', '_player_labels[0]', '_richTextBox1', '_payouts[4]', '_payouts[3]', '_payouts[2]', '_payouts[1]', '_payouts[0]', '_payout_labels[4]', '_payout_labels[3]', '_payout_labels[2]', '_payout_labels[1]', '_payout_labels[0]', '_tabs[2]']
  14. def __init__(self):
  15. self.executablePath = __file__
  16. if self.executablePath is None:
  17. self.executablePath = Application.ExecutablePath
  18. self.executableDirectory = Path.GetDirectoryName(self.executablePath)
  19. self.InitializeComponent()
  20. self.controller = SimpleICMController(self)
  21. self.go_button.Click += self.controller.handle_go
  22. for stack in self.stacks:
  23. stack.GotFocus += self.controller.cache_value
  24. stack.LostFocus += self.controller.validate_number
  25. for payout in self.payouts:
  26. payout.GotFocus += self.controller.cache_value
  27. payout.LostFocus += self.controller.validate_number
  28. self._WebBrowser1.Navigating += self.controller.handle_navigate
  29. @accepts(Self(), bool)
  30. @returns(None)
  31. def Dispose(self, disposing):
  32. super(type(self), self).Dispose(disposing)
  33. @returns(None)
  34. def InitializeComponent(self):
  35. self.MaximumSize = self.MinimumSize = System.Drawing.Size(300, 480)
  36. self._tab_control = System.Windows.Forms.TabControl()
  37. self.statusStrip = System.Windows.Forms.StatusStrip()
  38. self.statusLabel = System.Windows.Forms.ToolStripStatusLabel()
  39. self._tabs = []
  40. self.iconPath = 'icons\\simple_icm.ico'
  41. self.Icon = Icon(Path.Combine(self.executableDirectory, self.iconPath))
  42. for i in range(3):
  43. self._tabs.append(System.Windows.Forms.TabPage())
  44. self.go_button = System.Windows.Forms.Button()
  45. self.stacks = []
  46. self.equities = []
  47. self._player_labels = []
  48. for i in range(9):
  49. self.stacks.append(System.Windows.Forms.TextBox())
  50. self.equities.append(System.Windows.Forms.Label())
  51. self._player_labels.append(System.Windows.Forms.Label())
  52. self._label_eq_header = System.Windows.Forms.Label()
  53. self._label_player_header = System.Windows.Forms.Label()
  54. self._label_stack_header = System.Windows.Forms.Label()
  55. self._WebBrowser1 = System.Windows.Forms.WebBrowser()
  56. self._payout_labels = []
  57. self.payouts = []
  58. for i in range(5):
  59. self._payout_labels.append(System.Windows.Forms.Label())
  60. self.payouts.append(System.Windows.Forms.TextBox())
  61. self._tab_control.SuspendLayout()
  62. self._tabs[0].SuspendLayout()
  63. self._tabs[1].SuspendLayout()
  64. self._tabs[2].SuspendLayout()
  65. self.statusStrip.SuspendLayout()
  66. self.SuspendLayout()
  67. #
  68. # tab3
  69. #
  70. for tab in self._tabs:
  71. self._tab_control.Controls.Add(tab)
  72. #self._tab_control.Location = System.Drawing.Point(13, 13)
  73. self._tab_control.Name = 'tab3'
  74. self._tab_control.SelectedIndex = 0
  75. #self._tab_control.Size = System.Drawing.Size(287, 447)
  76. self._tab_control.TabIndex = 0
  77. self._tab_control.Dock = System.Windows.Forms.DockStyle.Fill
  78. self._tab_control.Location = System.Drawing.Point(0, 0)
  79. #
  80. # tab1
  81. #
  82. for i in range(9):
  83. self._tabs[0].Controls.Add(self.equities[i])
  84. self._tabs[0].Controls.Add(self.stacks[i])
  85. self._tabs[0].Controls.Add(self._player_labels[i])
  86. self._tabs[0].Controls.Add(self._label_stack_header)
  87. self._tabs[0].Controls.Add(self._label_eq_header)
  88. self._tabs[0].Controls.Add(self._label_player_header)
  89. self._tabs[0].Controls.Add(self.go_button)
  90. self._tabs[0].Controls.Add(self.statusStrip)
  91. self._tabs[0].Location = System.Drawing.Point(4, 27)
  92. self._tabs[0].Name = 'tab1'
  93. self._tabs[0].Padding = System.Windows.Forms.Padding(3)
  94. self._tabs[0].Size = System.Drawing.Size(279, 416)
  95. self._tabs[0].TabIndex = 0
  96. self._tabs[0].Text = 'Stacks'
  97. self._tabs[0].UseVisualStyleBackColor = True
  98. #
  99. # tab2
  100. #
  101. for i in range(5):
  102. self._tabs[1].Controls.Add(self.payouts[i])
  103. self._tabs[1].Controls.Add(self._payout_labels[i])
  104. self._tabs[1].Location = System.Drawing.Point(4, 27)
  105. self._tabs[1].Name = 'tab2'
  106. self._tabs[1].Padding = System.Windows.Forms.Padding(3)
  107. self._tabs[1].Size = System.Drawing.Size(279, 416)
  108. self._tabs[1].TabIndex = 1
  109. self._tabs[1].Text = 'Payouts'
  110. self._tabs[1].UseVisualStyleBackColor = True
  111. #
  112. # tabPage3
  113. #
  114. self._tabs[2].Controls.Add(self._WebBrowser1)
  115. self._tabs[2].Location = System.Drawing.Point(4, 27)
  116. self._tabs[2].Name = 'tabPage3'
  117. self._tabs[2].Padding = System.Windows.Forms.Padding(3)
  118. self._tabs[2].Size = System.Drawing.Size(279, 416)
  119. self._tabs[2].TabIndex = 2
  120. self._tabs[2].Text = 'About'
  121. self._tabs[2].UseVisualStyleBackColor = True
  122. #
  123. # button_go
  124. #
  125. self.go_button.Location = System.Drawing.Point(9, 350)
  126. self.go_button.Name = 'button_go'
  127. self.go_button.Size = System.Drawing.Size(263, 35)
  128. self.go_button.TabIndex = 55
  129. self.go_button.Text = 'Go'
  130. self.go_button.UseVisualStyleBackColor = True
  131. self.statusStrip.Items.AddRange( System.Array[System.Windows.Forms.ToolStripItem]((self.statusLabel, )))
  132. self.statusStrip.Location = System.Drawing.Point(3, 515)
  133. self.statusStrip.Name = 'statusStrip'
  134. self.statusStrip.Size = System.Drawing.Size(178, 22)
  135. self.statusStrip.TabIndex = 56
  136. self.statusStrip.Text = 'Waiting'
  137. self.statusStrip.Dock = System.Windows.Forms.DockStyle.Bottom
  138. self.statusLabel.Name = 'statusLabel'
  139. self.statusLabel.Size = System.Drawing.Size(109, 17)
  140. self.statusLabel.Text = 'Status: Ready'
  141. #self.statusLabel.Click += self.statusLabel1_Click
  142. #def click(sender, event):
  143. # print "Clicked"
  144. #
  145. # stack9
  146. #
  147. def initialize_stack(i, location, size, tabindex):
  148. self.stacks[i].Location = location
  149. self.stacks[i].Name = "stack%s" % (i+1)
  150. self.stacks[i].Size = size
  151. self.stacks[i].TabIndex = tabindex
  152. self.stacks[i].Text = '1500'
  153. initialize_stack(8, System.Drawing.Point(93, 309),
  154. System.Drawing.Size(111, 27), 54)
  155. initialize_stack(7 , System.Drawing.Point(93, 276),
  156. System.Drawing.Size(111, 27), 52)
  157. initialize_stack(6, System.Drawing.Point(93, 243),
  158. System.Drawing.Size(111, 27), 50)
  159. initialize_stack(5, System.Drawing.Point(93, 210),
  160. System.Drawing.Size(111, 27), 48)
  161. initialize_stack(4, System.Drawing.Point(93, 177),
  162. System.Drawing.Size(111, 27), 46)
  163. initialize_stack(3, System.Drawing.Point(93, 144),
  164. System.Drawing.Size(111, 27), 44)
  165. initialize_stack(2, System.Drawing.Point(93, 111),
  166. System.Drawing.Size(111, 27), 42)
  167. initialize_stack(1, System.Drawing.Point(93, 78),
  168. System.Drawing.Size(111, 27), 40)
  169. initialize_stack(0, System.Drawing.Point(93, 45),
  170. System.Drawing.Size(111, 27), 38)
  171. def initialize_player_label(i, location, size, tabindex):
  172. self._player_labels[i].AutoSize = True
  173. self._player_labels[i].Location = location
  174. self._player_labels[i].Name = "label_p%s" % (i+1)
  175. self._player_labels[i].Size = size
  176. self._player_labels[i].TabIndex = tabindex
  177. self._player_labels[i].Text = "Player %s" % (i+1)
  178. initialize_player_label(8, System.Drawing.Point(6, 312),
  179. System.Drawing.Size(74, 18), 53)
  180. initialize_player_label(7, System.Drawing.Point(6, 279),
  181. System.Drawing.Size(74, 18), 51)
  182. initialize_player_label(6, System.Drawing.Point(6, 246),
  183. System.Drawing.Size(74, 18), 49)
  184. initialize_player_label(5, System.Drawing.Point(6, 213),
  185. System.Drawing.Size(74, 18), 47)
  186. initialize_player_label(4, System.Drawing.Point(6, 180),
  187. System.Drawing.Size(74, 18), 45)
  188. initialize_player_label(3, System.Drawing.Point(6, 147),
  189. System.Drawing.Size(74, 18), 43)
  190. initialize_player_label(2, System.Drawing.Point(6, 114),
  191. System.Drawing.Size(74, 18), 41)
  192. initialize_player_label(1, System.Drawing.Point(6, 81),
  193. System.Drawing.Size(74, 18), 39)
  194. initialize_player_label(0, System.Drawing.Point(6, 48),
  195. System.Drawing.Size(74, 18), 37)
  196. #
  197. # eq1
  198. #
  199. #
  200. # label_eq_header
  201. #
  202. self._label_eq_header.AutoSize = True
  203. self._label_eq_header.Font = System.Drawing.Font('Verdana', 12.0, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 0)
  204. self._label_eq_header.Location = System.Drawing.Point(210, 9)
  205. self._label_eq_header.Name = 'label_eq_header'
  206. self._label_eq_header.Size = System.Drawing.Size(62, 18)
  207. self._label_eq_header.TabIndex = 59
  208. self._label_eq_header.Text = 'Equity'
  209. #
  210. # label_player_header
  211. #
  212. self._label_player_header.AutoSize = True
  213. self._label_player_header.Font = System.Drawing.Font('Verdana', 12.0, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 0)
  214. self._label_player_header.Location = System.Drawing.Point(6, 9)
  215. self._label_player_header.Name = 'label_player_header'
  216. self._label_player_header.Size = System.Drawing.Size(63, 18)
  217. self._label_player_header.TabIndex = 57
  218. self._label_player_header.Text = 'Player'
  219. #
  220. # label_stack_header
  221. #
  222. self._label_stack_header.AutoSize = True
  223. self._label_stack_header.Font = System.Drawing.Font('Verdana', 12.0, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 0)
  224. self._label_stack_header.Location = System.Drawing.Point(90, 9)
  225. self._label_stack_header.Name = 'label_stack_header'
  226. self._label_stack_header.Size = System.Drawing.Size(56, 18)
  227. self._label_stack_header.TabIndex = 60
  228. self._label_stack_header.Text = 'Stack'
  229. def initialize_equity(i, location, size, tabindex):
  230. self.equities[i].AutoSize = True
  231. self.equities[i].Location = location
  232. self.equities[i].Name = "eq%i" % (i+1)
  233. self.equities[i].Size = size
  234. self.equities[i].TabIndex = tabindex
  235. self.equities[i].Text = ''
  236. initialize_equity(0, System.Drawing.Point(210, 48),
  237. System.Drawing.Size(38, 18), 56)
  238. initialize_equity(1, System.Drawing.Point(210, 81),
  239. System.Drawing.Size(38, 18), 61)
  240. initialize_equity(2, System.Drawing.Point(210, 114),
  241. System.Drawing.Size(38, 18), 62)
  242. initialize_equity(3, System.Drawing.Point(210, 147),
  243. System.Drawing.Size(38, 18), 63)
  244. initialize_equity(4, System.Drawing.Point(210, 180),
  245. System.Drawing.Size(38, 18), 64)
  246. initialize_equity(5, System.Drawing.Point(210, 213),
  247. System.Drawing.Size(38, 18), 65)
  248. initialize_equity(6, System.Drawing.Point(210, 246),
  249. System.Drawing.Size(38, 18), 66)
  250. initialize_equity(7, System.Drawing.Point(210, 279),
  251. System.Drawing.Size(38, 18), 67)
  252. initialize_equity(8, System.Drawing.Point(210, 312),
  253. System.Drawing.Size(38, 18), 68)
  254. #
  255. # WebBrowser1
  256. #
  257. self._WebBrowser1.Location = System.Drawing.Point(7, 7)
  258. self._WebBrowser1.Name = 'WebBrowser1'
  259. self._WebBrowser1.Size = System.Drawing.Size(266, 403)
  260. self._WebBrowser1.TabIndex = 0
  261. self._WebBrowser1.BackColor = Color.White
  262. #self._WebBrowser1.AllowNavigation = False
  263. self._WebBrowser1.AllowWebBrowserDrop = False
  264. self._WebBrowser1.IsWebBrowserContextMenuEnabled = False
  265. self._WebBrowser1.ScrollBarsEnabled = False
  266. self._WebBrowser1.DocumentText = open(Path.Combine(self.executableDirectory, 'about.html')).read()
  267. #
  268. # labelpayouts[0]
  269. #
  270. def initialize_payout_labels():
  271. texts = ['1st', '2nd', '3rd', '4th', '5th']
  272. locations = [(6, 24), (6, 59), (6, 94), (6, 131), (6, 164)]
  273. for i in range(5):
  274. self._payout_labels[i].AutoSize = True
  275. self._payout_labels[i].Location = System.Drawing.Point(locations[i][0], locations[i][1])
  276. self._payout_labels[i].Name = "label_payouts_%s" % (i+1)
  277. self._payout_labels[i].Size = System.Drawing.Size(34, 18)
  278. self._payout_labels[i].TabIndex = i
  279. self._payout_labels[i].Text = texts[i]
  280. initialize_payout_labels()
  281. def initialize_payouts():
  282. texts = ['0.5', '0.3', '0.2', '0.0', '0.0']
  283. locations = [(66, 21), (66, 56), (66, 91), (66, 128), (66, 161)]
  284. for i in range(5):
  285. self.payouts[i].Location = System.Drawing.Point(locations[i][0], locations[i][1])
  286. self.payouts[i].Name = "payout%s" % (i+1)
  287. self.payouts[i].Size = System.Drawing.Size(100, 27)
  288. self.payouts[i].TabIndex = 5 + i
  289. self.payouts[i].Text = texts[i]
  290. initialize_payouts()
  291. #
  292. # SimpleICMView
  293. #
  294. self.ClientSize = System.Drawing.Size(308, 467)
  295. self.Controls.Add(self._tab_control)
  296. self.Font = System.Drawing.Font('Verdana', 12.0, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
  297. self.Name = 'SimpleICMView'
  298. self.Text = 'SimpleICM'
  299. self._tab_control.ResumeLayout(False)
  300. self._tabs[0].ResumeLayout(False)
  301. self._tabs[0].PerformLayout()
  302. self.statusStrip.ResumeLayout(False)
  303. self.statusStrip.PerformLayout()
  304. self._tabs[1].ResumeLayout(False)
  305. self._tabs[1].PerformLayout()
  306. self._tabs[2].ResumeLayout(False)
  307. self.ResumeLayout(False)
  308. @accepts(Self(), System.Object, System.EventArgs)
  309. @returns(None)
  310. def _textBox6_TextChanged(self, sender, e):
  311. pass
  312. if __name__ == '__main__':
  313. print "View"