2016-09-09 2 views
0

Travailler sur une interface utilisateur et certaines des entrées de texte sont remplies avec des informations par défaut. Comme vu dans le screencap ci-dessous le texte que j'ai prédéfini est à la fois mis en évidence et caché derrière le bord gauche du TextCtrl. Comment puis-je réparer cela?Pourquoi le texte que j'ai défini dans un TextCtrl wxPython a-t-il été déplacé vers la gauche et mis en surbrillance?

écran Cap:

Le texte est mis en surbrillance lorsque la fenêtre cadre est mise au point sur Windows. Ce n'était pas quand je l'ai coupée. Le texte Fulle est "/ var/lib/cmt/tomcat/CDES"

Image

(Désolé pour la taille de l'image, je ne sais pas comment le redimensionner dans l'interface de poste de SOF)

code directement relavent:

DirPath_O_Text = wx.StaticText(panel,label='Remote Directory Path', style=wx.ALIGN_RIGHT) 
    self.DirPath_O_TC = wx.TextCtrl(panel) 
    self.DirPath_O_TC.ChangeValue("/var/lib/cmt/tomcat/CDES") 

    hbox1.Add(DirPath_O_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
    hbox1.Add((25,-1)) 
    hbox1.Add(self.DirPath_O_TC, proportion=1,) 
    hbox1.Add((25,-1)) 

complet code:

import wx 

class Popup(wx.Frame): 

    def __init__(self, *args, **kwargs): #initializing 
     super(Popup, self).__init__(*args, **kwargs) 

     self.SetMinSize((500,400)) #change this to change the minimum size of the total frame 
     self.Centre() 
     self.InitUI() 
     self.Show() 


    def InitUI(self): #building the UI 

     panel = wx.Panel(self) #main panel that holds everything 

     #setting font 
     font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) 
     font.SetPointSize(16) #this is the size for the title, its smaller later on 

     #setting panel colour 
     # background_Colour = '#BCD7E0' 
     # panel.SetBackgroundColour(background_Colour) 

     ###########################  
     #vbox = sizer holds the whole thing 
     # Title = label 
     # hbox1 = sizer 
     #  Remote Directory Label 
     #  Remote Directory TextCtrl 
     # hbox2 = sizer 
     #  Local Directory Label 
     #  Local Directory TextCtrl 
     # hbox3 = sizer 
     #  Hostname Label 
     #  Hostname TextCtrl 
     # hbox4 = sizer 
     #  Username Label 
     #  Username TextCtrl 
     # hbox5 = sizer 
     #  Password Label 
     #  Password TextCtrl 
     # vbox2 = just used to align the hbox6 to center 
     #  hbox6 = sizer that holds the bottom two buttons 
     #  ok button = sends all info to next program 
     #  Cancel button = closes current program 

     ############### 
     #start 
     vbox = wx.BoxSizer(wx.VERTICAL) #oriented verticaly 

     ######### 
     #title  
     st_title = wx.StaticText(panel,label='CMT-CDES XML Messaging Tool', style=wx.ALIGN_CENTRE) 
     st_title.SetFont(font) 
     font.SetPointSize(9) #changes font back to small for all other text besides title 

     vbox.Add(st_title, proportion=1,flag=wx.EXPAND|wx.ALL, border=10) #adds the title 
     ###### 

     ######## 
     #6 sizers. 1-5 are for the inputs, 6 is for buttons on bottom 
     hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox2 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox3 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox4 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox5 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox6 = wx.BoxSizer(wx.HORIZONTAL) 
     ######## 


     ######## 
     #set labels and TC for each hbox 

     #hbox1 
     DirPath_O_Text = wx.StaticText(panel,label='Remote Directory Path', style=wx.ALIGN_RIGHT) 
     self.DirPath_O_TC = wx.TextCtrl(panel) 
     self.DirPath_O_TC.ChangeValue("/var/lib/cmt/tomcat/CDES") 

     hbox1.Add(DirPath_O_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox1.Add((25,-1)) 
     hbox1.Add(self.DirPath_O_TC, proportion=1,) 
     hbox1.Add((25,-1)) 

     #hbox2 
     DirPath_L_Text = wx.StaticText(panel,label='Local Directory Path', style=wx.ALIGN_RIGHT) 
     self.DirPath_L_TC = wx.TextCtrl(panel) 

     hbox2.Add(DirPath_L_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox2.Add((25,-1)) 
     hbox2.Add(self.DirPath_L_TC, proportion=1,) 
     hbox2.Add((25,-1)) 

     #hbox3 
     Host_Text = wx.StaticText(panel,label='Hostname\IP', style=wx.ALIGN_RIGHT) 
     self.Host_TC = wx.TextCtrl(panel) 

     hbox3.Add(Host_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox3.Add((25,-1)) 
     hbox3.Add(self.Host_TC, proportion=1) 
     hbox3.Add((25,-1)) 

     #hbox4 
     User_Text = wx.StaticText(panel,label='Username', style=wx.ALIGN_RIGHT) 
     self.User_TC = wx.TextCtrl(panel) 

     hbox4.Add(User_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox4.Add((25,-1)) 
     hbox4.Add(self.User_TC, proportion=1) 
     hbox4.Add((25,-1)) 

     #hbox5 
     Pass_Text = wx.StaticText(panel,label='Password', style=wx.ALIGN_RIGHT) 
     self.Pass_TC = wx.TextCtrl(panel, style=wx.TE_PASSWORD) 

     hbox5.Add(Pass_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox5.Add((25,-1)) 
     hbox5.Add(self.Pass_TC, proportion=1) 
     hbox5.Add((25,-1)) 
     ######## 

     ######## 
     #buttons 
     btn_size = (90, 30) 
     btn_OK = wx.Button(panel, label='OK', size=btn_size) 
     btn_Cancel = wx.Button(panel, label='Cancel', size=btn_size) 

     #bindings 
     btn_OK.Bind(wx.EVT_BUTTON, self.OK) #binds to ok (just takes variables from all text boxes, and passes to program) 
     btn_Cancel.Bind(wx.EVT_BUTTON, self.Cancel) #binds to cancel (just closes the window) 

     #holds buttons 
     hbox6.Add(btn_OK) 
     hbox6.Add((25,-1)) #spacer between buttons 
     hbox6.Add(btn_Cancel, flag=wx.ALIGN_RIGHT,proportion=0) 

     #aligns hbox 
     vbox2 = wx.BoxSizer(wx.VERTICAL) #added this vbox to set the alignment to center 
     vbox2.Add(hbox6, flag=wx.ALIGN_CENTRE, proportion = 0) 
     ####### 

     ############ 
     #add everything to main vbox 
     vbox.Add(hbox1,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox2,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox3,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox4,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox5,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 

     #buttons vbox 
     vbox.Add(vbox2,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     ############ 

     #add main vbox to panel 
     panel.SetSizer(vbox) 

    def OK(self, e): 
     #creates a 5 item list, [DirPath_O, DirPath_L, Host, User, Pass] 
     args = [str(self.DirPath_O_TC.GetValue()) , str(self.DirPath_L_TC.GetValue()),str(self.Host_TC.GetValue()), str(self.User_TC.GetValue()), str(self.Pass_TC.GetValue())] 

     #print "args[1:5]: ", args 

     '''TODO 
     ''' 
     #call main, pass it args 
     #self.Close() #closes window when done 
     ''' 
     ''' 

     #TODO: Test if values are correct 

     print #not needed, just extra 

    def Cancel(self, e): #closes window 
     self.Close() 



#this is the main loop 
ex = wx.App() 
Popup(None) 
ex.MainLoop() 

Répondre

0

Je crois que le texte est aligné à gauche par défaut. Si vous le souhaitez aligné à droite, je crois que vous pouvez utiliser la méthode SetWindowStyle du contrôle de texte avec le drapeau wx.TE_RIGHT pour le faire. En ce qui concerne les raisons pour lesquelles le premier contrôle de texte met en évidence le texte, la raison en est que le premier contrôle de texte est également le premier widget qui peut accepter le focus. Parce qu'il obtient le focus et qu'il contient du texte, le texte est automatiquement mis en surbrillance.

+0

Left Aligné est bien, ce qui m'inquiète, c'est que la moitié du texte est coupée à gauche. C'est comme si le programme pense que le début de TextCtrl est quelque part à gauche de l'endroit où il est affiché. –

+0

Essayez d'appeler 'SetInsertionPoint (0)' –

+0

J'ai essayé d'appeler cela sur le TextCtrl et cela n'a fait aucune différence malheureusement. –