1 from PyQt4.QtGui import *
2 from PyQt4.QtCore import *
3
4 import re
5
6 import Constants
7 import Connection
8
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
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
34
35
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
48 self._current = None
49 self.setWindowIcon (QIcon (Constants.ICON_DIR + "/file/preferences.png"))
50 self.setWindowTitle ("Preferences")
51 layout = QHBoxLayout (self)
52
53
54
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
69 self.addGeneral ()
70 self.addConnection ()
71 self.addToolBar ()
72 self.addAppearance ()
73
74 self.exec_ ()
75
76
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
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
133
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
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
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
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
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
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
454
455
458 QVBoxLayout.__init__ (self)
459 self._bridge = bridge
460 self._ipyShell = bridge._ipyShell._commandHistory
461
462
463
464
465
466 self._command = {}
467 self._comment = {}
468 self._result = {}
469 self.PopulateBufferFromShell ()
470
471
472 selectLabel = QLabel ("Select:")
473 selectLabel.setAlignment (Qt.AlignHCenter)
474 self.categorySelect = QComboBox ()
475 self.categorySelect.addItems (["Command", "Comment", "Result"])
476
477
478 fontLabel = QLabel ("Font:")
479 fontLabel.setAlignment (Qt.AlignHCenter)
480 self.fontSelect = QFontComboBox ()
481
482
483 sizeLabel = QLabel ("Size:")
484 sizeLabel.setAlignment (Qt.AlignHCenter)
485 self.sizeSelect = QSpinBox ()
486 self.sizeSelect.setRange (1, 64)
487
488
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
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
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
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
554
555 self.fontSelect.setCurrentFont (QFont (self.GetValFromBuffer (category, "Font")))
556
557
558 self.sizeSelect.setValue (int (self.GetValFromBuffer (category, "Size")))
559
560
561 colorIndex = self.colorSelect.findData (QVariant (self.GetValFromBuffer \
562 (category, "Color")), Qt.UserRole, Qt.MatchExactly)
563 if colorIndex == -1:
564
565 self.colorSelect.setCurrentIndex (self.colorSelect.count () - 1)
566 self.colorCode.setText (self.GetValFromBuffer (category, "Color"))
567 else:
568
569 self.colorSelect.setCurrentIndex (colorIndex)
570
571
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
584 target = "Font"
585 category = str (self.categorySelect.currentText ())
586 fontName = str (font.family ())
587 self.SendValToBuffer (category, target, fontName)
588
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
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
619
622
625
627 category = str (self.categorySelect.currentText ())
628 target = "Size"
629 self.SendValToBuffer (category, target, str (val))
630
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
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
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
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
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
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
748 QVBoxLayout.__init__ (self)
749 self._bridge = bridge
750
751
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
793 buttonLayout = QGridLayout ()
794
795
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
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
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
814
815
816 self.addLayout (buttonLayout)
817
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
832
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
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
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
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