<commit_before>from __future__ import absolute_import
import __init__

import wx, os, platform, types

from fabmetheus_utilities import settings

from newui import validators

def main():
	app = wx.App(False)
	mainWindow()
	app.MainLoop()

class configWindowBase(wx.Frame):
	"A base class for configuration dialogs. Handles creation of settings, and popups"
	def __init__(self, title):
		super(configWindowBase, self).__init__(None, title=title)
		
		self.settingControlList = []

		#Create the popup window
		self.popup = wx.PopupWindow(self, wx.BORDER_SIMPLE)
		self.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
		self.popup.setting = None
		self.popup.text = wx.StaticText(self.popup, -1, '');
		self.popup.sizer = wx.BoxSizer()
		self.popup.sizer.Add(self.popup.text, flag=wx.EXPAND|wx.ALL, border=1)
		self.popup.SetSizer(self.popup.sizer)

	def CreateConfigTab(self, nb, name):
		leftConfigPanel, rightConfigPanel, configPanel = self.CreateConfigPanel(nb)
		nb.AddPage(configPanel, name)
		return leftConfigPanel, rightConfigPanel
	
	def CreateConfigPanel(self, parent):
		configPanel = wx.Panel(parent);
		leftConfigPanel = wx.Panel(configPanel)
		rightConfigPanel = wx.Panel(configPanel)
		sizer = wx.GridBagSizer(2, 2)
		leftConfigPanel.SetSizer(sizer)
		sizer = wx.GridBagSizer(2, 2)
		rightConfigPanel.SetSizer(sizer)
		sizer = wx.BoxSizer(wx.HORIZONTAL)
		configPanel.SetSizer(sizer)
		sizer.Add(leftConfigPanel)
		sizer.Add(rightConfigPanel)
		leftConfigPanel.main = self
		rightConfigPanel.main = self
		return leftConfigPanel, rightConfigPanel, configPanel
	
	def OnPopupDisplay(self, setting):
		self.popup.setting = setting
		self.UpdatePopup(setting)
		self.popup.Show(True)
		
	def OnPopupHide(self, e):
		self.popup.Show(False)
	
	def UpdatePopup(self, setting):
		if self.popup.setting == setting:
			if setting.validationMsg != '':
				self.popup.text.SetLabel(setting.validationMsg + '\n\n' + setting.helpText)
			else:
				self.popup.text.SetLabel(setting.helpText)
			self.popup.text.Wrap(350)
			self.popup.Fit()
			x, y = setting.ctrl.ClientToScreenXY(0, 0)
			sx, sy = setting.ctrl.GetSizeTuple()
			#if platform.system() == "Windows":
			#	for some reason, under windows, the popup is relative to the main window... in some cases. (Wierd ass bug)
			#	wx, wy = self.ClientToScreenXY(0, 0)
			#	x -= wx
			#	y -= wy
			self.popup.SetPosition((x, y+sy))
	
	def updateProfileToControls(self):
		"Update the configuration wx controls to show the new configuration settings"
		for setting in self.settingControlList:
			if setting.type == 'profile':
				setting.SetValue(settings.getProfileSetting(setting.configName))
			else:
				setting.SetValue(settings.getPreference(setting.configName))

class TitleRow():
	def __init__(self, panel, name):
		"Add a title row to the configuration panel"
		sizer = panel.GetSizer()
		self.title = wx.StaticText(panel, -1, name)
		self.title.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
		sizer.Add(self.title, (sizer.GetRows(),0), (1,3), flag=wx.EXPAND)
		sizer.Add(wx.StaticLine(panel), (sizer.GetRows()+1,0), (1,3), flag=wx.EXPAND)
		sizer.SetRows(sizer.GetRows() + 2)

class SettingRow():
	def __init__(self, panel, label, configName, defaultValue = '', helpText = 'Help: TODO', type = 'profile'):
		"Add a setting to the configuration panel"
		sizer = panel.GetSizer()
		x = sizer.GetRows()
		y = 0
		
		self.validators = []
		self.validationMsg = ''
		self.helpText = helpText
		self.configName = configName
		self.panel = panel
		self.type = type
		
		self.label = wx.StaticText(panel, -1, label)
		getSettingFunc = settings.getPreference
		if self.type == 'profile':
			getSettingFunc = settings.getProfileSetting
		if isinstance(defaultValue, types.StringTypes):
			self.ctrl = wx.TextCtrl(panel, -1, getSettingFunc(configName, defaultValue))<commit_msg>Fixed possibly another MacOS layout bug<commit_after>from __future__ import absolute_import
import __init__

import wx, os, platform, types

