Package client :: Module Preferences
[hide private]
[frames] | no frames]

Source Code for Module client.Preferences

  1  from PyQt4.QtGui  import * 
  2  from PyQt4.QtCore import * 
  3   
  4  import re 
  5   
  6  import Constants 
  7  import Connection 
  8   
9 -class Preferences (QDialog):
10 """ 11 Overview 12 ======== 13 This is the overall preferences dialog. It essentially has a left column of different types of 14 preferences, and by clicking on these options you load (and by load, I mean uncover) the section 15 of preferences you want to edit. The right side is dedicated to the sections. 16 17 Each section is otherwise self sufficient from finding the settings to saving them. This class 18 manages the sections, not the preferences themselves. 19 """ 20
21 - def __init__ (self, bridge):
22 """ 23 Overview 24 ======== 25 The initialization method sets up how the preferences dialog will work, but nothing about 26 the actual preferences. 27 28 It sets up the eometry of the dialog box, then makes a left-hand list of the sections that 29 can be selected. After actually creating the secitons in their respective classes, it sets 30 up the mechanism for switching between them. 31 """ 32 33 # This simply sets up the position and size of the dialog 34 # Currently it is set to be centered to the main widget 35 # and be half of its size. 36 QDialog.__init__ (self) 37 self._bridge = bridge 38 mainRect = self._bridge._mainWindow.geometry () 39 width = mainRect.width () 40 height = mainRect.height () 41 x = mainRect.x () + int (width * 0.25) 42 y = mainRect.y () + int (height * 0.25) 43 width = int (width * 0.5) 44 height = int (height * 0.5) 45 self.setGeometry (x, y, width, height) 46 47 # Sets up the icon and title for the dialog 48 self._current = None 49 self.setWindowIcon (QIcon (Constants.ICON_DIR + "/file/preferences.png")) 50 self.setWindowTitle ("Preferences") 51 layout = QHBoxLayout (self) 52 53 # The left hand is a list-widget which contains the selector for 54 # Switching between sections, and the Done button to close the dialog 55 leftLayout = Constants.BQVBoxLayout (layout) 56 self.moduleSelect = QListWidget () 57 leftLayout.addWidget (self.moduleSelect) 58 doneButton = Constants.BQPushButton ("Done", leftLayout) 59 QObject.connect (doneButton, SIGNAL ("clicked ()"), self.accept) 60 61 self.moduleDisplay = Constants.BQHBoxLayout (layout) 62 layout.setStretchFactor (leftLayout, 1) 63 layout.setStretchFactor (self.moduleDisplay, 3) 64 QObject.connect (self.moduleSelect, SIGNAL ("itemClicked (QListWidgetItem *)"), self.changeDisplay) 65 QObject.connect (self.moduleSelect, SIGNAL ("itemSelected (QListWidgetItem *)"), self.changeDisplay) 66 self.moduleSelect.setResizeMode (QListView.Fixed) 67 68 # These are the sections to be added... 69 self.addGeneral () 70 self.addConnection () 71 self.addToolBar () 72 self.addAppearance () 73 74 self.exec_ ()
75 76
77 - def changeDisplay (self, item):
78 """ 79 Overview 80 ======== 81 This method will make the current displayed preference section invisible, and then make 82 the passed `item` preferences widget visisble. This is connected to slicking or selecting 83 items from the left-hand list of preferences sections. 84 """ 85 86 if self._current: 87 self._current.setVisible (False) 88 self._current = item._display 89 self._current.setVisible (True)
90
91 - def addConnection (self):
92 """ 93 Overview 94 ======== 95 This method simply encapsulates the adding of the Connection Preferences. It is an 96 organizational encapsulation, as nothing is really gained from taking this out of __init__. 97 98 This sets up the ConnectionPreferences class, and then makes it inviisble until the user 99 actually wants to use it. 100 """ 101 102 item = QListWidgetItem ("Connection") 103 104 display = QWidget () 105 display.setVisible (False) 106 display.setLayout (ConnectionPreferences (self._bridge)) 107 108 item._display = display 109 self.moduleSelect.addItem (item) 110 self.moduleDisplay.addWidget (display)
111
112 - def addToolBar (self):
113 """ 114 Overview 115 ======== 116 This method simply encapsulates the adding of the Tool Bar Preferences. It is an organizational 117 encapsulation, as nothing is really gained from taking this out of __init__. 118 119 This sets up the ToolBarPreferences class, and then makes it inviisble until the user actually 120 wants to use it. 121 """ 122 123 item = QListWidgetItem ("Tool Bar") 124 125 display = QWidget () 126 display.setVisible (False) 127 layout = QVBoxLayout (display) 128 layout.addLayout (ToolBarPreferences (self._bridge)) 129 130 item._display = display 131 self.moduleSelect.addItem (item) 132 self.moduleDisplay.addWidget (display)
133
134 - def addAppearance (self):
135 """ 136 Overview 137 ======== 138 This method simply encapsulates the adding of the Appearance Preferences. It is an organizational 139 encapsulation, as nothing is really gained from taking this out of __init__. 140 141 This sets up the AppearancePreferences class, and then makes it inviisble until the user actually 142 wants to use it. 143 """ 144 145 item = QListWidgetItem ("Appearance") 146 147 display = QWidget () 148 display.setVisible (False) 149 layout = QVBoxLayout (display) 150 layout.addLayout (AppearancePreferences (self._bridge)) 151 152 item._display = display 153 self.moduleSelect.addItem (item) 154 self.moduleDisplay.addWidget (display)
155
156 - def addGeneral (self):
157 """ 158 Overview 159 ======== 160 This method simply encapsulates the adding of the General Preferences. It is an organizational 161 encapsulation, as nothing is really gained from taking this out of __init__. 162 163 This sets up the GeneralPreferences class, and then makes it inviisble until the user actually 164 wants to use it. 165 """ 166 167 item = QListWidgetItem ("General") 168 169 display = QWidget () 170 display.setVisible (False) 171 layout = QVBoxLayout (display) 172 layout.addLayout (GeneralPreferences (self._bridge)) 173 174 item._display = display 175 self.moduleSelect.addItem (item) 176 self.moduleDisplay.addWidget (display) 177 item.setSelected (True) 178 self.changeDisplay (item)
179 180
181 -class GeneralPreferences (QVBoxLayout):
182 """ 183 Overview 184 ======== 185 These are essentially the miscellaneous options that weren't grouped well enough to warrant their 186 own section. They include such things as: 187 - Default save/open directory 188 - Reduction in cluster output 189 - Dock widget's auto-guessing feature 190 - Dock widget's auto-inplace or free flaoting feature 191 192 These settings get saved in ~/.basin/client/general.conf 193 """ 194
195 - def __init__ (self, bridge):
196 """ 197 GeneralPreferences.__init__ (self, bridge) 198 199 The initialization of the General Preferences section 200 of the Preferences dialog simply lays out a few simple 201 options for the user. 202 203 It sets up a place to enter a default path for open/saving 204 to default to. 205 206 It sets up three checkboxes for auto-guessing auto-inplace 207 functions, and limiting output. 208 """ 209 QVBoxLayout.__init__ (self) 210 self._bridge = bridge 211 212 header = QLabel ("General Preferences") 213 header.setAlignment (Qt.AlignHCenter) 214 self.addWidget (header) 215 216 dataPathLayout = Constants.BQHBoxLayout (self) 217 dataPathLabel = QLabel ("Default Data Path:") 218 dataPathLabel.setAlignment (Qt.AlignRight | Qt.AlignVCenter) 219 dataPathLayout.addWidget (dataPathLabel) 220 self._dataPath = QLineEdit () 221 dataPathLayout.addWidget (self._dataPath) 222 223 self._inplaceCheck = QCheckBox ("Functions default output to parent,\n" + \ 224 "instead of free floating variables\n" + \ 225 "when possible.") 226 self.addWidget (self._inplaceCheck) 227 228 self._autoguessCheck = QCheckBox ("Functions will automatically try\n" + \ 229 "to guess input values.") 230 self.addWidget (self._autoguessCheck) 231 232 self._limitoutCheck = QCheckBox ("Limit output to 1 node, even\n" + \ 233 "when you are in parallel mode.") 234 self.addWidget (self._limitoutCheck) 235 236 saveButton = Constants.BQPushButton ("Save", self) 237 QObject.connect (saveButton, SIGNAL ("clicked ()"), self.saveSettings) 238 self.getValues ()
239
240 - def getValues (self):
241 """ 242 GeneralPreferences.getValues (self) 243 244 This method is generally only to be called initially. It 245 retrieves the settings that it controls from the bridge. 246 247 The widgets which are affected from these settings need to 248 be aware of the settings from the bridge, so this informs 249 the preferences menu of what is already set. 250 251 If settings are then applied after this, they will both be 252 saved to the bridge, where they will go into effect, but 253 also to the conf file: ~/.basin/client/general.conf 254 """ 255 if self._bridge._inPlace: 256 self._inplaceCheck.setCheckState (Qt.Checked) 257 else: 258 self._inplaceCheck.setCheckState (Qt.Unchecked) 259 if self._bridge._autoGuess: 260 self._autoguessCheck.setCheckState (Qt.Checked) 261 else: 262 self._autoguessCheck.setCheckState (Qt.Unchecked) 263 if self._bridge._limitOut: 264 self._limitoutCheck.setCheckState (Qt.Checked) 265 else: 266 self._limitoutCheck.setCheckState (Qt.Unchecked) 267 if self._bridge._dataPath: 268 self._dataPath.setText (self._bridge._dataPath) 269 else: 270 self._dataPath.setText ("None")
271
272 - def saveSettings (self):
273 """ 274 GeneralPreferences.saveSettings (self) 275 276 This is a fairly straight forward method which takes 277 the current settings, regarldess of what they are, were, 278 or anything, saves them to ~/.basin/client/general.conf 279 280 If the file didn't already exist, thats no problem and it will 281 now. This will also make the bridge re-load the values from the 282 newly created file. 283 284 In general, the format of the file ignores non newline whitespace. 285 It follows the format:: 286 287 SETTING:value 288 289 Order is irrelevant! 290 291 Everything obviously gets saved as a string, to this needs 292 to be kept in mind when re-loading at the bridge. 293 """ 294 path = QDir.home () 295 if not path.exists (".basin"): 296 path.mkdir (".basin") 297 path.cd (".basin") 298 if not path.exists ("client"): 299 path.mkdir ("client") 300 path.cd ("client") 301 file = QFile (str (path.path ()) + "/general.conf" ) 302 file.setPermissions (QFile.WriteOwner | QFile.ReadOwner | QFile.ReadUser | QFile.WriteUser) 303 file.open (QIODevice.WriteOnly | QIODevice.Text) 304 305 file.writeData ("# General Preferences\n\n\n") 306 307 file.writeData ("# True / False Section\n") 308 if self._inplaceCheck.checkState () == Qt.Unchecked: 309 file.writeData ("INPLACE:False\n") 310 elif self._inplaceCheck.checkState () == Qt.Checked: 311 file.writeData ("INPLACE:True\n") 312 313 if self._autoguessCheck.checkState () == Qt.Unchecked: 314 file.writeData ("AUTOGUESS:False\n") 315 elif self._autoguessCheck.checkState () == Qt.Checked: 316 file.writeData ("AUTOGUESS:True\n") 317 318 if self._limitoutCheck.checkState () == Qt.Unchecked: 319 file.writeData ("LIMITOUT:False\n\n") 320 elif self._limitoutCheck.checkState () == Qt.Checked: 321 file.writeData ("LIMITOUT:True\n\n") 322 323 file.writeData ("# A *NIX style absolute path\n") 324 file.writeData ("DATAPATH:" + str (self._dataPath.text ()) + "\n\n") 325 326 file.close () 327 328 self._bridge.loadSettings ()
329 330
331 -class ToolBarPreferences (QVBoxLayout):
332 """ 333 Overview 334 ======== 335 This class is another section of settings that will dictate what actions are available to the user 336 from the tool bar. At this point, they can select only entire packages to be displayed or removed from it. 337 338 Also, currently there is just a single order that they are displayed with. This means that File 339 actions will always be at the beginning of the toolbar, Plotting next, etc, without being re-ordered. 340 """ 341
342 - def __init__ (self, bridge):
343 """ 344 Overview 345 ======== 346 This initialization requires only the Bridge object to work properly. It will essentially 347 create 2 lists, one with the packages, and the other with the individial actions in each 348 package. 349 350 The list of actions is really just to inform the user what is exactly in each package. 351 The list of packages, however, have checkboxes so that the user can choose which packages 352 they would like on their toolbar. 353 """ 354 355 QVBoxLayout.__init__ (self) 356 self._bridge = bridge 357 self._toolBar = bridge._toolBar 358 359 headerLayout = Constants.BQHBoxLayout (self) 360 leftHeader = QLabel ("Categories") 361 leftHeader.setAlignment (Qt.AlignHCenter) 362 rightHeader = QLabel ("Contents") 363 rightHeader.setAlignment (Qt.AlignHCenter) 364 headerLayout.addWidget (leftHeader) 365 headerLayout.addWidget (rightHeader) 366 367 selectLayout = Constants.BQHBoxLayout (self) 368 self.leftList = QListWidget () 369 self.rightList = QListWidget () 370 selectLayout.addWidget (self.leftList) 371 selectLayout.addWidget (self.rightList) 372 QObject.connect (self.leftList, SIGNAL ("itemActivated (QListWidgetItem *)"), self.updateCategory) 373 QObject.connect (self.leftList, SIGNAL ("itemClicked (QListWidgetItem *)"), self.updateCategory) 374 375 for category in self._toolBar.categories (): 376 temp = QListWidgetItem (category[0]) 377 # For some reason this is the only way to enable 378 # checking in the first place... 379 temp.setCheckState (Qt.Unchecked) 380 if category[1]: 381 temp.setCheckState (Qt.Checked) 382 self.leftList.addItem (temp) 383 384 saveButton = Constants.BQPushButton ("Save", self) 385 QObject.connect (saveButton, SIGNAL ("clicked ()"), self.saveSettings)
386
387 - def updateCategory (self, item):
388 """ 389 Overview 390 ======== 391 This method is called whenever an item is clicked on the left-hand list, the package list. 392 It will automatically update the right-hand action list to reflect the actions in the newly 393 selected package. 394 """ 395 396 self.rightList.clear () 397 actions = self._toolBar.actions (item.text ()) 398 for action in actions: 399 text = action.text ().replace ("&", "").replace ("...", "") 400 if text != "": 401 temp = QListWidgetItem (action.icon (), text) 402 self.rightList.addItem (temp)
403
404 - def saveSettings (self):
405 """ 406 ToolBarPreferences.saveSettings (self) 407 408 This method is called whenever settings are applied 409 """ 410 path = QDir.home () 411 if not path.exists (".basin"): 412 path.mkdir (".basin") 413 path.cd (".basin") 414 if not path.exists ("client"): 415 path.mkdir ("client") 416 path.cd ("client") 417 file = QFile (str (path.path ()) + "/menubar.conf" ) 418 file.setPermissions (QFile.WriteOwner | QFile.ReadOwner | QFile.ReadUser | QFile.WriteUser) 419 file.open (QIODevice.WriteOnly | QIODevice.Text) 420 file.writeData ("# Toolbar Preferences\n\n") 421 file.writeData ("# True / False Section\n") 422 423 for category in ["File", "Plotting", "General Functions", "Stellar Dynamics", \ 424 "Statistics", "Cosmology", "Linear Algebra", "Transformations", "Help"]: 425 item = self.leftList.findItems (category, Qt.MatchExactly)[0] 426 val = None 427 if item.checkState () == Qt.Checked: 428 val = "True" 429 else: 430 val = "False" 431 432 if item.text () == "File": 433 file.writeData ("FILE:" + val + "\n") 434 elif item.text () == "Plotting": 435 file.writeData ("PLOT:" + val + "\n") 436 elif item.text () == "General Functions": 437 file.writeData ("GENERALFUNCTIONS:" + val + "\n") 438 elif item.text () == "Stellar Dynamics": 439 file.writeData ("STELLARDYNAMICS:" + val + "\n") 440 elif item.text () == "Statistics": 441 file.writeData ("STATISTICS:" + val + "\n") 442 elif item.text () == "Cosmology": 443 file.writeData ("COSMOLOGY:" + val + "\n") 444 elif item.text () == "Linear Algebra": 445 file.writeData ("LINEARALGEBRA:" + val + "\n") 446 elif item.text () == "Transformations": 447 file.writeData ("TRANSFORMATIONS:" + val + "\n") 448 elif item.text () == "Help": 449 file.writeData ("HELP:" + val + "\n") 450 file.writeData ("\n") 451 452 file.close () 453 self._toolBar.loadSettings ()
454 455
456 -class AppearancePreferences (QGridLayout):
457 - def __init__ (self, bridge):
458 QVBoxLayout.__init__ (self) 459 self._bridge = bridge 460 self._ipyShell = bridge._ipyShell._commandHistory 461 462 # Create buffer values and populate them 463 # These values will act as an intermediate for a user 464 # to edit settings before they are committed to a both 465 # the shell, and a conf file 466 self._command = {} 467 self._comment = {} 468 self._result = {} 469 self.PopulateBufferFromShell () 470 471 # The overall category selector 472 selectLabel = QLabel ("Select:") 473 selectLabel.setAlignment (Qt.AlignHCenter) 474 self.categorySelect = QComboBox () 475 self.categorySelect.addItems (["Command", "Comment", "Result"]) 476 477 # The font family selector 478 fontLabel = QLabel ("Font:") 479 fontLabel.setAlignment (Qt.AlignHCenter) 480 self.fontSelect = QFontComboBox () 481 482 # The font size spin-box 483 sizeLabel = QLabel ("Size:") 484 sizeLabel.setAlignment (Qt.AlignHCenter) 485 self.sizeSelect = QSpinBox () 486 self.sizeSelect.setRange (1, 64) 487 488 # The color selector and html code editor 489 colorLabel = QLabel ("Color:") 490 colorLabel.setAlignment (Qt.AlignHCenter) 491 self.colorSelect = QComboBox () 492 self.colorSelect.addItem (QIcon (Constants.ICON_DIR + "/colors/white.png"), \ 493 "White", QVariant ("#ffffff")) 494 self.colorSelect.addItem (QIcon (Constants.ICON_DIR + "/colors/red.png"), \ 495 "Red", QVariant ("#ff0000")) 496 self.colorSelect.addItem (QIcon (Constants.ICON_DIR + "/colors/blue.png"), \ 497 "Blue", QVariant ("#000cff")) 498 self.colorSelect.addItem (QIcon (Constants.ICON_DIR + "/colors/lightgreen.png"), \ 499 "Light Green", QVariant ("#19e83b")) 500 self.colorSelect.addItem (QIcon (Constants.ICON_DIR + "/colors/darkgreen.png"), \ 501 "Dark Green", QVariant ("#05851a")) 502 self.colorSelect.addItem (QIcon (Constants.ICON_DIR + "/colors/black.png"), \ 503 "Black", QVariant ("#000000")) 504 self.colorSelect.addItem ("Custom", QVariant ("")) 505 colorcodeLabel = QLabel ("Color (HTML):") 506 colorLabel.setAlignment (Qt.AlignHCenter) 507 self.colorCode = QLineEdit () 508 509 # Area for selecting additional font decorations, bold, underline, etc 510 decorationsBox = QGroupBox ("Decorations") 511 decorationsLayout = QGridLayout (decorationsBox) 512 self.bold = QCheckBox ("Bold") 513 self.italics = QCheckBox ("Italics") 514 self.underline = QCheckBox ("Underline") 515 decorationsLayout.addWidget (self.bold, 0, 0) 516 decorationsLayout.addWidget (self.italics, 1, 0) 517 decorationsLayout.addWidget (self.underline, 2, 0) 518 519 # Save button to save changes 520 saveButton = QPushButton ("Save") 521 saveButton.setAutoDefault (True) 522 523 self.categorySelect.setCurrentIndex (1) 524 525 QObject.connect (self.categorySelect, SIGNAL ("currentIndexChanged (const QString&)"), \ 526 self.updateCategory) 527 QObject.connect (self.fontSelect, SIGNAL ("currentFontChanged (const QFont&)"), self.updateFont) 528 QObject.connect (self.sizeSelect, SIGNAL ("valueChanged (int)"), self.updateSize) 529 QObject.connect (self.colorSelect, SIGNAL ("currentIndexChanged (int)"), self.updateColor) 530 QObject.connect (self.colorCode, SIGNAL ("editingFinished ()"), self.customColorEdit) 531 QObject.connect (self.bold, SIGNAL ("stateChanged (int)"), self.updateBold) 532 QObject.connect (self.italics, SIGNAL ("stateChanged (int)"), self.updateItalics) 533 QObject.connect (self.underline, SIGNAL ("stateChanged (int)"), self.updateUnderline) 534 QObject.connect (saveButton, SIGNAL ("clicked ()"), self.saveSettings) 535 536 self.categorySelect.setCurrentIndex (0) 537 538 # connect everything in one big lump 539 self.addWidget (selectLabel, 1, 0, Qt.AlignRight) 540 self.addWidget (self.categorySelect, 1, 1) 541 self.addWidget (QLabel ("IPython Appearance"), 0, 0, 1, 2, Qt.AlignHCenter) 542 self.addWidget (fontLabel, 2, 0, Qt.AlignRight) 543 self.addWidget (self.fontSelect, 2, 1) 544 self.addWidget (sizeLabel, 3, 0, Qt.AlignRight) 545 self.addWidget (self.sizeSelect, 3, 1, Qt.AlignLeft) 546 self.addWidget (colorLabel, 4, 0, Qt.AlignRight) 547 self.addWidget (self.colorSelect, 4, 1) 548 self.addWidget (colorcodeLabel, 5, 0, Qt.AlignRight) 549 self.addWidget (self.colorCode, 5, 1, Qt.AlignLeft) 550 self.addWidget (decorationsBox, 6, 0, 1, 2, Qt.AlignHCenter) 551 self.addWidget (saveButton, 7, 0, 1, 2, Qt.AlignHCenter)
552
553 - def updateCategory (self, category):
554 # Switch font name 555 self.fontSelect.setCurrentFont (QFont (self.GetValFromBuffer (category, "Font"))) 556 557 # Switch font size 558 self.sizeSelect.setValue (int (self.GetValFromBuffer (category, "Size"))) 559 560 # Switch font color 561 colorIndex = self.colorSelect.findData (QVariant (self.GetValFromBuffer \ 562 (category, "Color")), Qt.UserRole, Qt.MatchExactly) 563 if colorIndex == -1: 564 # Set the color to custom and insert the html code 565 self.colorSelect.setCurrentIndex (self.colorSelect.count () - 1) 566 self.colorCode.setText (self.GetValFromBuffer (category, "Color")) 567 else: 568 # set the color to the known color, that should fill in the code automatically 569 self.colorSelect.setCurrentIndex (colorIndex) 570 571 # Switch font decorations 572 self.bold.setCheckState (Qt.Unchecked) 573 self.underline.setCheckState (Qt.Unchecked) 574 self.italics.setCheckState (Qt.Unchecked) 575 for dec in self.GetValFromBuffer (category, "Decorations"): 576 if dec == "b": 577 self.bold.setCheckState (Qt.Checked) 578 elif dec == "u": 579 self.underline.setCheckState (Qt.Checked) 580 elif dec == "i": 581 self.italics.setCheckState (Qt.Checked)
582
583 - def updateFont (self, font):
584 target = "Font" 585 category = str (self.categorySelect.currentText ()) 586 fontName = str (font.family ()) 587 self.SendValToBuffer (category, target, fontName)
588
589 - def customColorEdit (self):
590 color = self.colorCode.text () 591 category = str (self.categorySelect.currentText ()) 592 colorIndex = self.colorSelect.findData (QVariant (self.GetValFromBuffer \ 593 (category, "Color")), Qt.UserRole, Qt.MatchExactly) 594 if colorIndex != -1: 595 self.colorSelect.setCurrentIndex (colorIndex) 596 else: 597 self.colorSelect.setCurrentIndex (self.colorSelect.count () - 1) 598 self.colorCode.setText (color) 599 self.SendValToBuffer (category, "Color", color)
600
601 - def updateDecorations (self, state, val):
602 target = "Decorations" 603 category = str (self.categorySelect.currentText ()) 604 current = self.GetValFromBuffer (category, target) 605 exists = current.count (val) 606 final = current 607 if state == 0 and exists > 0: 608 final = [] 609 for dec in current: 610 if dec != val: 611 final.append (dec) 612 elif state == 2 and exists == 0: 613 final.append (val) 614 615 self.SendValToBuffer (category, target, final)
616
617 - def updateBold (self, state):
618 self.updateDecorations (state, "b")
619
620 - def updateItalics (self, state):
621 self.updateDecorations (state, "i")
622
623 - def updateUnderline (self, state):
624 self.updateDecorations (state, "u")
625
626 - def updateSize (self, val):
627 category = str (self.categorySelect.currentText ()) 628 target = "Size" 629 self.SendValToBuffer (category, target, str (val))
630
631 - def updateColor (self, index):
632 category = str (self.categorySelect.currentText ()) 633 target = "Color" 634 if str (self.colorSelect.itemText (index)) == "Custom": 635 self.colorCode.setText (self.GetValFromBuffer (category, target)) 636 else: 637 variant = self.colorSelect.itemData (index) 638 self.colorCode.setText (str (variant.toString ())) 639 self.SendValToBuffer (category, target, str (variant.toString ()))
640
641 - def PopulateBufferFromShell (self):
642 self.SendValToBuffer ("Command", "Font", self._ipyShell._commandFont) 643 self.SendValToBuffer ("Command", "Size", self._ipyShell._commandSize) 644 self.SendValToBuffer ("Command", "Color", self._ipyShell._commandColor) 645 self.SendValToBuffer ("Command", "Decorations", self._ipyShell._commandDecorations) 646 self.SendValToBuffer ("Comment", "Font", self._ipyShell._commentFont) 647 self.SendValToBuffer ("Comment", "Size", self._ipyShell._commentSize) 648 self.SendValToBuffer ("Comment", "Color", self._ipyShell._commentColor) 649 self.SendValToBuffer ("Comment", "Decorations", self._ipyShell._commentDecorations) 650 self.SendValToBuffer ("Result", "Font", self._ipyShell._resultFont) 651 self.SendValToBuffer ("Result", "Size", self._ipyShell._resultSize) 652 self.SendValToBuffer ("Result", "Color", self._ipyShell._resultColor) 653 self.SendValToBuffer ("Result", "Decorations", self._ipyShell._resultDecorations)
654
655 - def CommitBufferToShell (self):
656 self._ipyShell._commandFont = self.GetValFromBuffer ("Command", "Font") 657 self._ipyShell._commandSize = self.GetValFromBuffer ("Command", "Size") 658 self._ipyShell._commandColor = self.GetValFromBuffer ("Command", "Color") 659 self._ipyShell._commandDecorations = self.GetValFromBuffer ("Command", "Decorations") 660 self._ipyShell._commentFont = self.GetValFromBuffer ("Comment", "Font") 661 self._ipyShell._commentSize = self.GetValFromBuffer ("Comment", "Size") 662 self._ipyShell._commentColor = self.GetValFromBuffer ("Comment", "Color") 663 self._ipyShell._commentDecorations = self.GetValFromBuffer ("Comment", "Decorations") 664 self._ipyShell._resultFont = self.GetValFromBuffer ("Result", "Font") 665 self._ipyShell._resultSize = self.GetValFromBuffer ("Result", "Size") 666 self._ipyShell._resultColor = self.GetValFromBuffer ("Result", "Color") 667 self._ipyShell._resultDecorations = self.GetValFromBuffer ("Result", "Decorations")
668
669 - def SendValToBuffer (self, target, field, value):
670 if target == "Command": 671 target = self._command 672 elif target == "Comment": 673 target = self._comment 674 elif target == "Result": 675 target = self._result 676 else: 677 return 678 679 if field != "Font" and field != "Size" and field != "Color" and field != "Decorations": 680 return 681 682 target[field] = value
683
684 - def GetValFromBuffer (self, target, field):
685 if target == "Command": 686 target = self._command 687 elif target == "Comment": 688 target = self._comment 689 elif target == "Result": 690 target = self._result 691 else: 692 return 693 694 if field != "Font" and field != "Size" and field != "Color" and field != "Decorations": 695 return 696 697 return target[field]
698
699 - def saveSettings (self):
700 self.CommitBufferToShell () 701 702 path = QDir.home () 703 if not path.exists (".basin"): 704 path.mkdir (".basin") 705 path.cd (".basin") 706 if not path.exists ("client"): 707 path.mkdir ("client") 708 path.cd ("client") 709 710 file = QFile (str (path.path ()) + "/ipython_appearance.conf") 711 file.setPermissions (QFile.WriteOwner | QFile.ReadOwner | QFile.ReadUser | QFile.WriteUser) 712 file.open (QIODevice.WriteOnly | QIODevice.Text) 713 file.writeData ("IPython Appearance Preferences\n\n") 714 715 decs = "" 716 for dec in self._ipyShell._commandDecorations: 717 decs += dec + "," 718 decs = decs[:-1] 719 file.writeData ("COMMAND:SIZE:" + self._ipyShell._commandSize + "\n") 720 file.writeData ("COMMAND:FONT:" + self._ipyShell._commandFont + "\n") 721 file.writeData ("COMMAND:COLOR:" + self._ipyShell._commandColor + "\n") 722 file.writeData ("COMMAND:DECORATIONS:" + decs + "\n\n") 723 724 decs = "" 725 for dec in self._ipyShell._resultDecorations: 726 decs += dec + "," 727 decs = decs[:-1] 728 file.writeData ("RESULT:SIZE:" + self._ipyShell._resultSize + "\n") 729 file.writeData ("RESULT:FONT:" + self._ipyShell._resultFont + "\n") 730 file.writeData ("RESULT:COLOR:" + self._ipyShell._resultColor + "\n") 731 file.writeData ("RESULT:DECORATIONS:" + decs + "\n\n") 732 733 decs = "" 734 for dec in self._ipyShell._commentDecorations: 735 decs += dec + "," 736 decs = decs[:-1] 737 file.writeData ("COMMENT:SIZE:" + self._ipyShell._commentSize + "\n") 738 file.writeData ("COMMENT:FONT:" + self._ipyShell._commentFont + "\n") 739 file.writeData ("COMMENT:COLOR:" + self._ipyShell._commentColor + "\n") 740 file.writeData ("COMMENT:DECORATIONS:" + decs + "\n\n") 741 742 file.close () 743 self._ipyShell.loadSettings ()
744 745
746 -class ConnectionPreferences (QVBoxLayout):
747 - def __init__ (self, bridge):
748 QVBoxLayout.__init__ (self) 749 self._bridge = bridge 750 751 # A dictionary of profile names, to Profile objects 752 self.profiles = {} 753 754 profileSelectLayout = Constants.BQHBoxLayout (self) 755 profileSelectLabel = QLabel (QString ("Profile:")) 756 profileSelectLayout.addWidget (profileSelectLabel) 757 self._profileSelect = QComboBox () 758 QObject.connect (self._profileSelect, \ 759 SIGNAL ("currentIndexChanged (const QString&)"), self.profileChanged) 760 profileSelectLayout.addWidget (self._profileSelect) 761 762 profileLayout = Constants.BQHBoxLayout (self) 763 profileLabel = QLabel (QString ("Profile Name:")) 764 profileLayout.addWidget (profileLabel) 765 self._profile = QLineEdit () 766 self._profile.setEnabled (False) 767 profileLayout.addWidget (self._profile) 768 769 hostLayout = Constants.BQHBoxLayout (self) 770 hostLabel = QLabel (QString ("BASIN Host:")) 771 hostLayout.addWidget (hostLabel) 772 self._hostLine = QLineEdit () 773 self._hostLine.setToolTip ("The hostname of your cluster") 774 hostLayout.addWidget (self._hostLine) 775 776 portLayout = Constants.BQHBoxLayout (self) 777 portLabel = QLabel (QString ("BASIN Port:")) 778 portLayout.addWidget (portLabel) 779 self._portLine = QLineEdit () 780 self._portLine.setToolTip ("The port on your cluster") 781 portLayout.addWidget (self._portLine) 782 783 userLayout = Constants.BQHBoxLayout (self) 784 userLabel = QLabel (QString ("User Name:")) 785 userLayout.addWidget (userLabel) 786 self._userLine = QLineEdit () 787 self._userLine.setToolTip ("") 788 userLayout.addWidget (self._userLine) 789 790 self.loadSettings () 791 792 # Start setting up the buttons 793 buttonLayout = QGridLayout () 794 795 # Everything concerning the "New" button 796 newButton = QPushButton ("New") 797 buttonLayout.addWidget (newButton, 0, 0, 1, 2) 798 newButton.setToolTip ("Create new profile") 799 QObject.connect (newButton, SIGNAL ("clicked ()"), self.newProfile) 800 801 # Everything concerning the "Remove" button 802 removeButton = QPushButton ("Remove") 803 buttonLayout.addWidget (removeButton, 0, 2, 1, 2) 804 removeButton.setToolTip ("Remove current profile") 805 QObject.connect (removeButton, SIGNAL ("clicked ()"), self.removeProfile) 806 807 # Everything concerning the "Save" button 808 saveButton = QPushButton ("Save") 809 buttonLayout.addWidget (saveButton, 0, 4, 1, 2) 810 saveButton.setToolTip ("Permanently change settings") 811 QObject.connect (saveButton, SIGNAL ("clicked ()"), self.saveProfile) 812 813 # Set "Connect" to be the default button 814 #connectButton.setDefault (True) 815 816 self.addLayout (buttonLayout)
817
818 - def profileChanged (self, string):
819 self._profile.setEnabled (False) 820 profile = str (string) 821 self._profile.setText (profile) 822 self._hostLine.setText (self.profiles [profile].getHost ()) 823 self._portLine.setText (self.profiles [profile].getPort ()) 824 self._userLine.setText (self.profiles [profile].getUser ())
825
826 - def newProfile (self):
827 self._profile.setEnabled (True) 828 self._profile.clear () 829 self._hostLine.clear () 830 self._portLine.clear () 831 self._userLine.clear ()
832
833 - def saveProfile (self):
834 self._profile.setEnabled (False) 835 profile = str (self._profile.text ()) 836 837 if profile not in self.profiles: 838 self.profiles[profile] = Connection.Profile (profile) 839 self._profileSelect.addItems (QStringList (profile)) 840 841 self.profiles[profile].setHost (str (self._hostLine.text ())) 842 self.profiles[profile].setPort (str (self._portLine.text ())) 843 self.profiles[profile].setUser (str (self._userLine.text ())) 844 self.saveSettings ()
845
846 - def removeProfile (self):
847 if self._profile.isEnabled (): 848 return 849 profile = str (self._profile.text ()) 850 del (self.profiles[profile]) 851 self._profileSelect.removeItem (self._profileSelect.currentIndex ())
852
853 - def loadSettings (self):
854 file = QFile (str (QDir.home ().path ()) + "/.basin/client/connection.conf") 855 if file.exists (): 856 file.open (QIODevice.ReadOnly | QIODevice.Text) 857 stream = QTextStream (file) 858 reProfile = re.compile ("\s*PROFILE\s*:\s*.*\s*") 859 reHost = re.compile ("\s*HOST\s*:\s*.*\s*:\s*.*\s*") 860 rePort = re.compile ("\s*PORT\s*:\s*.*\s*:\s*.*\s*") 861 reUser = re.compile ("\s*USER\s*:\s*.*\s*:\s*.*\s*") 862 while not stream.atEnd (): 863 line = str (stream.readLine ()) 864 865 if reProfile.match (line): 866 name = line[line.find (':') + 1:] 867 if name not in self.profiles: 868 self.profiles [name] = Connection.Profile (name) 869 elif reHost.match (line): 870 name = line[line.find (':') + 1:line.rfind (':')] 871 host = line[line.rfind (':') + 1:] 872 if name in self.profiles: 873 self.profiles[name].setHost (host) 874 elif rePort.match (line): 875 name = line[line.find (':') + 1:line.rfind (':')] 876 port = line[line.rfind (':') + 1:] 877 if name in self.profiles: 878 self.profiles[name].setPort (port) 879 elif reUser.match (line): 880 name = line[line.find (':') + 1:line.rfind (':')] 881 user = line[line.rfind (':') + 1:] 882 if name in self.profiles: 883 self.profiles[name].setUser (user) 884 file.close () 885 886 profileList = QStringList () 887 for profile in self.profiles.keys (): 888 profileList.append (profile) 889 self._profileSelect.addItems (profileList)
890 891
892 - def saveSettings (self):
893 path = QDir.home () 894 if not path.exists (".basin"): 895 path.mkdir (".basin") 896 path.cd (".basin") 897 if not path.exists ("client"): 898 path.mkdir ("client") 899 path.cd ("client") 900 901 file = QFile (str (path.path ()) + "/connection.conf") 902 file.setPermissions (QFile.WriteOwner | QFile.ReadOwner | QFile.ReadUser | QFile.WriteUser) 903 file.open (QIODevice.WriteOnly | QIODevice.Text) 904 file.writeData ("Connection Preferences\n\n") 905 906 for profile in self.profiles.keys (): 907 host = self.profiles[profile].getHost () 908 port = self.profiles[profile].getPort () 909 user = self.profiles[profile].getUser () 910 file.writeData ("PROFILE:" + profile + "\n") 911 file.writeData ("HOST:" + profile + ":" + host + "\n") 912 file.writeData ("PORT:" + profile + ":" + port + "\n") 913 file.writeData ("USER:" + profile + ":" + user + "\n\n") 914 file.close ()
915