from fabmetheus_utilities import settings

from newui import validators

def main():
	app = wx.App(False)
	mainWindow()
	app.MainLoop()

class configWindowBase(wx.Frame):
	"A base class for configuration dialogs. Handles creation of settings, and popups"
	def __init__(self, title):
		super(configWindowBase, self).__init__(None, title=title)
		
		self.settingControlList = []

		#Create the popup window
		self.popup = wx.PopupWindow(self, wx.BORDER_SIMPLE)
		self.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
		self.popup.setting = None
		self.popup.text = wx.StaticText(self.popup, -1, '');
		self.popup.sizer = wx.BoxSizer()
		self.popup.sizer.Add(self.popup.text, flag=wx.EXPAND|wx.ALL, border=1)
		self.popup.SetSizer(self.popup.sizer)

	def CreateConfigTab(self, nb, name):
		leftConfigPanel, rightConfigPanel, configPanel = self.CreateConfigPanel(nb)
		nb.AddPage(configPanel, name)
		return leftConfigPanel, rightConfigPanel
	
	def CreateConfigPanel(self, parent):
		configPanel = wx.Panel(parent);
		leftConfigPanel = wx.Panel(configPanel)
		rightConfigPanel = wx.Panel(configPanel)
		sizer = wx.GridBagSizer(2, 2)
		leftConfigPanel.SetSizer(sizer)
		sizer = wx.GridBagSizer(2, 2)
		rightConfigPanel.SetSizer(sizer)
		sizer = wx.BoxSizer(wx.HORIZONTAL)
		configPanel.SetSizer(sizer)
		sizer.Add(leftConfigPanel)
		sizer.Add(rightConfigPanel)
		leftConfigPanel.main = self
		rightConfigPanel.main = self
		return leftConfigPanel, rightConfigPanel, configPanel
	
	def OnPopupDisplay(self, setting):
		self.popup.setting = setting
		self.UpdatePopup(setting)
		self.popup.Show(True)
		
	def OnPopupHide(self, e):
		self.popup.Show(False)
	
	def UpdatePopup(self, setting):
		if self.popup.setting == setting:
			if setting.validationMsg != '':
				self.popup.text.SetLabel(setting.validationMsg + '\n\n' + setting.helpText)
			else:
				self.popup.text.SetLabel(setting.helpText)
			self.popup.text.Wrap(350)
			self.popup.Fit()
			x, y = setting.ctrl.ClientToScreenXY(0, 0)
			sx, sy = setting.ctrl.GetSizeTuple()
			#if platform.system() == "Windows":
			#	for some reason, under windows, the popup is relative to the main window... in some cases. (Wierd ass bug)
			#	wx, wy = self.ClientToScreenXY(0, 0)
			#	x -= wx
			#	y -= wy
			self.popup.SetPosition((x, y+sy))
	
	def updateProfileToControls(self):
		"Update the configuration wx controls to show the new configuration settings"
		for setting in self.settingControlList:
			if setting.type == 'profile':
				setting.SetValue(settings.getProfileSetting(setting.configName))
			else:
				setting.SetValue(settings.getPreference(setting.configName))

class TitleRow():
	def __init__(self, panel, name):
		"Add a title row to the configuration panel"
		sizer = panel.GetSizer()
		x = sizer.GetRows()
		self.title = wx.StaticText(panel, -1, name)
		self.title.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
		sizer.Add(self.title, (sizer.GetRows(),0), (1,3), flag=wx.EXPAND)
		sizer.Add(wx.StaticLine(panel), (sizer.GetRows()+1,0), (1,3), flag=wx.EXPAND)
		sizer.SetRows(x + 2)

class SettingRow():
	def __init__(self, panel, label, configName, defaultValue = '', helpText = 'Help: TODO', type = 'profile'):
		"Add a setting to the configuration panel"
		sizer = panel.GetSizer()
		x = sizer.GetRows()
		y = 0
		
		self.validators = []
		self.validationMsg = ''
		self.helpText = helpText
		self.configName = configName
		self.panel = panel
		self.type = type
		
		self.label = wx.StaticText(panel, -1, label)
		getSettingFunc = settings.getPreference
		if self.type == 'profile':
			getSettingFunc = settings.getProfileSetting
		if isinstance(defaultValue, types.StringTypes):
			self.ctrl = wx.TextCtrl(panel, -1, getSettingFunc(configName, defaultValue))
{'fraction_non_alphanumeric': 0.12314197847257817, 'fraction_numerical': 0.006663249615581753, 'mean_word_length': 4.578984989278056, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3727763', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2649, 'n_words': 576}